diff --git a/admin/access.php b/admin/access.php index a6ea8dd1..0c35b4fc 100644 --- a/admin/access.php +++ b/admin/access.php @@ -22,127 +22,127 @@ require '../lib/init.php'; -if (!Access::check('interface','100')) { +if (!Access::check('interface','100')) { access_denied(); exit(); } -show_header(); +show_header(); -switch ($_REQUEST['action']) { +switch ($_REQUEST['action']) { case 'delete_record': - if (!Core::form_verify('delete_access')) { - access_denied(); - exit; - } + if (!Core::form_verify('delete_access')) { + access_denied(); + exit; + } Access::delete($_REQUEST['access_id']); $url = Config::get('web_path') . '/admin/access.php'; show_confirmation(_('Deleted'),_('Your Access List Entry has been removed'),$url); break; - case 'show_delete_record': - if (Config::get('demo_mode')) { break; } - $access = new Access($_GET['access_id']); + case 'show_delete_record': + if (Config::get('demo_mode')) { break; } + $access = new Access($_GET['access_id']); show_confirmation(_('Deletion Request'),_('Are you sure you want to permanently delete') . ' ' . $access->name, - 'admin/access.php?action=delete_record&access_id=' . $access->id,1,'delete_access'); - break; + 'admin/access.php?action=delete_record&access_id=' . $access->id,1,'delete_access'); + break; case 'add_host': // Make sure we've got a valid form submission - if (!Core::form_verify('add_acl','post')) { - access_denied(); - exit; - } + if (!Core::form_verify('add_acl','post')) { + access_denied(); + exit; + } // We need to pre-process this a little bit as stuff is coming in from all over - switch ($_GET['method']) { - case 'advanced': - Access::create($_POST); - break; - case 'local': - $_POST['type'] = 'network'; - Access::create($_POST); - - // Create Additional stuff based on the type - if ($_POST['addtype'] == 'streamnetwork' OR $_POST['addtype'] == 'allnetwork') { - $_POST['type'] = 'stream'; - Access::create($_POST); - } - if ($_POST['addtype'] == 'allnetwork') { - $_POST['type'] = 'interface'; - Access::create($_POST); - } - break; - case 'current': - $_POST['start'] = $_SERVER['REMOTE_ADDR']; - $_POST['end'] = $_SERVER['REMOTE_ADDR']; - $_POST['type'] = 'interface'; - Access::create($_POST); - $_POST['type'] = 'stream'; - Access::create($_POST); - break; - case 'rpc': - $_POST['type'] = 'rpc'; - Access::create($_POST); + switch ($_GET['method']) { + case 'advanced': + Access::create($_POST); + break; + case 'local': + $_POST['type'] = 'network'; + Access::create($_POST); // Create Additional stuff based on the type - if ($_POST['addtype'] == 'streamrpc' OR $_POST['addtype'] == 'allrpc') { - $_POST['type'] = 'stream'; - Access::create($_POST); + if ($_POST['addtype'] == 'streamnetwork' OR $_POST['addtype'] == 'allnetwork') { + $_POST['type'] = 'stream'; + Access::create($_POST); } - if ($_POST['addtype'] == 'allrpc') { - $_POST['type'] = 'interface'; - Access::create($_POST); - } - break; - default: + if ($_POST['addtype'] == 'allnetwork') { + $_POST['type'] = 'interface'; + Access::create($_POST); + } + break; + case 'current': + $_POST['start'] = $_SERVER['REMOTE_ADDR']; + $_POST['end'] = $_SERVER['REMOTE_ADDR']; + $_POST['type'] = 'interface'; + Access::create($_POST); + $_POST['type'] = 'stream'; + Access::create($_POST); + break; + case 'rpc': + $_POST['type'] = 'rpc'; + Access::create($_POST); + + // Create Additional stuff based on the type + if ($_POST['addtype'] == 'streamrpc' OR $_POST['addtype'] == 'allrpc') { + $_POST['type'] = 'stream'; + Access::create($_POST); + } + if ($_POST['addtype'] == 'allrpc') { + $_POST['type'] = 'interface'; + Access::create($_POST); + } + break; + default: // Do nothing they f'ed something up - break; + break; } // end switch on method - if (!Error::occurred()) { + if (!Error::occurred()) { $url = Config::get('web_path') . '/admin/access.php'; show_confirmation(_('Added'),_('Your new Access Control List(s) have been created'),$url); - } - else { - switch ($_GET['method']) { + } + else { + switch ($_GET['method']) { case 'rpc': require_once Config::get('prefix') . '/templates/show_add_access_rpc.inc.php'; break; - case 'local': require_once Config::get('prefix') . '/templates/show_add_access_local.inc.php'; break; + case 'local': require_once Config::get('prefix') . '/templates/show_add_access_local.inc.php'; break; case 'current': require_once Config::get('prefix') . '/templates/show_add_access_current.inc.php'; break; - case 'advanced': require_once Config::get('prefix') . '/templates/show_add_access.inc.php'; break; - default: require_once Config::get('prefix') . '/templates/show_access_list.inc.php'; break; - } - } - break; - case 'update_record': - if (!Core::form_verify('edit_acl')) { - access_denied(); - exit; - } - $access = new Access($_REQUEST['access_id']); - $access->update($_POST); - if (!Error::occurred()) { - show_confirmation(_('Updated'),_('Access List Entry updated'), Config::get('web_path').'/admin/access.php'); - } - else { - $access->format(); - require_once Config::get('prefix') . '/templates/show_edit_access.inc.php'; + case 'advanced': require_once Config::get('prefix') . '/templates/show_add_access.inc.php'; break; + default: require_once Config::get('prefix') . '/templates/show_access_list.inc.php'; break; + } } break; - case 'show_add_current': - require_once Config::get('prefix') . '/templates/show_add_access_current.inc.php'; - break; - case 'show_add_rpc': - require_once Config::get('prefix') . '/templates/show_add_access_rpc.inc.php'; - break; - case 'show_add_local': - require_once Config::get('prefix') . '/templates/show_add_access_local.inc.php'; - break; + case 'update_record': + if (!Core::form_verify('edit_acl')) { + access_denied(); + exit; + } + $access = new Access($_REQUEST['access_id']); + $access->update($_POST); + if (!Error::occurred()) { + show_confirmation(_('Updated'),_('Access List Entry updated'), Config::get('web_path').'/admin/access.php'); + } + else { + $access->format(); + require_once Config::get('prefix') . '/templates/show_edit_access.inc.php'; + } + break; + case 'show_add_current': + require_once Config::get('prefix') . '/templates/show_add_access_current.inc.php'; + break; + case 'show_add_rpc': + require_once Config::get('prefix') . '/templates/show_add_access_rpc.inc.php'; + break; + case 'show_add_local': + require_once Config::get('prefix') . '/templates/show_add_access_local.inc.php'; + break; case 'show_add_advanced': require_once Config::get('prefix') . '/templates/show_add_access.inc.php'; break; case 'show_edit_record': $access = new Access($_REQUEST['access_id']); - $access->format(); + $access->format(); require_once Config::get('prefix') . '/templates/show_edit_access.inc.php'; break; default: diff --git a/admin/catalog.php b/admin/catalog.php index 7dcc0f10..9dee29eb 100644 --- a/admin/catalog.php +++ b/admin/catalog.php @@ -25,10 +25,10 @@ require_once '../lib/init.php'; if (!Access::check('interface','100')) { access_denied(); - exit; + exit; } -show_header(); +show_header(); /* Big switch statement to handle various actions */ switch ($_REQUEST['action']) { @@ -42,8 +42,8 @@ switch ($_REQUEST['action']) { $catalog = new Catalog(); $_REQUEST['catalogs'] = $catalog->get_catalog_ids(); case 'add_to_catalog': - toggle_visible('ajax-loading'); - ob_end_flush(); + toggle_visible('ajax-loading'); + ob_end_flush(); if (Config::get('demo_mode')) { break; } if ($_REQUEST['catalogs'] ) { foreach ($_REQUEST['catalogs'] as $catalog_id) { @@ -55,19 +55,19 @@ switch ($_REQUEST['action']) { $title = _('Catalog Updated'); $body = ''; show_confirmation($title,$body,$url); - toggle_visible('ajax-loading'); + toggle_visible('ajax-loading'); break; case 'update_all_catalogs': $_REQUEST['catalogs'] = Catalog::get_catalog_ids(); case 'update_catalog': - toggle_visible('ajax-loading'); - ob_end_flush(); + toggle_visible('ajax-loading'); + ob_end_flush(); /* If they are in demo mode stop here */ if (Config::get('demo_mode')) { break; } if (isset($_REQUEST['catalogs'])) { foreach ($_REQUEST['catalogs'] as $catalog_id) { - $catalog = new Catalog($catalog_id); + $catalog = new Catalog($catalog_id); $catalog->verify_catalog($catalog_id); } } @@ -75,59 +75,59 @@ switch ($_REQUEST['action']) { $title = _('Catalog Updated'); $body = ''; show_confirmation($title,$body,$url); - toggle_visible('ajax-loading'); + toggle_visible('ajax-loading'); break; case 'full_service': - toggle_visible('ajax-loading'); - ob_end_flush(); + toggle_visible('ajax-loading'); + ob_end_flush(); /* Make sure they aren't in demo mode */ - if (Config::get('demo_mode')) { access_denied(); break; } + if (Config::get('demo_mode')) { access_denied(); break; } - if (!$_REQUEST['catalogs']) { + if (!$_REQUEST['catalogs']) { $_REQUEST['catalogs'] = Catalog::get_catalog_ids(); } /* This runs the clean/verify/add in that order */ - foreach ($_REQUEST['catalogs'] as $catalog_id) { + foreach ($_REQUEST['catalogs'] as $catalog_id) { $catalog = new Catalog($catalog_id); $catalog->clean_catalog($catalog_id); $catalog->count = 0; $catalog->verify_catalog($catalog_id); $catalog->count = 0; $catalog->add_to_catalog($catalog_id); - } + } $url = Config::get('web_path') . '/admin/catalog.php'; $title = _('Catalog Updated'); $body = ''; show_confirmation($title,$body,$url); - toggle_visible('ajax-loading'); + toggle_visible('ajax-loading'); break; case 'delete_catalog': /* Make sure they aren't in demo mode */ if (Config::get('demo_mode')) { break; } - if (!Core::form_verify('delete_catalog')) { - access_denied(); - exit; - } - + if (!Core::form_verify('delete_catalog')) { + access_denied(); + exit; + } + /* Delete the sucker, we don't need to check perms as thats done above */ - Catalog::delete($_GET['catalog_id']); + Catalog::delete($_GET['catalog_id']); $next_url = Config::get('web_path') . '/admin/catalog.php'; show_confirmation(_('Catalog Deleted'),_('The Catalog and all associated records have been deleted'),$next_url); break; - case 'show_delete_catalog': - $catalog_id = scrub_in($_GET['catalog_id']); + case 'show_delete_catalog': + $catalog_id = scrub_in($_GET['catalog_id']); - $next_url = Config::get('web_path') . '/admin/catalog.php?action=delete_catalog&catalog_id=' . scrub_out($catalog_id); - show_confirmation(_('Catalog Delete'),_('Confirm Deletion Request'),$next_url,1,'delete_catalog'); - break; + $next_url = Config::get('web_path') . '/admin/catalog.php?action=delete_catalog&catalog_id=' . scrub_out($catalog_id); + show_confirmation(_('Catalog Delete'),_('Confirm Deletion Request'),$next_url,1,'delete_catalog'); + break; case 'remove_disabled': if (conf('demo_mode')) { break; } $song = $_REQUEST['song']; - if (count($song)) { + if (count($song)) { $catalog->remove_songs($song); $body = ngettext('Song Removed', 'Songs Removed', count($song)); } @@ -139,27 +139,27 @@ switch ($_REQUEST['action']) { show_confirmation($title,$body,$url); break; case 'clean_all_catalogs': - $catalog = new Catalog(); + $catalog = new Catalog(); $_REQUEST['catalogs'] = Catalog::get_catalog_ids(); case 'clean_catalog': - toggle_visible('ajax-loading'); - ob_end_flush(); + toggle_visible('ajax-loading'); + ob_end_flush(); /* If they are in demo mode stop them here */ if (Config::get('demo_mode')) { break; } - + // Make sure they checked something - if (isset($_REQUEST['catalogs'])) { - foreach($_REQUEST['catalogs'] as $catalog_id) { + if (isset($_REQUEST['catalogs'])) { + foreach($_REQUEST['catalogs'] as $catalog_id) { $catalog = new Catalog($catalog_id); $catalog->clean_catalog(0,1); } // end foreach catalogs } - + $url = Config::get('web_path') . '/admin/catalog.php'; $title = _('Catalog Cleaned'); $body = ''; show_confirmation($title,$body,$url); - toggle_visible('ajax-loading'); + toggle_visible('ajax-loading'); break; case 'update_catalog_settings': /* No Demo Here! */ @@ -167,82 +167,82 @@ switch ($_REQUEST['action']) { /* Update the catalog */ Catalog::update_settings($_REQUEST); - + $url = Config::get('web_path') . '/admin/catalog.php'; $title = _('Catalog Updated'); $body = ''; show_confirmation($title,$body,$url); break; - case 'update_from': - if (Config::get('demo_mode')) { break; } + case 'update_from': + if (Config::get('demo_mode')) { break; } // First see if we need to do an add - if ($_POST['add_path'] != '/' AND strlen($_POST['add_path'])) { - if ($catalog_id = Catalog::get_from_path($_POST['add_path'])) { - $catalog = new Catalog($catalog_id); - $catalog->run_add(array('subdirectory'=>$_POST['add_path'])); - } + if ($_POST['add_path'] != '/' AND strlen($_POST['add_path'])) { + if ($catalog_id = Catalog::get_from_path($_POST['add_path'])) { + $catalog = new Catalog($catalog_id); + $catalog->run_add(array('subdirectory'=>$_POST['add_path'])); + } } // end if add - + // Now check for an update - if ($_POST['update_path'] != '/' AND strlen($_POST['update_path'])) { - if ($catalog_id = Catalog::get_from_path($_POST['update_path'])) { - $songs = Song::get_from_path($_POST['update_path']); - foreach ($songs as $song_id) { Catalog::update_single_item('song',$song_id); } - } + if ($_POST['update_path'] != '/' AND strlen($_POST['update_path'])) { + if ($catalog_id = Catalog::get_from_path($_POST['update_path'])) { + $songs = Song::get_from_path($_POST['update_path']); + foreach ($songs as $song_id) { Catalog::update_single_item('song',$song_id); } + } } // end if update - break; + break; case 'add_catalog': /* Wah Demo! */ if (Config::get('demo_mode')) { break; } - ob_end_flush(); + ob_end_flush(); - if (!strlen($_POST['path']) || !strlen($_POST['name'])) { - Error::add('general',_('Error: Name and path not specified')); - } + if (!strlen($_POST['path']) || !strlen($_POST['name'])) { + Error::add('general',_('Error: Name and path not specified')); + } - if (substr($_POST['path'],0,7) != 'http://' && $_POST['type'] == 'remote') { + if (substr($_POST['path'],0,7) != 'http://' && $_POST['type'] == 'remote') { Error::add('general',_('Error: Remote selected, but path is not a URL')); - } - - if ($_POST['type'] == 'remote' && !strlen($_POST['key'])) { - Error::add('general',_('Error: Remote Catalog specified, but no key provided')); - } + } - if (!Core::form_verify('add_catalog','post')) { - access_denied(); - exit; - } + if ($_POST['type'] == 'remote' && !strlen($_POST['key'])) { + Error::add('general',_('Error: Remote Catalog specified, but no key provided')); + } + + if (!Core::form_verify('add_catalog','post')) { + access_denied(); + exit; + } // Make sure that there isn't a catalog with a directory above this one - if (Catalog::get_from_path($_POST['path'])) { + if (Catalog::get_from_path($_POST['path'])) { Error::add('general',_('Error: Defined Path is inside an existing catalog')); - } + } // If an error hasn't occured - if (!Error::occurred()) { + if (!Error::occurred()) { - $catalog_id = Catalog::Create($_POST); + $catalog_id = Catalog::Create($_POST); - if (!$catalog_id) { - require Config::get('prefix') . '/templates/show_add_catalog.inc.php'; - break; + if (!$catalog_id) { + require Config::get('prefix') . '/templates/show_add_catalog.inc.php'; + break; } - $catalog = new Catalog($catalog_id); + $catalog = new Catalog($catalog_id); // Run our initial add - $catalog->run_add($_POST); + $catalog->run_add($_POST); - show_box_top(); + show_box_top(); echo "

" . _('Catalog Created') . "

"; - Error::display('general'); - Error::display('catalog_add'); - show_box_bottom(); + Error::display('general'); + Error::display('catalog_add'); + show_box_bottom(); - show_confirmation('','', Config::get('web_path').'/admin/catalog.php'); + show_confirmation('','', Config::get('web_path').'/admin/catalog.php'); } else { @@ -251,16 +251,16 @@ switch ($_REQUEST['action']) { break; case 'clear_stats': if (Config::get('demo_mode')) { access_denied(); break; } - - Catalog::clear_stats(); + + Catalog::clear_stats(); $url = Config::get('web_path') . '/admin/catalog.php'; $title = _('Catalog statistics cleared'); $body = ''; show_confirmation($title,$body,$url); break; - default: - case 'show_catalogs': - require_once Config::get('prefix') . '/templates/show_manage_catalogs.inc.php'; + default: + case 'show_catalogs': + require_once Config::get('prefix') . '/templates/show_manage_catalogs.inc.php'; break; case 'show_add_catalog': require Config::get('prefix') . '/templates/show_add_catalog.inc.php'; @@ -273,9 +273,9 @@ switch ($_REQUEST['action']) { case 'show_disabled': /* Stop the demo hippies */ if (conf('demo_mode')) { break; } - + $songs = $catalog->get_disabled(); - if (count($songs)) { + if (count($songs)) { require (conf('prefix') . '/templates/show_disabled_songs.inc.php'); } else { @@ -284,27 +284,27 @@ switch ($_REQUEST['action']) { break; case 'show_delete_catalog': /* Stop the demo hippies */ - if (Config::get('demo_mode')) { access_denied(); break; } + if (Config::get('demo_mode')) { access_denied(); break; } - $catalog = new Catalog($_REQUEST['catalog_id']); + $catalog = new Catalog($_REQUEST['catalog_id']); $nexturl = Config::get('web_path') . '/admin/catalog.php?action=delete_catalog&catalog_id=' . scrub_out($_REQUEST['catalog_id']); show_confirmation(_('Delete Catalog'),_('Do you really want to delete this catalog?') . " -- $catalog->name ($catalog->path)",$nexturl,1); break; case 'show_customize_catalog': - $catalog = new Catalog($_REQUEST['catalog_id']); + $catalog = new Catalog($_REQUEST['catalog_id']); require_once Config::get('prefix') . '/templates/show_edit_catalog.inc.php'; break; case 'gather_album_art': - toggle_visible('ajax-loading'); - ob_end_flush(); + toggle_visible('ajax-loading'); + ob_end_flush(); $catalogs = $_REQUEST['catalogs'] ? $_REQUEST['catalogs'] : Catalog::get_catalogs(); // Itterate throught the catalogs and gather as needed - foreach ($catalogs as $catalog_id) { + foreach ($catalogs as $catalog_id) { $catalog = new Catalog($catalog_id); - require Config::get('prefix') . '/templates/show_gather_art.inc.php'; - flush(); + require Config::get('prefix') . '/templates/show_gather_art.inc.php'; + flush(); $catalog->get_album_art('',1); } $url = Config::get('web_path') . '/admin/catalog.php'; diff --git a/admin/duplicates.php b/admin/duplicates.php index d61f5170..e2f82815 100644 --- a/admin/duplicates.php +++ b/admin/duplicates.php @@ -22,22 +22,22 @@ require_once '../lib/init.php'; -if (!Access::check('interface','100')) { - access_denied(); +if (!Access::check('interface','100')) { + access_denied(); exit; } -show_header(); +show_header(); /* Switch on Action */ switch ($_REQUEST['action']) { case 'find_duplicates': - $duplicates = Catalog::get_duplicate_songs($_REQUEST['search_type']); - require_once Config::get('prefix') . '/templates/show_duplicate.inc.php'; - require_once Config::get('prefix') . '/templates/show_duplicates.inc.php'; + $duplicates = Catalog::get_duplicate_songs($_REQUEST['search_type']); + require_once Config::get('prefix') . '/templates/show_duplicate.inc.php'; + require_once Config::get('prefix') . '/templates/show_duplicates.inc.php'; break; default: - require_once Config::get('prefix') . '/templates/show_duplicate.inc.php'; + require_once Config::get('prefix') . '/templates/show_duplicate.inc.php'; break; } // end switch on action diff --git a/admin/export.php b/admin/export.php index 4e423647..7b22cd8c 100644 --- a/admin/export.php +++ b/admin/export.php @@ -22,24 +22,24 @@ require_once '../lib/init.php'; -if (!Access::check('interface','100')) { - access_denied(); +if (!Access::check('interface','100')) { + access_denied(); exit; } -show_header(); +show_header(); /* Switch on Action */ switch ($_REQUEST['action']) { case 'export': - + // This may take a while - set_time_limit(0); - + set_time_limit(0); + $catalog = new Catalog($_REQUEST['export_catalog']); // Clear everything we've done so far - ob_end_clean(); + ob_end_clean(); // This will disable buffering so contents are sent immediately to browser. // This is very useful for large catalogs because it will immediately display the download dialog to user, @@ -49,7 +49,7 @@ switch ($_REQUEST['action']) { header("Content-Transfer-Encoding: binary"); header("Cache-control: public"); - $date = date("d/m/Y",time()); + $date = date("d/m/Y",time()); switch($_REQUEST['export_format']) { case 'itunes': @@ -57,19 +57,19 @@ switch ($_REQUEST['action']) { header("Content-Disposition: attachment; filename=\"ampache-itunes-$date.xml\""); $catalog->export('itunes'); break; - case 'csv': - header("Content-Type: application/vnd.ms-excel"); - header("Content-Disposition: filename=\"ampache-export-$date.csv\""); - $catalog->export('csv'); - break; - } // end switch on format + case 'csv': + header("Content-Type: application/vnd.ms-excel"); + header("Content-Disposition: filename=\"ampache-export-$date.csv\""); + $catalog->export('csv'); + break; + } // end switch on format // We don't want the footer so we're done here - exit; - + exit; + break; default: - require_once Config::get('prefix') . '/templates/show_export.inc.php'; + require_once Config::get('prefix') . '/templates/show_export.inc.php'; break; } // end switch on action diff --git a/admin/flag.php b/admin/flag.php index 79d9c81b..1d419421 100644 --- a/admin/flag.php +++ b/admin/flag.php @@ -21,52 +21,52 @@ */ require '../lib/init.php'; -if (!Access::check('interface','100')) { +if (!Access::check('interface','100')) { access_denied(); exit(); } -show_header(); +show_header(); switch ($_REQUEST['action']) { case 'edit_song': $catalog = new Catalog(); $song = new Song($_REQUEST['song_id']); $new_song = new Song(); - - /* Setup the vars so we can use the update_song function */ + + /* Setup the vars so we can use the update_song function */ $new_song->title = revert_string(scrub_in($_REQUEST['title'])); $new_song->track = revert_string(scrub_in($_REQUEST['track'])); $new_song->year = revert_string(scrub_in($_REQUEST['year'])); $new_song->comment = revert_string(scrub_in($_REQUEST['comment'])); /* If no change in string take Drop down */ - if (strcasecmp(stripslashes($_REQUEST['genre_string']),$song->get_genre_name()) == 0) { + if (strcasecmp(stripslashes($_REQUEST['genre_string']),$song->get_genre_name()) == 0) { $genre = $song->get_genre_name($_REQUEST['genre']); } - else { + else { $genre = scrub_in($_REQUEST['genre_string']); } - - if (strcasecmp(stripslashes($_REQUEST['album_string']),$song->get_album_name()) == 0) { + + if (strcasecmp(stripslashes($_REQUEST['album_string']),$song->get_album_name()) == 0) { $album = $song->get_album_name($_REQUEST['album']); } - else { + else { $album = scrub_in($_REQUEST['album_string']); } - - if (strcasecmp(stripslashes($_REQUEST['artist_string']),$song->get_artist_name()) == 0) { + + if (strcasecmp(stripslashes($_REQUEST['artist_string']),$song->get_artist_name()) == 0) { $artist = $song->get_artist_name($_REQUEST['artist']); } - else { + else { $artist = scrub_in($_REQUEST['artist_string']); } - + /* Use the check functions to get / create ids for this info */ $new_song->genre = $catalog->check_genre(revert_string($genre)); $new_song->album = $catalog->check_album(revert_string($album)); $new_song->artist = $catalog->check_artist(revert_string($artist)); - + /* Update this mofo, store an old copy for cleaning */ $old_song = new Song(); $old_song->artist = $song->artist; @@ -75,129 +75,129 @@ switch ($_REQUEST['action']) { $song->update_song($song->id,$new_song); /* Now that it's been updated clean old junk entries */ - $catalog = new Catalog(); + $catalog = new Catalog(); $cleaned = $catalog->clean_single_song($old_song); - + /* Add a tagging record of this so we can fix the file */ - if ($_REQUEST['flag']) { + if ($_REQUEST['flag']) { $flag = new Flag(); $flag->add($song->id,'song','retag','Edited Song, auto-tag'); } - if (isset($cleaned['artist']) || isset($cleaned['album'])) { $_SESSION['source'] = Config::get('web_path') . '/index.php'; } - + if (isset($cleaned['artist']) || isset($cleaned['album'])) { $_SESSION['source'] = Config::get('web_path') . '/index.php'; } + show_confirmation(_('Song Updated'),_('The requested song has been updated'),$_SESSION['source']); break; // Show the page for editing a full album case 'show_edit_album': - $album = new Album($_REQUEST['album_id']); - - require_once(conf('prefix') . '/templates/show_edit_album.inc.php'); + $album = new Album($_REQUEST['album_id']); + + require_once(conf('prefix') . '/templates/show_edit_album.inc.php'); break; // Update all songs from this album case 'edit_album': - - // Build the needed album - $album = new Album($_REQUEST['album_id']); - // Create the needed catalog object cause we can't do - // static class methods :( - $catalog = new Catalog(); - $flag = new Flag(); + // Build the needed album + $album = new Album($_REQUEST['album_id']); + + // Create the needed catalog object cause we can't do + // static class methods :( + $catalog = new Catalog(); + $flag = new Flag(); /* Check the new Name */ - $album_id = $catalog->check_album($_REQUEST['name'],$_REQUEST['year']); + $album_id = $catalog->check_album($_REQUEST['name'],$_REQUEST['year']); - $songs = $album->get_songs(); + $songs = $album->get_songs(); - foreach ($songs as $song) { - // Make that copy and change the album + foreach ($songs as $song) { + // Make that copy and change the album $new_song = $song; $new_song->album = $album_id; $song->update_song($song->id,$new_song); - if ($_REQUEST['flag'] == '1') { + if ($_REQUEST['flag'] == '1') { $flag->add($song->id,'song','retag','Edited Song, auto-tag'); - } + } } // end foreach songs - // Clean out the old album + // Clean out the old album $catalog->clean_albums(); - show_confirmation(_('Album Updated'),'',Config::get('web_path') . '/admin/index.php'); + show_confirmation(_('Album Updated'),'',Config::get('web_path') . '/admin/index.php'); break; // Show the page for editing a full artist case 'show_edit_artist': - $artist = new Artist($_REQUEST['artist_id']); + $artist = new Artist($_REQUEST['artist_id']); - require_once(conf('prefix') . '/templates/show_edit_artist.inc.php'); + require_once(conf('prefix') . '/templates/show_edit_artist.inc.php'); break; // Update all songs by this artist case 'edit_artist': // Build the needed artist - $artist = new Artist($_REQUEST['artist_id']); + $artist = new Artist($_REQUEST['artist_id']); // Create the needed objects, a pox on PHP4 - $catalog = new Catalog(); - $flag = new Flag(); + $catalog = new Catalog(); + $flag = new Flag(); /* Check the new Name */ - $artist_id = $catalog->check_artist($_REQUEST['name']); + $artist_id = $catalog->check_artist($_REQUEST['name']); - $songs = $artist->get_songs(); + $songs = $artist->get_songs(); - foreach ($songs as $song) { + foreach ($songs as $song) { // Make that copy and change the artist - $new_song = $song; - $new_song->artist = $artist_id; - - $song->update_song($song->id,$new_song); + $new_song = $song; + $new_song->artist = $artist_id; - if ($_REQUEST['flag'] == '1') { - $flag->add($song->id,'song','retag','Edited Song, auto-tag'); - } + $song->update_song($song->id,$new_song); + + if ($_REQUEST['flag'] == '1') { + $flag->add($song->id,'song','retag','Edited Song, auto-tag'); + } } // end foreach songs // Clean out the old artist(s) - $catalog->clean_artists(); + $catalog->clean_artists(); show_confirmation(_('Artist Updated'),'',Config::get('web_path') . '/admin/index.php'); - break; + break; /* Done by 'Select' code passes array of song ids */ - case 'mass_update': - $songs = $_REQUEST['song']; + case 'mass_update': + $songs = $_REQUEST['song']; $catalog = new Catalog(); - $object = $_REQUEST['update_field']; - $flag = new Flag(); + $object = $_REQUEST['update_field']; + $flag = new Flag(); /* If this is an album we need to pull the songs */ - if ($_REQUEST['type'] == 'album') { + if ($_REQUEST['type'] == 'album') { - // Define the results array - $results = array(); + // Define the results array + $results = array(); - foreach ($songs as $album_id) { - $album = new Album($album_id); - $results = array_merge($results,$album->get_song_ids()); + foreach ($songs as $album_id) { + $album = new Album($album_id); + $results = array_merge($results,$album->get_song_ids()); } // end foreach albums - // Re-assign the variable... HACK ALERT :( - $songs = $results; + // Re-assign the variable... HACK ALERT :( + $songs = $results; - } // is album + } // is album /* Foreach the songs we need to update */ - foreach ($songs as $song_id) { + foreach ($songs as $song_id) { $new_song = new Song($song_id); $old_song = new Song(); @@ -206,21 +206,21 @@ switch ($_REQUEST['action']) { $old_song->genre = $new_song->genre; /* Restrict which fields can be updated */ - switch ($object) { - case 'genre': - $new_song->genre = $catalog->check_genre(revert_string($_REQUEST['update_value'])); + switch ($object) { + case 'genre': + $new_song->genre = $catalog->check_genre(revert_string($_REQUEST['update_value'])); break; case 'album': - $new_song->album = $catalog->check_album(revert_string($_REQUEST['update_value'])); + $new_song->album = $catalog->check_album(revert_string($_REQUEST['update_value'])); break; case 'artist': - $new_song->artist = $catalog->check_artist(revert_string($_REQUEST['update_value'])); - break; - case 'year': - $new_song->year = intval($_REQUEST['update_value']); + $new_song->artist = $catalog->check_artist(revert_string($_REQUEST['update_value'])); break; - default: - // Rien a faire + case 'year': + $new_song->year = intval($_REQUEST['update_value']); + break; + default: + // Rien a faire break; } // end switch @@ -235,14 +235,14 @@ switch ($_REQUEST['action']) { } // end foreach songs // Show a confirmation that this worked - show_confirmation(_('Songs Updated'),'',return_referer()); - break; + show_confirmation(_('Songs Updated'),'',return_referer()); + break; case 'reject_flag': $flag_id = scrub_in($_REQUEST['flag_id']); $flag = new Flag($flag_id); - $flag->delete_flag(); + $flag->delete_flag(); $flag->format_name(); - $url = return_referer(); + $url = return_referer(); $title = _('Flag Removed'); $body = _('Flag Removed from') . " " . $flag->name; show_confirmation($title,$body,$url); @@ -250,22 +250,22 @@ switch ($_REQUEST['action']) { case 'reject_flags': $flags = $_REQUEST['song']; - foreach ($flags as $flag_id) { - $flag = new Flag($flag_id); - if ($_REQUEST['update_action'] == 'reject') { - $flag->delete_flag(); - } - else { - $flag->approve(); - } + foreach ($flags as $flag_id) { + $flag = new Flag($flag_id); + if ($_REQUEST['update_action'] == 'reject') { + $flag->delete_flag(); + } + else { + $flag->approve(); + } } // end foreach flags - $title = _('Flags Updated'); - show_confirmation($title,'',return_referer()); + $title = _('Flags Updated'); + show_confirmation($title,'',return_referer()); break; case 'show_edit_song': $_SESSION['source'] = return_referer(); $song = new Song($_REQUEST['song']); - $song->fill_ext_info(); + $song->fill_ext_info(); $song->format_song(); require_once (conf('prefix') . '/templates/show_edit_song.inc.php'); break; @@ -291,20 +291,20 @@ switch ($_REQUEST['action']) { } // end else show_confirmation(_('Songs Enabled'),_('The requested song(s) have been enabled'),return_referer()); break; - case 'show_disabled': - $disabled = Flag::get_disabled(); - Browse::set_type('song'); - Browse::set_static_content(1); - Browse::save_objects($disabled); - Browse::show_objects($disabled); - break; + case 'show_disabled': + $disabled = Flag::get_disabled(); + Browse::set_type('song'); + Browse::set_static_content(1); + Browse::save_objects($disabled); + Browse::show_objects($disabled); + break; default: case 'show_flagged': $flagged = Flag::get_all(); - Flag::build_cache($flagged); - Browse::set_type('flagged'); + Flag::build_cache($flagged); + Browse::set_type('flagged'); Browse::set_static_content(1); - Browse::save_objects($flagged); + Browse::save_objects($flagged); Browse::show_objects($flagged); break; } // end switch diff --git a/admin/index.php b/admin/index.php index 24f358ad..ccb77661 100644 --- a/admin/index.php +++ b/admin/index.php @@ -22,21 +22,21 @@ require '../lib/init.php'; -if (!Access::check('interface',100)) { +if (!Access::check('interface',100)) { access_denied(); exit(); } -show_header(); +show_header(); -switch ($_REQUEST['action']) { - default: +switch ($_REQUEST['action']) { + default: // Show Catalogs - $catalog_ids = Catalog::get_catalogs(); - Browse::set_type('catalog'); - Browse::show_objects($catalog_ids); + $catalog_ids = Catalog::get_catalogs(); + Browse::set_type('catalog'); + Browse::show_objects($catalog_ids); break; -} +} -show_footer(); +show_footer(); ?> diff --git a/admin/mail.php b/admin/mail.php index e1eaf0c2..18bcb100 100644 --- a/admin/mail.php +++ b/admin/mail.php @@ -22,20 +22,20 @@ require_once '../lib/init.php'; -if (!Access::check('interface','75')) { +if (!Access::check('interface','75')) { access_denied(); exit(); } -show_header(); +show_header(); // Action switch -switch ($_REQUEST['action']) { +switch ($_REQUEST['action']) { case 'send_mail': - if (Config::get('demo_mode')) { - access_denied(); + if (Config::get('demo_mode')) { + access_denied(); exit; - } + } // Multi-byte Character Mail if(function_exists('mb_language')) { @@ -43,21 +43,21 @@ switch ($_REQUEST['action']) { mb_language("uni"); } - $clients = AmpacheMail::get_users($_REQUEST['to']); + $clients = AmpacheMail::get_users($_REQUEST['to']); - foreach ($clients as $client) { + foreach ($clients as $client) { if(function_exists('mb_encode_mimeheader')) { $recipient .= mb_encode_mimeheader($client['fullname']) ." <" . $client['email'] . ">, "; } else { $recipient .= $client['fullname'] ." <" . $client['email'] . ">, "; } } - + // Remove the last , from the recipient $recipient = rtrim($recipient,", "); - + // Set the vars on the object - AmpacheMail::$recipient = $recipient; + AmpacheMail::$recipient = $recipient; if(function_exists('mb_encode_mimeheader')) { AmpacheMail::$fullname = mb_encode_mimeheader($GLOBALS['user']->fullname); } else { @@ -77,16 +77,16 @@ switch ($_REQUEST['action']) { /* Confirmation Send */ $url = Config::get('web_path') . '/admin/mail.php'; - $title = _('E-mail Sent'); + $title = _('E-mail Sent'); $body = _('Your E-mail was successfully sent.'); show_confirmation($title,$body,$url); break; - default: + default: require_once Config::get('prefix') . '/templates/show_mail_users.inc.php'; break; } // end switch -show_footer(); +show_footer(); ?> diff --git a/admin/modules.php b/admin/modules.php index 5f3270d1..fd1e14b9 100644 --- a/admin/modules.php +++ b/admin/modules.php @@ -30,40 +30,40 @@ if (!$GLOBALS['user']->has_access(100)) { /* Always show the header */ -show_header(); +show_header(); -switch ($_REQUEST['action']) { - case 'install_localplay': - $localplay = new Localplay($_REQUEST['type']); - if (!$localplay->player_loaded()) { - Error::add('general',_('Install Failed, Controller Error')); - Error::display('general'); +switch ($_REQUEST['action']) { + case 'install_localplay': + $localplay = new Localplay($_REQUEST['type']); + if (!$localplay->player_loaded()) { + Error::add('general',_('Install Failed, Controller Error')); + Error::display('general'); break; - } + } // Install it! - $localplay->install(); + $localplay->install(); // Go ahead and enable Localplay (Admin->System) as we assume they want to do that // if they are enabling this - Preference::update('allow_localplay_playback','-1','1'); - Preference::update('localplay_level',$GLOBALS['user']->id,'100'); + Preference::update('allow_localplay_playback','-1','1'); + Preference::update('localplay_level',$GLOBALS['user']->id,'100'); Preference::update('localplay_controller',$GLOBALS['user']->id,$localplay->type); - header("Location:" . Config::get('web_path') . '/admin/modules.php?action=show_localplay'); + header("Location:" . Config::get('web_path') . '/admin/modules.php?action=show_localplay'); break; - case 'confirm_uninstall_localplay': - $type = scrub_in($_REQUEST['type']); - $url = Config::get('web_path') . '/admin/modules.php?action=uninstall_localplay&type=' . $type; - $title = _('Are you sure you want to remove this plugin?'); - $body = ''; - show_confirmation($title,$body,$url,1); + case 'confirm_uninstall_localplay': + $type = scrub_in($_REQUEST['type']); + $url = Config::get('web_path') . '/admin/modules.php?action=uninstall_localplay&type=' . $type; + $title = _('Are you sure you want to remove this plugin?'); + $body = ''; + show_confirmation($title,$body,$url,1); break; - case 'uninstall_localplay': - $type = scrub_in($_REQUEST['type']); + case 'uninstall_localplay': + $type = scrub_in($_REQUEST['type']); + + $localplay = new Localplay($type); + $localplay->uninstall(); - $localplay = new Localplay($type); - $localplay->uninstall(); - /* Show Confirmation */ $url = Config::get('web_path') . '/admin/modules.php?action=show_localplay'; $title = _('Plugin Deactivated'); @@ -72,49 +72,49 @@ switch ($_REQUEST['action']) { break; case 'install_plugin': /* Verify that this plugin exists */ - $plugins = Plugin::get_plugins(); - if (!array_key_exists($_REQUEST['plugin'],$plugins)) { - debug_event('plugins','Error: Invalid Plugin: ' . $_REQUEST['plugin'] . ' selected','1'); - break; - } - $plugin = new Plugin($_REQUEST['plugin']); - if (!$plugin->install()) { - debug_event('plugins','Error: Plugin Install Failed, ' . $_REQUEST['plugin'],'1'); - $url = Config::get('web_path') . '/admin/modules.php?action=show_plugins'; - $title = _('Unable to Install Plugin'); - $body = ''; - show_confirmation($title,$body,$url); - break; - } - - // Don't trust the plugin to this stuff - User::rebuild_all_preferences(); - - /* Show Confirmation */ - $url = Config::get('web_path') . '/admin/modules.php?action=show_plugins'; - $title = _('Plugin Activated'); - $body = ''; - show_confirmation($title,$body,$url); - break; - case 'confirm_uninstall_plugin': - $plugin = scrub_in($_REQUEST['plugin']); - $url = Config::get('web_path') . '/admin/modules.php?action=uninstall_plugin&plugin=' . $plugin; - $title = _('Are you sure you want to remove this plugin?'); - $body = ''; - show_confirmation($title,$body,$url,1); - break; - case 'uninstall_plugin': - /* Verify that this plugin exists */ - $plugins = Plugin::get_plugins(); + $plugins = Plugin::get_plugins(); if (!array_key_exists($_REQUEST['plugin'],$plugins)) { debug_event('plugins','Error: Invalid Plugin: ' . $_REQUEST['plugin'] . ' selected','1'); break; } $plugin = new Plugin($_REQUEST['plugin']); - $plugin->uninstall(); + if (!$plugin->install()) { + debug_event('plugins','Error: Plugin Install Failed, ' . $_REQUEST['plugin'],'1'); + $url = Config::get('web_path') . '/admin/modules.php?action=show_plugins'; + $title = _('Unable to Install Plugin'); + $body = ''; + show_confirmation($title,$body,$url); + break; + } + + // Don't trust the plugin to this stuff + User::rebuild_all_preferences(); + + /* Show Confirmation */ + $url = Config::get('web_path') . '/admin/modules.php?action=show_plugins'; + $title = _('Plugin Activated'); + $body = ''; + show_confirmation($title,$body,$url); + break; + case 'confirm_uninstall_plugin': + $plugin = scrub_in($_REQUEST['plugin']); + $url = Config::get('web_path') . '/admin/modules.php?action=uninstall_plugin&plugin=' . $plugin; + $title = _('Are you sure you want to remove this plugin?'); + $body = ''; + show_confirmation($title,$body,$url,1); + break; + case 'uninstall_plugin': + /* Verify that this plugin exists */ + $plugins = Plugin::get_plugins(); + if (!array_key_exists($_REQUEST['plugin'],$plugins)) { + debug_event('plugins','Error: Invalid Plugin: ' . $_REQUEST['plugin'] . ' selected','1'); + break; + } + $plugin = new Plugin($_REQUEST['plugin']); + $plugin->uninstall(); // Don't trust the plugin to do it - User::rebuild_all_preferences(); + User::rebuild_all_preferences(); /* Show Confirmation */ $url = Config::get('web_path') . '/admin/modules.php?action=show_plugins'; @@ -125,23 +125,23 @@ switch ($_REQUEST['action']) { case 'upgrade_plugin': break; - case 'show_plugins': - $plugins = Plugin::get_plugins(); - show_box_top(_('Plugins')); - require_once Config::get('prefix') . '/templates/show_plugins.inc.php'; - show_box_bottom(); + case 'show_plugins': + $plugins = Plugin::get_plugins(); + show_box_top(_('Plugins')); + require_once Config::get('prefix') . '/templates/show_plugins.inc.php'; + show_box_bottom(); break; - case 'show_localplay': - $controllers = Localplay::get_controllers(); - show_box_top(_('Localplay Controllers')); - require_once Config::get('prefix') . '/templates/show_localplay_controllers.inc.php'; - show_box_bottom(); + case 'show_localplay': + $controllers = Localplay::get_controllers(); + show_box_top(_('Localplay Controllers')); + require_once Config::get('prefix') . '/templates/show_localplay_controllers.inc.php'; + show_box_bottom(); break; - default: + default: // Rien a faire break; } // end switch -show_footer(); +show_footer(); ?> diff --git a/admin/shout.php b/admin/shout.php index 31b7405a..b88ab1c1 100644 --- a/admin/shout.php +++ b/admin/shout.php @@ -26,18 +26,18 @@ if (!Access::check('interface','100')) { exit; } -show_header(); +show_header(); // Switch on the incomming action -switch ($_REQUEST['action']) { - case 'edit_shout': - $shout_id = $_POST['shout_id']; - $update = shoutBox::update($_POST); +switch ($_REQUEST['action']) { + case 'edit_shout': + $shout_id = $_POST['shout_id']; + $update = shoutBox::update($_POST); show_confirmation(_('Shoutbox Post Updated'),'',Config::get('web_path').'/admin/shout.php'); - break; + break; case 'show_edit': $shout = new shoutBox($_REQUEST['shout_id']); - $object = shoutBox::get_object($shout->object_type,$shout->object_id); + $object = shoutBox::get_object($shout->object_type,$shout->object_id); $object->format(); $client = new User($shout->user); $client->format(); @@ -48,12 +48,12 @@ switch ($_REQUEST['action']) { show_confirmation(_('Shoutbox Post Deleted'),'',Config::get('web_path').'/admin/shout.php'); break; default: - Browse::set_type('shoutbox'); - Browse::set_simple_browse(1); - $shoutbox_ids = Browse::get_objects(); - Browse::show_objects($shoutbox_ids); - break; + Browse::set_type('shoutbox'); + Browse::set_simple_browse(1); + $shoutbox_ids = Browse::get_objects(); + Browse::show_objects($shoutbox_ids); + break; } // end switch on action -show_footer(); +show_footer(); ?> diff --git a/admin/system.php b/admin/system.php index 85cf143e..c986cb51 100644 --- a/admin/system.php +++ b/admin/system.php @@ -29,35 +29,35 @@ if (!Access::check('interface',100) OR Config::get('demo_mode')) { exit(); } -show_header(); +show_header(); /* Switch on action boys */ -switch ($_REQUEST['action']) { +switch ($_REQUEST['action']) { /* This re-generates the config file comparing * /config/ampache.cfg to .cfg.dist */ case 'generate_config': - ob_end_clean(); + ob_end_clean(); $current = parse_ini_file(Config::get('prefix') . '/config/ampache.cfg.php'); $final = generate_config($current); - $browser = new Browser(); - $browser->downloadHeaders('ampache.cfg.php','text/plain',false,filesize(Config::get('prefix') . '/config/ampache.cfg.php.dist')); - echo $final; - exit; + $browser = new Browser(); + $browser->downloadHeaders('ampache.cfg.php','text/plain',false,filesize(Config::get('prefix') . '/config/ampache.cfg.php.dist')); + echo $final; + exit; break; case 'reset_db_charset': - Dba::reset_db_charset(); - show_confirmation(_('Database Charset Updated'),_('Your Database and associated tables have been updated to match your currently configured charset'), Config::get('web_path').'/admin/system.php?action=show_debug'); - break; - case 'show_debug': + Dba::reset_db_charset(); + show_confirmation(_('Database Charset Updated'),_('Your Database and associated tables have been updated to match your currently configured charset'), Config::get('web_path').'/admin/system.php?action=show_debug'); + break; + case 'show_debug': $configuration = Config::get_all(); require_once Config::get('prefix') . '/templates/show_debug.inc.php'; - break; - default: + break; + default: // Rien a faire break; } // end switch -show_footer(); +show_footer(); ?> diff --git a/admin/users.php b/admin/users.php index c871a5e7..5ed49043 100644 --- a/admin/users.php +++ b/admin/users.php @@ -22,22 +22,22 @@ require_once '../lib/init.php'; -if (!Access::check('interface','100')) { +if (!Access::check('interface','100')) { access_denied(); exit(); } -show_header(); +show_header(); -// Switch on the actions +// Switch on the actions switch ($_REQUEST['action']) { case 'update_user': if (Config::get('demo_mode')) { break; } - if (!Core::form_verify('edit_user','post')) { - access_denied(); - exit; - } + if (!Core::form_verify('edit_user','post')) { + access_denied(); + exit; + } /* Clean up the variables */ $user_id = scrub_in($_POST['user_id']); @@ -47,49 +47,49 @@ switch ($_REQUEST['action']) { $access = scrub_in($_POST['access']); $pass1 = scrub_in($_POST['password_1']); $pass2 = scrub_in($_POST['password_2']); - - /* Setup the temp user */ + + /* Setup the temp user */ $client = new User($user_id); - + /* Verify Input */ - if (empty($username)) { + if (empty($username)) { Error::add('username',_("Error Username Required")); } - if ($pass1 !== $pass2 && !empty($pass1)) { + if ($pass1 !== $pass2 && !empty($pass1)) { Error::add('password',_("Error Passwords don't match")); } /* If we've got an error then break! */ - if (Error::occurred()) { + if (Error::occurred()) { $_REQUEST['action'] = 'show_edit'; break; } // if we've had an oops! - if ($access != $client->access) { + if ($access != $client->access) { $client->update_access($access); } - if ($email != $client->email) { + if ($email != $client->email) { $client->update_email($email); } - if ($username != $client->username) { + if ($username != $client->username) { $client->update_username($username); - } + } if ($fullname != $client->fullname) { $client->update_fullname($fullname); } - if ($pass1 == $pass2 && strlen($pass1)) { + if ($pass1 == $pass2 && strlen($pass1)) { $client->update_password($pass1); - } - + } + show_confirmation(_('User Updated'), $client->fullname . "(" . $client->username . ")" . _('updated'), Config::get('web_path'). '/admin/users.php'); break; case 'add_user': if (Config::get('demo_mode')) { break; } - if (!Core::form_verify('add_user','post')) { + if (!Core::form_verify('add_user','post')) { access_denied(); exit; - } + } $username = scrub_in($_POST['username']); $fullname = scrub_in($_POST['fullname']); @@ -98,74 +98,74 @@ switch ($_REQUEST['action']) { $pass1 = scrub_in($_POST['password_1']); $pass2 = scrub_in($_POST['password_2']); - if ($pass1 !== $pass2 || !strlen($pass1)) { + if ($pass1 !== $pass2 || !strlen($pass1)) { Error::add('password',_("Error Passwords don't match")); } - if (empty($username)) { + if (empty($username)) { Error::add('username',_('Error Username Required')); } /* make sure the username doesn't already exist */ - if (!User::check_username($username)) { + if (!User::check_username($username)) { Error::add('username',_('Error Username already exists')); - } + } - if (!Error::occurred()) { + if (!Error::occurred()) { /* Attempt to create the user */ $user_id = User::create($username, $fullname, $email, $pass1, $access); - if (!$user_id) { + if (!$user_id) { Error::add('general',_("Error: Insert Failed")); } } // if no errors - else { + else { $_REQUEST['action'] = 'show_add_user'; break; } if ($access == 5){ $access = _('Guest');} elseif ($access == 25){ $access = _('User');} elseif ($access == 100){ $access = _('Admin');} - + /* HINT: %1 Username, %2 Access num */ show_confirmation(_('New User Added'),sprintf(_('%1$s has been created with an access level of %2$s'), $username, $access), Config::get('web_path').'/admin/users.php'); break; case 'enable': - $client = new User($_REQUEST['user_id']); - $client->enable(); - show_confirmation(_('User Enabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php'); + $client = new User($_REQUEST['user_id']); + $client->enable(); + show_confirmation(_('User Enabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php'); break; case 'disable': - $client = new User($_REQUEST['user_id']); - if ($client->disable()) { - show_confirmation(_('User Disabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php'); - } - else { - show_confirmation(_('Error'),_('Unable to Disabled last Administrator'), Config::get('web_path').'/admin/users.php'); - } + $client = new User($_REQUEST['user_id']); + if ($client->disable()) { + show_confirmation(_('User Disabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php'); + } + else { + show_confirmation(_('Error'),_('Unable to Disabled last Administrator'), Config::get('web_path').'/admin/users.php'); + } break; case 'show_edit': if (Config::get('demo_mode')) { break; } - $client = new User($_REQUEST['user_id']); + $client = new User($_REQUEST['user_id']); require_once Config::get('prefix') . '/templates/show_edit_user.inc.php'; break; case 'confirm_delete': if (Config::get('demo_mode')) { break; } - if (!Core::form_verify('delete_user')) { - access_denied(); - exit; - } - $client = new User($_REQUEST['user_id']); - if ($client->delete()) { + if (!Core::form_verify('delete_user')) { + access_denied(); + exit; + } + $client = new User($_REQUEST['user_id']); + if ($client->delete()) { show_confirmation(_('User Deleted'), sprintf(_('%s has been Deleted'), $client->username), Config::get('web_path'). "/admin/users.php"); } - else { + else { show_confirmation(_('Delete Error'), _("Unable to delete last Admin User"), Config::get('web_path')."/admin/users.php"); } break; case 'delete': if (Config::get('demo_mode')) { break; } - $client = new User($_REQUEST['user_id']); + $client = new User($_REQUEST['user_id']); show_confirmation(_('Deletion Request'), sprintf(_('Are you sure you want to permanently delete %s?'), $client->fullname), Config::get('web_path')."/admin/users.php?action=confirm_delete&user_id=" . $_REQUEST['user_id'],1,'delete_user'); @@ -173,11 +173,11 @@ switch ($_REQUEST['action']) { /* Show IP History for the Specified User */ case 'show_ip_history': /* get the user and their history */ - $working_user = new User($_REQUEST['user_id']); + $working_user = new User($_REQUEST['user_id']); if (!isset($_REQUEST['all'])){ $history = $working_user->get_ip_history(0,1); - } + } else { $history = $working_user->get_ip_history(); } @@ -187,18 +187,18 @@ switch ($_REQUEST['action']) { if (Config::get('demo_mode')) { break; } require_once Config::get('prefix') . '/templates/show_add_user.inc.php'; break; - case 'show_preferences': - $client = new User($_REQUEST['user_id']); - $preferences = Preference::get_all($client->id); + case 'show_preferences': + $client = new User($_REQUEST['user_id']); + $preferences = Preference::get_all($client->id); require_once Config::get('prefix') . '/templates/show_user_preferences.inc.php'; break; default: Browse::reset_filters(); - Browse::set_type('user'); + Browse::set_type('user'); Browse::set_simple_browse(1); Browse::set_sort('name','ASC'); - $user_ids = Browse::get_objects(); - Browse::show_objects($user_ids); + $user_ids = Browse::get_objects(); + Browse::show_objects($user_ids); break; } // end switch on action diff --git a/albums.php b/albums.php index 74f85ad2..3fce3720 100644 --- a/albums.php +++ b/albums.php @@ -25,9 +25,9 @@ require_once 'lib/init.php'; require_once Config::get('prefix') . '/templates/header.inc.php'; /* Switch on Action */ -switch ($_REQUEST['action']) { +switch ($_REQUEST['action']) { case 'clear_art': - if (!$GLOBALS['user']->has_access('75')) { access_denied(); } + if (!$GLOBALS['user']->has_access('75')) { access_denied(); } $album = new Album($_REQUEST['album_id']); $album->clear_art(); show_confirmation(_('Album Art Cleared'),_('Album Art information has been removed from the database'),"/albums.php?action=show&album=" . $album->id); @@ -35,29 +35,29 @@ switch ($_REQUEST['action']) { // Upload album art case 'upload_art': - // we didn't find anything - if (empty($_FILES['file']['tmp_name'])) { + // we didn't find anything + if (empty($_FILES['file']['tmp_name'])) { show_confirmation(_('Album Art Not Located'),_('Album Art could not be located at this time. This may be due to write access error, or the file is not received correctly.'),"/albums.php?action=show&album=" . $album->id); break; } - $album = new Album($_REQUEST['album_id']); - + $album = new Album($_REQUEST['album_id']); + // Pull the image information - $data = array('file'=>$_FILES['file']['tmp_name']); - $image_data = Album::get_image_from_source($data); + $data = array('file'=>$_FILES['file']['tmp_name']); + $image_data = Album::get_image_from_source($data); // If we got something back insert it - if ($image_data) { + if ($image_data) { $album->insert_art($image_data,$_FILES['file']['type']); show_confirmation(_('Album Art Inserted'),'',"/albums.php?action=show&album=" . $album->id); - } + } // Else it failed - else { + else { show_confirmation(_('Album Art Not Located'),_('Album Art could not be located at this time. This may be due to write access error, or the file is not received correctly.'),"/albums.php?action=show&album=" . $album->id); - } + } - break; + break; case 'find_art': // If not a user then kick em out @@ -65,61 +65,61 @@ switch ($_REQUEST['action']) { // get the Album information $album = new Album($_REQUEST['album_id']); - $album->format(); - $images = array(); - $cover_url = array(); + $album->format(); + $images = array(); + $cover_url = array(); // If we've got an upload ignore the rest and just insert it - if (!empty($_FILES['file']['tmp_name'])) { - $path_info = pathinfo($_FILES['file']['name']); + if (!empty($_FILES['file']['tmp_name'])) { + $path_info = pathinfo($_FILES['file']['name']); $upload['file'] = $_FILES['file']['tmp_name']; - $upload['mime'] = 'image/' . $path_info['extension']; - $image_data = Album::get_image_from_source($upload); + $upload['mime'] = 'image/' . $path_info['extension']; + $image_data = Album::get_image_from_source($upload); - if ($image_data) { - $album->insert_art($image_data,$upload['0']['mime']); + if ($image_data) { + $album->insert_art($image_data,$upload['0']['mime']); show_confirmation(_('Album Art Inserted'),'',"/albums.php?action=show&album=" . $_REQUEST['album_id']); break; } // if image data } // if it's an upload - + // Build the options for our search - if (isset($_REQUEST['artist_name'])) { + if (isset($_REQUEST['artist_name'])) { $artist = scrub_in($_REQUEST['artist_name']); - } - elseif ($album->artist_count == '1') { + } + elseif ($album->artist_count == '1') { $artist = $album->f_artist_name; } - if (isset($_REQUEST['album_name'])) { + if (isset($_REQUEST['album_name'])) { $album_name = scrub_in($_REQUEST['album_name']); } - else { + else { $album_name = $album->full_name; } - - $options['artist'] = $artist; - $options['album_name'] = $album_name; - $options['keyword'] = $artist . " " . $album_name; - - // Attempt to find the art. + + $options['artist'] = $artist; + $options['album_name'] = $album_name; + $options['keyword'] = $artist . " " . $album_name; + + // Attempt to find the art. $images = $album->find_art($options,'6'); - if (!empty($_REQUEST['cover'])) { - $path_info = pathinfo($_REQUEST['cover']); - $cover_url[0]['url'] = scrub_in($_REQUEST['cover']); + if (!empty($_REQUEST['cover'])) { + $path_info = pathinfo($_REQUEST['cover']); + $cover_url[0]['url'] = scrub_in($_REQUEST['cover']); $cover_url[0]['mime'] = 'image/' . $path_info['extension']; } - $images = array_merge($cover_url,$images); + $images = array_merge($cover_url,$images); - // If we've found anything then go for it! + // If we've found anything then go for it! if (count($images)) { // We don't want to store raw's in here so we need to strip them out into a seperate array - foreach ($images as $index=>$image) { - if ($image['raw']) { - unset($images[$index]['raw']); - } + foreach ($images as $index=>$image) { + if ($image['raw']) { + unset($images[$index]['raw']); + } } // end foreach // Store the results for further use $_SESSION['form']['images'] = $images; @@ -129,42 +129,42 @@ switch ($_REQUEST['action']) { else { show_confirmation(_('Album Art Not Located'),_('Album Art could not be located at this time. This may be due to write access error, or the file is not received correctly.'),"/albums.php?action=show&album=" . $album->id); } - + $albumname = $album->name; $artistname = $artist; - + // Remember the last typed entry, if there was one if (!empty($_REQUEST['album_name'])) { $albumname = scrub_in($_REQUEST['album_name']); } if (!empty($_REQUEST['artist_name'])) { $artistname = scrub_in($_REQUEST['artist_name']); } - + require_once Config::get('prefix') . '/templates/show_get_albumart.inc.php'; - + break; - case 'select_art': + case 'select_art': /* Check to see if we have the image url still */ $image_id = $_REQUEST['image']; $album_id = $_REQUEST['album_id']; - + $image = Album::get_image_from_source($_SESSION['form']['images'][$image_id]); $mime = $_SESSION['form']['images'][$image_id]['mime']; - + $album = new Album($album_id); $album->insert_art($image,$mime); - header("Location:" . Config::get('web_path') . "/albums.php?action=show&album=" . $album->id); + header("Location:" . Config::get('web_path') . "/albums.php?action=show&album=" . $album->id); break; case 'update_from_tags': // Make sure they are a 'power' user at least - if (!Access::check('interface','75')) { - access_denied(); - exit; - } + if (!Access::check('interface','75')) { + access_denied(); + exit; + } - $type = 'album'; - $object_id = intval($_REQUEST['album_id']); - $target_url = Config::get('web_path') . '/albums.php?action=show&album=' . $object_id; - require_once Config::get('prefix') . '/templates/show_update_items.inc.php'; + $type = 'album'; + $object_id = intval($_REQUEST['album_id']); + $target_url = Config::get('web_path') . '/albums.php?action=show&album=' . $object_id; + require_once Config::get('prefix') . '/templates/show_update_items.inc.php'; break; // Browse by Album default: @@ -173,7 +173,7 @@ switch ($_REQUEST['action']) { $album->format(); Browse::reset_filters(); require Config::get('prefix') . '/templates/show_album.inc.php'; - + break; } // switch on view diff --git a/artists.php b/artists.php index 634521dc..1f915d94 100644 --- a/artists.php +++ b/artists.php @@ -22,32 +22,32 @@ require_once 'lib/init.php'; -show_header(); +show_header(); /** - * Display Switch + * Display Switch */ switch($_REQUEST['action']) { case 'show': $artist = new Artist($_REQUEST['artist']); - $artist->format(); - $object_ids = $artist->get_albums(); - $object_type = 'album'; + $artist->format(); + $object_ids = $artist->get_albums(); + $object_type = 'album'; require_once Config::get('prefix') . '/templates/show_artist.inc.php'; break; case 'show_all_songs': $artist = new Artist($_REQUEST['artist']); $artist->format(); - $object_type = 'song'; - $object_ids = $artist->get_songs(); + $object_type = 'song'; + $object_ids = $artist->get_songs(); require_once Config::get('prefix') . '/templates/show_artist.inc.php'; break; case 'update_from_tags': - $type = 'artist'; - $object_id = intval($_REQUEST['artist']); - $target_url = Config::get('web_path') . "/artists.php?action=show&artist=" . $object_id; - require_once Config::get('prefix') . '/templates/show_update_items.inc.php'; + $type = 'artist'; + $object_id = intval($_REQUEST['artist']); + $target_url = Config::get('web_path') . "/artists.php?action=show&artist=" . $object_id; + require_once Config::get('prefix') . '/templates/show_update_items.inc.php'; break; case 'rename_similar': if (!$user->has_access('100')) { access_denied(); } @@ -81,14 +81,14 @@ switch($_REQUEST['action']) { } else { $GLOBALS['error']->print_error('general'); } - + break; case 'show_similar': - if (!$GLOBALS['user']->has_access('75')) { - access_denied(); - exit; + if (!$GLOBALS['user']->has_access('75')) { + access_denied(); + exit; } - + $artist = new Artist($_REQUEST['artist']); //options $similar_artists = $artist->get_similar_artists( @@ -103,23 +103,23 @@ switch($_REQUEST['action']) { $artist_id = $artist->id; $artist_name = $artist->name; require Config::get('prefix') . '/templates/show_similar_artists.inc.php'; - + break; case 'rename': //die if not enough permissions if (!$user->has_access('100')) { access_denied(); } - + /* Get the artist */ $artist = new Artist($_REQUEST['artist']); $catalog = new Catalog(); - + //check if we've been given a target if ((isset($_POST['artist_id']) && $_POST['artist_id'] != $artist->id ) || (isset($_POST['artist_name']) && $_POST['artist_name'] != "")) { - + //if we want to update id3 tags, then get the array of ids now, it's too late afterwards if (make_bool($_POST['update_id3'])) - $songs = $artist->get_songs(); - + $songs = $artist->get_songs(); + $ret = 0; //the manual rename takes priority, but if they tested out the insert thing ignore if ($_POST['artist_name'] != "" && $_POST['artist_name'] != $artist->name) { @@ -134,24 +134,24 @@ switch($_REQUEST['action']) { $ret = $artist->merge($_POST['artist_id']); $newid = $_POST['artist_id']; $newname = $ret; - } // elseif different artist and id + } // elseif different artist and id //if no changes, no changes - + //now flag for id3tag update if selected, and something actually happaned if ($ret && make_bool($_POST['update_id3'])) { - + /* Set the rename information in the db */ foreach ($songs as $song) { $flag = new Flag(); $flag->add($song->id,"song","retag","Renamed artist, retag"); - $flag_qstring = "REPLACE INTO flagged " . + $flag_qstring = "REPLACE INTO flagged " . "SET type = 'setid3', song = '" . $song->id . "', date = '" . time() . "', user = '" . $GLOBALS['user']->username . "'"; - mysql_query($flag_qstring, dbh()); + mysql_query($flag_qstring, dbh()); } - + } // end if they wanted to update - - // show something other than a blank screen after this + + // show something other than a blank screen after this if ($ret) { show_confirmation ( "Renamed artist", @@ -159,25 +159,25 @@ switch($_REQUEST['action']) { conf('web_path') . "/artists.php?action=show&artist=" . $newid ); } - + } // if we've got the needed variables /* Else we've got an error! But be lenient, and just show the form again */ - else { + else { require (conf('prefix') . '/templates/show_rename_artist.inc.php'); } - break; + break; case 'show_rename': $artist = new Artist($_REQUEST['artist']); - require (conf('prefix') . '/templates/show_rename_artist.inc.php'); + require (conf('prefix') . '/templates/show_rename_artist.inc.php'); break; case 'match': case 'Match': $match = scrub_in($_REQUEST['match']); if ($match == "Browse" || $match == "Show_all") { $chr = ""; } - else { $chr = $match; } + else { $chr = $match; } /* Enclose this in the purty box! */ - require (conf('prefix') . '/templates/show_box_top.inc.php'); + require (conf('prefix') . '/templates/show_box_top.inc.php'); show_alphabet_list('artists','artists.php',$match); show_alphabet_form($chr,_('Show Artists starting with'),"artists.php?action=match"); require (conf('prefix') . '/templates/show_box_bottom.inc.php'); @@ -188,7 +188,7 @@ switch($_REQUEST['action']) { elseif ($match === "Show_all") { $offset_limit = 999999; show_artists(); - } + } else { if ($chr == '') { show_artists('A'); @@ -197,7 +197,7 @@ switch($_REQUEST['action']) { show_artists($chr); } } - break; + break; } // end switch show_footer(); diff --git a/batch.php b/batch.php index b0684f38..3860cd44 100644 --- a/batch.php +++ b/batch.php @@ -21,20 +21,20 @@ */ require_once 'lib/init.php'; -ob_end_clean(); +ob_end_clean(); //test that batch download is permitted -if (!Access::check_function('batch_download')) { - access_denied(); - exit; +if (!Access::check_function('batch_download')) { + access_denied(); + exit; } /* Drop the normal Time limit constraints, this can take a while */ set_time_limit(0); switch ($_REQUEST['action']) { - case 'tmp_playlist': - $media_ids = $GLOBALS['user']->playlist->get_items(); + case 'tmp_playlist': + $media_ids = $GLOBALS['user']->playlist->get_items(); $name = $GLOBALS['user']->username . ' - Playlist'; break; case 'playlist': @@ -47,28 +47,28 @@ switch ($_REQUEST['action']) { $media_ids = $album->get_songs(); $name = $album->name; break; - case 'artist': - $artist = new Artist($_REQUEST['id']); - $media_ids = $artist->get_songs(); - $name = $artist->name; + case 'artist': + $artist = new Artist($_REQUEST['id']); + $media_ids = $artist->get_songs(); + $name = $artist->name; break; case 'genre': - $id = scrub_in($_REQUEST['id']); - $genre = new Genre($id); + $id = scrub_in($_REQUEST['id']); + $genre = new Genre($id); $media_ids = $genre->get_songs(); - $name = $genre->name; + $name = $genre->name; break; - case 'browse': - $media_ids = Browse::get_saved(); - $name = 'Batch-' . date("dmY",time()); + case 'browse': + $media_ids = Browse::get_saved(); + $name = 'Batch-' . date("dmY",time()); default: // Rien a faire break; -} // action switch +} // action switch // Take whatever we've got and send the zip -$song_files = get_song_files($media_ids); -set_memory_limit($song_files['1']+32); -send_zip($name,$song_files['0']); -exit; +$song_files = get_song_files($media_ids); +set_memory_limit($song_files['1']+32); +send_zip($name,$song_files['0']); +exit; ?> diff --git a/browse.php b/browse.php index 73cd37d1..616f2588 100644 --- a/browse.php +++ b/browse.php @@ -24,7 +24,7 @@ * * Browse By Page * This page shows the browse menu, which allows you to browse by many different - * fields including genre, artist, album, catalog, ??? + * fields including genre, artist, album, catalog, ??? * this page also handles the actuall browse action * */ @@ -34,70 +34,70 @@ require_once 'lib/init.php'; // This page is a little wonky we don't want the sidebar until we know what type we're dealing with // so we've got a little switch here that creates the type.. this feels hackish... -switch ($_REQUEST['action']) { - case 'tag': - case 'file': - case 'album': - case 'artist': - case 'playlist': - case 'live_stream': - case 'video': - case 'song': - Browse::set_type($_REQUEST['action']); - Browse::reset(); - Browse::set_simple_browse(true); - break; -} // end switch +switch ($_REQUEST['action']) { + case 'tag': + case 'file': + case 'album': + case 'artist': + case 'playlist': + case 'live_stream': + case 'video': + case 'song': + Browse::set_type($_REQUEST['action']); + Browse::reset(); + Browse::set_simple_browse(true); + break; +} // end switch -show_header(); +show_header(); switch($_REQUEST['action']) { case 'file': - break; + break; case 'album': Browse::set_sort('name','ASC'); - Browse::show_objects(); + Browse::show_objects(); break; - case 'tag': - Browse::set_sort('count','ASC'); + case 'tag': + Browse::set_sort('count','ASC'); // This one's a doozy - Browse::set_simple_browse(0); - Browse::save_objects(Tag::get_tags(Config::get('offset_limit'),array())); - $keys = array_keys(Browse::get_saved()); - Tag::build_cache($keys); - $object_ids = Browse::get_saved(); - show_box_top(_('Tag Cloud'),$class); - require_once Config::get('prefix') . '/templates/show_tagcloud.inc.php'; - show_box_bottom(); - require_once Config::get('prefix') . '/templates/browse_content.inc.php'; - break; + Browse::set_simple_browse(0); + Browse::save_objects(Tag::get_tags(Config::get('offset_limit'),array())); + $keys = array_keys(Browse::get_saved()); + Tag::build_cache($keys); + $object_ids = Browse::get_saved(); + show_box_top(_('Tag Cloud'),$class); + require_once Config::get('prefix') . '/templates/show_tagcloud.inc.php'; + show_box_bottom(); + require_once Config::get('prefix') . '/templates/browse_content.inc.php'; + break; case 'artist': Browse::set_sort('name','ASC'); - Browse::show_objects(); + Browse::show_objects(); break; case 'song': Browse::set_sort('title','ASC'); - Browse::show_objects(); + Browse::show_objects(); break; case 'live_stream': Browse::set_sort('name','ASC'); - Browse::show_objects(); + Browse::show_objects(); break; case 'catalog': - + break; - case 'playlist': + case 'playlist': Browse::set_sort('type','ASC'); Browse::set_filter('playlist_type','1'); - Browse::show_objects(); + Browse::show_objects(); break; - case 'video': - Browse::set_sort('title','ASC'); - Browse::show_objects(); - break; - default: + case 'video': + Browse::set_sort('title','ASC'); + Browse::show_objects(); + break; + default: - break; + break; } // end Switch $action /* Show the Footer */ diff --git a/democratic.php b/democratic.php index 65e1a846..76279c66 100644 --- a/democratic.php +++ b/democratic.php @@ -23,104 +23,104 @@ require_once 'lib/init.php'; /* Make sure they have access to this */ -if (!Config::get('allow_democratic_playback')) { - access_denied(); +if (!Config::get('allow_democratic_playback')) { + access_denied(); exit; } -show_header(); +show_header(); // Switch on their action -switch ($_REQUEST['action']) { - case 'manage': +switch ($_REQUEST['action']) { + case 'manage': $democratic = Democratic::get_current_playlist(); $democratic->set_parent(); $democratic->format(); - case 'show_create': - if (!Access::check('interface','75')) { - access_denied(); + case 'show_create': + if (!Access::check('interface','75')) { + access_denied(); break; - } + } // Show the create page - require_once Config::get('prefix') . '/templates/show_create_democratic.inc.php'; - break; - case 'delete': - if (!Access::check('interface','75')) { - access_denied(); - break; - } - - Democratic::delete($_REQUEST['democratic_id']); - - $title = ''; - $text = _('The Requested Playlist has been deleted.'); - $url = Config::get('web_path') . '/democratic.php?action=manage_playlists'; - show_confirmation($title,$text,$url); - break; - case 'create': - // Only power users here - if (!Access::check('interface','75')) { - access_denied(); + require_once Config::get('prefix') . '/templates/show_create_democratic.inc.php'; + break; + case 'delete': + if (!Access::check('interface','75')) { + access_denied(); break; - } + } - if (!Core::form_verify('create_democratic')) { - access_denied(); - exit; - } - - $democratic = Democratic::get_current_playlist(); + Democratic::delete($_REQUEST['democratic_id']); + + $title = ''; + $text = _('The Requested Playlist has been deleted.'); + $url = Config::get('web_path') . '/democratic.php?action=manage_playlists'; + show_confirmation($title,$text,$url); + break; + case 'create': + // Only power users here + if (!Access::check('interface','75')) { + access_denied(); + break; + } + + if (!Core::form_verify('create_democratic')) { + access_denied(); + exit; + } + + $democratic = Democratic::get_current_playlist(); // If we don't have anything currently create something - if (!$democratic->id) { + if (!$democratic->id) { // Create the playlist - Democratic::create($_POST); - $democratic = Democratic::get_current_playlist(); - } - else { - $democratic->update($_POST); - } + Democratic::create($_POST); + $democratic = Democratic::get_current_playlist(); + } + else { + $democratic->update($_POST); + } // Now check for additional things we might have to do - if ($_POST['force_democratic']) { - Democratic::set_user_preferences(); - } + if ($_POST['force_democratic']) { + Democratic::set_user_preferences(); + } - header("Location: " . Config::get('web_path') . "/democratic.php?action=show"); - break; - case 'manage_playlists': - if (!Access::check('interface','75')) { - access_denied(); + header("Location: " . Config::get('web_path') . "/democratic.php?action=show"); + break; + case 'manage_playlists': + if (!Access::check('interface','75')) { + access_denied(); break; - } + } // Get all of the non-user playlists - $playlists = Democratic::get_playlists(); + $playlists = Democratic::get_playlists(); - require_once Config::get('prefix') . '/templates/show_manage_democratic.inc.php'; + require_once Config::get('prefix') . '/templates/show_manage_democratic.inc.php'; break; - case 'show_playlist': - default: - $democratic = Democratic::get_current_playlist(); - if (!$democratic->id) { - require_once Config::get('prefix') . '/templates/show_democratic.inc.php'; - break; - } + case 'show_playlist': + default: + $democratic = Democratic::get_current_playlist(); + if (!$democratic->id) { + require_once Config::get('prefix') . '/templates/show_democratic.inc.php'; + break; + } - $democratic->set_parent(); - $democratic->format(); - require_once Config::get('prefix') . '/templates/show_democratic.inc.php'; + $democratic->set_parent(); + $democratic->format(); + require_once Config::get('prefix') . '/templates/show_democratic.inc.php'; $objects = $democratic->get_items(); - Song::build_cache($democratic->object_ids); - Democratic::build_vote_cache($democratic->vote_ids); - Browse::set_type('democratic'); - Browse::reset(); - Browse::set_static_content(1); - Browse::show_objects($objects); + Song::build_cache($democratic->object_ids); + Democratic::build_vote_cache($democratic->vote_ids); + Browse::set_type('democratic'); + Browse::reset(); + Browse::set_static_content(1); + Browse::show_objects($objects); break; } // end switch on action -show_footer(); +show_footer(); ?> diff --git a/flag.php b/flag.php index da031bc2..da71c4cc 100644 --- a/flag.php +++ b/flag.php @@ -34,7 +34,7 @@ $action = scrub_in($_REQUEST['action']); $flag = new Flag($_REQUEST['flag_id']); /* Switch on the action */ -switch ($action) { +switch ($action) { case 'remove_flag': break; case 'flag': @@ -42,7 +42,7 @@ switch ($action) { $type = scrub_in($_REQUEST['type']); $flag_type = scrub_in($_REQUEST['flag_type']); $comment = scrub_in($_REQUEST['comment']); - $flag->add($id,$type,$flag_type,$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': @@ -51,10 +51,10 @@ switch ($action) { include(conf('prefix') . '/templates/show_flag.inc.php'); break; case 'show_remove_flag': - + break; default: - + break; } // end action switch diff --git a/genre.php b/genre.php index 7355b73d..d8a37620 100644 --- a/genre.php +++ b/genre.php @@ -28,19 +28,19 @@ require_once 'lib/init.php'; show_header(); /** - * switch on action + * switch on action */ -switch($_REQUEST['action']) { +switch($_REQUEST['action']) { case 'show_songs': $genre = new Genre($_REQUEST['genre_id']); show_genre($_REQUEST['genre_id']); $object_ids = $genre->get_songs(); - Browse::reset_filters(); - Browse::set_type('song'); - Browse::set_sort('name','ASC'); - Browse::set_static_content(1); + Browse::reset_filters(); + Browse::set_type('song'); + Browse::set_sort('name','ASC'); + Browse::set_static_content(1); Browse::save_objects($object_ids); - Browse::show_objects($object_ids); + Browse::show_objects($object_ids); break; case 'show_genre': default: @@ -48,23 +48,23 @@ switch($_REQUEST['action']) { $genre = new Genre($_REQUEST['genre_id']); show_genre($_REQUEST['genre_id']); $object_ids = $genre->get_albums(); - Browse::reset_filters(); - Browse::set_type('album'); - Browse::set_sort('name','ASC'); - Browse::set_static_content(1); - Browse::save_objects($object_ids); - Browse::show_objects($object_ids); + Browse::reset_filters(); + Browse::set_type('album'); + Browse::set_sort('name','ASC'); + Browse::set_static_content(1); + Browse::save_objects($object_ids); + Browse::show_objects($object_ids); break; case 'show_artists': $genre = new Genre($_REQUEST['genre_id']); show_genre($_REQUEST['genre_id']); $object_ids = $genre->get_artists(); - Browse::reset_filters(); - Browse::set_type('artist'); - Browse::set_sort('name','ASC'); - Browse::set_static_content(1); - Browse::save_objects($object_ids); - Browse::show_objects($object_ids); + Browse::reset_filters(); + Browse::set_type('artist'); + Browse::set_sort('name','ASC'); + Browse::set_static_content(1); + Browse::save_objects($object_ids); + Browse::show_objects($object_ids); break; } // action diff --git a/image.php b/image.php index 7e30c176..cd629013 100644 --- a/image.php +++ b/image.php @@ -23,22 +23,22 @@ * Album Art * This pulls album art out of the file using the getid3 library * and dumps it to the browser as an image mime type. - * + * */ // This file is a little weird it needs to allow API session // this needs to be done a little better, but for now... eah -define('NO_SESSION','1'); +define('NO_SESSION','1'); require 'lib/init.php'; // Check to see if they've got an interface session or a valid API session, if not GTFO -if (!vauth::session_exists('interface',$_COOKIE[Config::get('session_name')]) AND !vauth::session_exists('api',$_REQUEST['auth']) AND !vauth::session_exists('xml-rpc',$_REQUEST['auth'])) { +if (!vauth::session_exists('interface',$_COOKIE[Config::get('session_name')]) AND !vauth::session_exists('api',$_REQUEST['auth']) AND !vauth::session_exists('xml-rpc',$_REQUEST['auth'])) { debug_event('DENIED','Image Access, Checked Cookie Session:' . $_COOKIE[Config::get('session_name')] . ' and Auth:' . $_REQUEST['auth'],'1'); - exit; -} + exit; +} /* Decide what size this image is */ -switch ($_REQUEST['thumb']) { +switch ($_REQUEST['thumb']) { case '1': /* This is used by the now_playing stuff */ $size['height'] = '75'; @@ -47,13 +47,13 @@ switch ($_REQUEST['thumb']) { case '2': $size['height'] = '128'; $size['width'] = '128'; - // $return_raw = true; + // $return_raw = true; break; case '3': /* This is used by the flash player */ $size['height'] = '80'; $size['width'] = '80'; - // $return_raw = true; + // $return_raw = true; break; default: $size['height'] = '275'; @@ -62,35 +62,35 @@ switch ($_REQUEST['thumb']) { break; } // define size based on thumbnail -switch ($_REQUEST['type']) { +switch ($_REQUEST['type']) { case 'popup': require_once Config::get('prefix') . '/templates/show_big_art.inc.php'; break; - // If we need to pull the data out of the session + // If we need to pull the data out of the session case 'session': - vauth::check_session(); - $key = scrub_in($_REQUEST['image_index']); + vauth::check_session(); + $key = scrub_in($_REQUEST['image_index']); $image = Album::get_image_from_source($_SESSION['form']['images'][$key]); $mime = $_SESSION['form']['images'][$key]['mime']; - $data = explode("/",$mime); - $extension = $data['1']; + $data = explode("/",$mime); + $extension = $data['1']; // Send the headers and output the image header("Expires: Sun, 19 Nov 1978 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Pragma: no-cache"); - header("Content-type: $mime"); - header("Content-Disposition: filename=" . $key . "." . $extension); - echo $image; + header("Content-type: $mime"); + header("Content-Disposition: filename=" . $key . "." . $extension); + echo $image; break; - default: + default: $album = new Album($_REQUEST['id']); // Attempt to pull art from the database $art = $album->get_art($return_raw); $mime = $art['mime']; - if (!$mime) { + if (!$mime) { header('Content-type: image/jpeg'); readfile(Config::get('prefix') . Config::get('theme_path') . '/images/blankalbum.jpg'); break; @@ -99,21 +99,21 @@ switch ($_REQUEST['type']) { // Print the album art $data = explode("/",$mime); $extension = $data['1']; - - if (empty($_REQUEST['thumb'])) { + + if (empty($_REQUEST['thumb'])) { $art_data = $art['raw']; } - else { + else { $art_data = img_resize($art,array('width'=>'275','height'=>'275'),$extension,$_REQUEST['id']); } - + // Send the headers and output the image - header("Expires: Sun, 19 Nov 1978 05:00:00 GMT"); + header("Expires: Sun, 19 Nov 1978 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-type: $mime"); - header("Content-Disposition: filename=" . $album->name . "." . $extension); + header("Content-Disposition: filename=" . $album->name . "." . $extension); echo $art_data; break; diff --git a/index.php b/index.php index f25db948..d6cb7f7d 100644 --- a/index.php +++ b/index.php @@ -22,7 +22,7 @@ require_once 'lib/init.php'; -show_header(); +show_header(); $action = scrub_in($_REQUEST['action']); @@ -31,14 +31,14 @@ $action = scrub_in($_REQUEST['action']); * refresh_javascript include. Must be greater then 5, I'm not * going to let them break their servers */ -if (Config::get('refresh_limit') > 5) { - $refresh_limit = Config::get('refresh_limit'); +if (Config::get('refresh_limit') > 5) { + $refresh_limit = Config::get('refresh_limit'); $ajax_url = Config::get('ajax_url') . '?page=index&action=reloadnp'; require_once Config::get('prefix') . '/templates/javascript_refresh.inc.php'; } require_once Config::get('prefix') . '/templates/show_index.inc.php'; -show_footer(); +show_footer(); ?> diff --git a/lib/batch.lib.php b/lib/batch.lib.php index aca73874..e79a55d0 100644 --- a/lib/batch.lib.php +++ b/lib/batch.lib.php @@ -8,7 +8,7 @@ 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 @@ -28,20 +28,20 @@ */ function get_song_files($media_ids) { - $media_files = array(); - + $media_files = array(); + foreach ($media_ids as $element) { - if (is_array($element)) { - $type = array_shift($element); - $media = new $type(array_shift($element)); - } - else { - $media = new Song($element); - } - if ($media->enabled) { + if (is_array($element)) { + $type = array_shift($element); + $media = new $type(array_shift($element)); + } + else { + $media = new Song($element); + } + if ($media->enabled) { $total_size += sprintf("%.2f",($media->size/1048576)); array_push($media_files, $media->file); - } + } } return array($media_files,$total_size); @@ -59,19 +59,19 @@ function send_zip( $name, $song_files ) { // Check if they want to save it to a file, if so then make sure they've got // a defined path as well and that it's writeable - if (Config::get('file_zip_download') && Config::get('file_zip_path')) { + if (Config::get('file_zip_download') && Config::get('file_zip_path')) { // Check writeable - if (!is_writable(Config::get('file_zip_path'))) { - $in_memory = '1'; - debug_event('Error','File Zip Path:' . Config::get('file_zip_path') . ' is not writeable','1'); - } - else { - $in_memory = '0'; - $basedir = Config::get('file_zip_path'); - } + if (!is_writable(Config::get('file_zip_path'))) { + $in_memory = '1'; + debug_event('Error','File Zip Path:' . Config::get('file_zip_path') . ' is not writeable','1'); + } + else { + $in_memory = '0'; + $basedir = Config::get('file_zip_path'); + } } else { - $in_memory = '1'; + $in_memory = '1'; } // if file downloads /* Require needed library */ @@ -84,20 +84,20 @@ function send_zip( $name, $song_files ) { 'level' => 0, // no compression 'comment' => Config::get('file_zip_comment') ); - + $arc->set_options( $options ); $arc->add_files( $song_files ); - if (count($arc->error)) { + if (count($arc->error)) { debug_event('archive',"Error: unable to add songs",'3'); - return false; + return false; } // if failed to add songs - - if (!$arc->create_archive()) { + + if (!$arc->create_archive()) { debug_event('archive',"Error: unable to create archive",'3'); - return false; + return false; } // if failed to create archive - + $arc->download_file(); } // send_zip diff --git a/lib/class/access.class.php b/lib/class/access.class.php index 3652715d..7f986fef 100644 --- a/lib/class/access.class.php +++ b/lib/class/access.class.php @@ -16,10 +16,10 @@ 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. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/** +/** * Access Class * This class handles the access list mojo for Ampache, it is ment to restrict * access based on IP and maybe something else in the future @@ -38,7 +38,7 @@ class Access { /** * constructor - * Takes an ID of the access_id dealie :) + * Takes an ID of the access_id dealie :) */ public function __construct($access_id='') { @@ -48,9 +48,9 @@ class Access { $this->id = intval($access_id); $info = $this->_get_info(); - foreach ($info as $key=>$value) { - $this->$key = $value; - } + foreach ($info as $key=>$value) { + $this->$key = $value; + } return true; @@ -58,7 +58,7 @@ class Access { /** * _get_info - * get's the vars for $this out of the database + * get's the vars for $this out of the database * Taken from the object */ private function _get_info() { @@ -75,16 +75,16 @@ class Access { /** * format - * This makes the Access object a nice fuzzy human readable object, spiffy ain't it. + * This makes the Access object a nice fuzzy human readable object, spiffy ain't it. */ - public function format() { + public function format() { - $this->f_start = inet_ntop($this->start); - $this->f_end = inet_ntop($this->end); + $this->f_start = inet_ntop($this->start); + $this->f_end = inet_ntop($this->end); - $this->f_user = $this->get_user_name(); - $this->f_level = $this->get_level_name(); - $this->f_type = $this->get_type_name(); + $this->f_user = $this->get_user_name(); + $this->f_level = $this->get_level_name(); + $this->f_type = $this->get_type_name(); } // format @@ -92,7 +92,7 @@ class Access { * update * This function takes a named array as a datasource and updates the current access list entry */ - public function update($data) { + public function update($data) { /* We need to verify the incomming data a littlebit */ $start = @inet_pton($data['start']); @@ -113,16 +113,16 @@ class Access { return false; } - $name = Dba::escape($data['name']); - $type = self::validate_type($data['type']); + $name = Dba::escape($data['name']); + $type = self::validate_type($data['type']); $start = Dba::escape(inet_pton($data['start'])); - $end = Dba::escape(inet_pton($data['end'])); + $end = Dba::escape(inet_pton($data['end'])); $level = Dba::escape($data['level']); - $user = $data['user'] ? Dba::escape($data['user']) : '-1'; - $enabled = make_bool($data['enabled']); - - $sql = "UPDATE `access_list` " . - "SET `start`='$start', `end`='$end', `level`='$level', `user`='$user', " . + $user = $data['user'] ? Dba::escape($data['user']) : '-1'; + $enabled = make_bool($data['enabled']); + + $sql = "UPDATE `access_list` " . + "SET `start`='$start', `end`='$end', `level`='$level', `user`='$user', " . "`name`='$name', `type`='$type',`enabled`='$enabled' WHERE `id`='" . Dba::escape($this->id) . "'"; $db_results = Dba::write($sql); @@ -132,45 +132,45 @@ class Access { /** * create - * This takes a key'd array of data and trys to insert it as a + * This takes a key'd array of data and trys to insert it as a * new ACL entry */ - public static function create($data) { + public static function create($data) { /* We need to verify the incomming data a littlebit */ - $start = @inet_pton($data['start']); - $end = @inet_pton($data['end']); + $start = @inet_pton($data['start']); + $end = @inet_pton($data['end']); - if (!$start AND $data['start'] != '0.0.0.0' AND $data['start'] != '::') { - Error::add('start',_('Invalid IPv4 / IPv6 Address Entered')); - return false; - } - if (!$end) { - Error::add('end',_('Invalid IPv4 / IPv6 Address Entered')); - return false; - } + if (!$start AND $data['start'] != '0.0.0.0' AND $data['start'] != '::') { + Error::add('start',_('Invalid IPv4 / IPv6 Address Entered')); + return false; + } + if (!$end) { + Error::add('end',_('Invalid IPv4 / IPv6 Address Entered')); + return false; + } - if (strlen(bin2hex($start)) != strlen(bin2hex($end))) { - Error::add('start',_('IP Address Version Mismatch')); - Error::add('end',_('IP Address Version Mismatch')); - return false; - } + if (strlen(bin2hex($start)) != strlen(bin2hex($end))) { + Error::add('start',_('IP Address Version Mismatch')); + Error::add('end',_('IP Address Version Mismatch')); + return false; + } // Check existing ACL's to make sure we're not duplicating values here - if (self::exists($data)) { - debug_event('ACL Create','Error did not create duplicate ACL entrie for ' . $data['start'] . ' - ' . $data['end'],'1'); - return false; - } + if (self::exists($data)) { + debug_event('ACL Create','Error did not create duplicate ACL entrie for ' . $data['start'] . ' - ' . $data['end'],'1'); + return false; + } - $start = Dba::escape($start); + $start = Dba::escape($start); $end = Dba::escape($end); $name = Dba::escape($data['name']); - $user = $data['user'] ? Dba::escape($data['user']) : '-1'; + $user = $data['user'] ? Dba::escape($data['user']) : '-1'; $level = intval($data['level']); $type = self::validate_type($data['type']); - $enabled = make_bool($data['enabled']); + $enabled = make_bool($data['enabled']); - $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`user`,`type`,`enabled`) " . + $sql = "INSERT INTO `access_list` (`name`,`level`,`start`,`end`,`user`,`type`,`enabled`) " . "VALUES ('$name','$level','$start','$end','$user','$type','$enabled')"; $db_results = Dba::write($sql); @@ -182,22 +182,22 @@ class Access { * exists * this sees if the ACL that we've specified already exists, prevent duplicates. This ignores the name */ - public static function exists($data) { + public static function exists($data) { - $start = Dba::escape(inet_pton($data['start'])); - $end = Dba::escape(inet_pton($data['end'])); - $type = self::validate_type($data['type']); - $user = $data['user'] ? Dba::escape($data['user']) : '-1'; + $start = Dba::escape(inet_pton($data['start'])); + $end = Dba::escape(inet_pton($data['end'])); + $type = self::validate_type($data['type']); + $user = $data['user'] ? Dba::escape($data['user']) : '-1'; - $sql = "SELECT * FROM `access_list` WHERE `start`='$start' AND `end` = '$end' " . - "AND `type`='$type' AND `user`='$user'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `access_list` WHERE `start`='$start' AND `end` = '$end' " . + "AND `type`='$type' AND `user`='$user'"; + $db_results = Dba::read($sql); - if (Dba::fetch_assoc($db_results)) { - return true; - } + if (Dba::fetch_assoc($db_results)) { + return true; + } - return false; + return false; } // exists @@ -205,23 +205,23 @@ class Access { * delete * deletes the specified access_list entry */ - public static function delete($access_id) { + public static function delete($access_id) { $sql = "DELETE FROM `access_list` WHERE `id`='" . Dba::escape($access_id) . "'"; $db_results = Dba::write($sql); } // delete - + /** * check_function * This checks if a specific functionality is enabled * it takes a type only */ - public static function check_function($type) { + public static function check_function($type) { - switch ($type) { - case 'download': - return Config::get('download'); + switch ($type) { + case 'download': + return Config::get('download'); break ; case 'batch_download': if (!function_exists('gzcompress')) { @@ -233,37 +233,37 @@ class Access { } break; default: - return false; + return false; break; - } // end switch + } // end switch } // check_function /** * check_network - * This takes a type, ip, user, level and key + * This takes a type, ip, user, level and key * and then returns true or false if they have access to this * the IP is passed as a dotted quad */ - public static function check_network($type,$user,$level,$ip='') { + public static function check_network($type,$user,$level,$ip='') { - if (!Config::get('access_control')) { - switch ($type) { - case 'interface': - case 'stream': - return true; - break; - default: - return false; + if (!Config::get('access_control')) { + switch ($type) { + case 'interface': + case 'stream': + return true; + break; + default: + return false; } // end switch } // end if access control is turned off // Clean incomming variables - $ip = $ip ? Dba::escape(inet_pton($ip)) : Dba::escape(inet_pton($_SERVER['REMOTE_ADDR'])); + $ip = $ip ? Dba::escape(inet_pton($ip)) : Dba::escape(inet_pton($_SERVER['REMOTE_ADDR'])); $user = Dba::escape($user); $level = Dba::escape($level); - switch ($type) { + switch ($type) { /* This is here because we want to at least check IP before even creating the xml-rpc server * however we don't have the key that was passed yet so we've got to do just ip */ @@ -272,39 +272,39 @@ class Access { $sql = "SELECT `id` FROM `access_list`" . " WHERE `start` <= '$ip' AND `end` >= '$ip' AND `type`='rpc' AND `level` >= '$level'"; break; - case 'rpc': + case 'rpc': case 'xml-rpc': - $sql = "SELECT `id` FROM `access_list`" . - " WHERE `start` <= '$ip' AND `end` >= '$ip'" . + $sql = "SELECT `id` FROM `access_list`" . + " WHERE `start` <= '$ip' AND `end` >= '$ip'" . " AND `level` >= '$level' AND `type`='rpc'"; break; case 'init-api': $type = 'rpc'; - if ($user) { - $client = User::get_from_username($user); - $user = $client->id; - } + if ($user) { + $client = User::get_from_username($user); + $user = $client->id; + } case 'network': case 'interface': case 'stream': default: - $sql = "SELECT `id` FROM `access_list`" . + $sql = "SELECT `id` FROM `access_list`" . " WHERE `start` <= '$ip' AND `end` >= '$ip'" . " AND `level` >= '$level' AND `type` = '$type'"; if (strlen($user)) { $sql .= " AND (`user` = '$user' OR `user` = '-1')"; } else { $sql .= " AND `user` = '-1'"; } break; } // end switch on type - + $db_results = Dba::read($sql); // Yah they have access they can use the mojo - if (Dba::fetch_row($db_results)) { + if (Dba::fetch_row($db_results)) { return true; } // No Access Sucks to be them. - else { + else { return false; } @@ -315,40 +315,40 @@ class Access { * This is the global 'has_access' function it can check for any 'type' of object * everything uses the global 0,5,25,50,75,100 stuff. GLOBALS['user'] is always used */ - public static function check($type,$level) { + public static function check($type,$level) { - if (Config::get('demo_mode')) { return true; } - if (INSTALL == '1') { return true; } + if (Config::get('demo_mode')) { return true; } + if (INSTALL == '1') { return true; } - $level = intval($level); + $level = intval($level); // Switch on the type - switch ($type) { - case 'localplay': - // Check their localplay_level - if (Config::get('localplay_level') >= $level OR $GLOBALS['user']->access >= '100') { - return true; - } - else { - return false; - } + switch ($type) { + case 'localplay': + // Check their localplay_level + if (Config::get('localplay_level') >= $level OR $GLOBALS['user']->access >= '100') { + return true; + } + else { + return false; + } break; - case 'interface': + case 'interface': // Check their standard user level - if ($GLOBALS['user']->access >= $level) { - return true; - } - else { - return false; - } + if ($GLOBALS['user']->access >= $level) { + return true; + } + else { + return false; + } break; default: - return false; - break; + return false; + break; } // end switch on type // Default false - return false; + return false; } // check @@ -356,9 +356,9 @@ class Access { * validate_type * This cleans up and validates the specified type */ - public static function validate_type($type) { + public static function validate_type($type) { - switch($type) { + switch($type) { case 'rpc': case 'interface': case 'network': @@ -366,8 +366,8 @@ class Access { break; case 'xml-rpc': return 'rpc'; - break; - default: + break; + default: return 'stream'; break; } // end switch @@ -378,13 +378,13 @@ class Access { * get_access_lists * returns a full listing of all access rules on this server */ - public static function get_access_lists() { + public static function get_access_lists() { $sql = "SELECT `id` FROM `access_list`"; $db_results = Dba::read($sql); - - $results = array(); - + + $results = array(); + // Man this is the wrong way to do it... while ($row = Dba::fetch_assoc($db_results)) { $results[] = $row['id']; @@ -395,22 +395,22 @@ class Access { } // get_access_lists - /** + /** * get_level_name * take the int level and return a named level */ - public function get_level_name() { + public function get_level_name() { - if ($this->level >= '75') { + if ($this->level >= '75') { return _('All'); } - if ($this->level == '5') { - return _('View'); + if ($this->level == '5') { + return _('View'); } - if ($this->level == '25') { + if ($this->level == '25') { return _('Read'); } - if ($this->level == '50') { + if ($this->level == '50') { return _('Read/Write'); } @@ -420,23 +420,23 @@ class Access { * get_user_name * Take a user and return their full name */ - public function get_user_name() { + public function get_user_name() { + + if ($this->user == '-1') { return _('All'); } - if ($this->user == '-1') { return _('All'); } - $user = new User($this->user); return $user->fullname . " (" . $user->username . ")"; - + } // get_user_name /** * get_type_name * This function returns the pretty name for our current type */ - public function get_type_name() { + public function get_type_name() { - switch ($this->type) { - case 'xml-rpc': + switch ($this->type) { + case 'xml-rpc': case 'rpc': return _('API/RPC'); break; @@ -447,7 +447,7 @@ class Access { return _('Web Interface'); break; case 'stream': - default: + default: return _('Stream Access'); break; } // end switch @@ -460,35 +460,35 @@ class Access { * exists, it also provides an array of key'd data that may be required * based on the type */ - public static function session_exists($data,$key,$type) { + public static function session_exists($data,$key,$type) { // Switch on the type they pass - switch ($type) { - case 'api': - $key = Dba::escape($key); - $time = time(); - $sql = "SELECT * FROM `session_api` WHERE `id`='$key' AND `expire` > '$time'"; - $db_results = Dba::read($sql); - - if (Dba::num_rows($db_results)) { - $time = $time + 3600; - $sql = "UPDATE `session_api` WHERE `id`='$key' SET `expire`='$time'"; - $db_results = Dba::write($sql); - return true; - } + switch ($type) { + case 'api': + $key = Dba::escape($key); + $time = time(); + $sql = "SELECT * FROM `session_api` WHERE `id`='$key' AND `expire` > '$time'"; + $db_results = Dba::read($sql); - return false; + if (Dba::num_rows($db_results)) { + $time = $time + 3600; + $sql = "UPDATE `session_api` WHERE `id`='$key' SET `expire`='$time'"; + $db_results = Dba::write($sql); + return true; + } - break; - case 'stream': - - break; - case 'interface': + return false; - break; - default: - return false; - break; + break; + case 'stream': + + break; + case 'interface': + + break; + default: + return false; + break; } // type diff --git a/lib/class/ajax.class.php b/lib/class/ajax.class.php index 5381f529..38c451a9 100644 --- a/lib/class/ajax.class.php +++ b/lib/class/ajax.class.php @@ -25,15 +25,15 @@ * This class is specifically for setuping/printing out ajax related * elements onto a page it takes care of the observing and all that raz-a-ma-taz */ -class Ajax { +class Ajax { - private static $include_override; + private static $include_override; /** * constructor * This is what is called when the class is loaded */ - public function __construct() { + public function __construct() { // Rien a faire @@ -43,7 +43,7 @@ class Ajax { * observe * This returns a string with the correct and full ajax 'observe' stuff from prototype */ - public static function observe($source,$method,$action,$post='') { + public static function observe($source,$method,$action,$post='') { $non_quoted = array('document','window'); @@ -55,15 +55,15 @@ class Ajax { } // If it's a post then we need to stop events - if ($post) { - $action = 'Event.stop(e); ' . $action; - } + if ($post) { + $action = 'Event.stop(e); ' . $action; + } $observe = ""; - return $observe; + return $observe; } // observe @@ -72,9 +72,9 @@ class Ajax { * This takes the action, the source and the post (if passed) and generated the full * ajax link */ - public static function action($action,$source,$post='') { + public static function action($action,$source,$post='') { - $url = Config::get('ajax_url') . $action; + $url = Config::get('ajax_url') . $action; $non_quoted = array('document','window'); @@ -85,14 +85,14 @@ class Ajax { $source_txt = "'$source'"; } - if ($post) { - $ajax_string = "ajaxPost('$url','$post',$source_txt)"; + if ($post) { + $ajax_string = "ajaxPost('$url','$post',$source_txt)"; } - else { - $ajax_string = "ajaxPut('$url',$source_txt)"; - } - - return $ajax_string; + else { + $ajax_string = "ajaxPut('$url',$source_txt)"; + } + + return $ajax_string; } // action @@ -101,24 +101,24 @@ class Ajax { * This prints out an img of the specified icon with the specified alt text * and then sets up the required ajax for it */ - public static function button($action,$icon,$alt,$source='',$post='',$class='') { + public static function button($action,$icon,$alt,$source='',$post='',$class='') { // Get the correct action - $ajax_string = self::action($action,$source,$post); + $ajax_string = self::action($action,$source,$post); // If they passed a span class - if ($class) { - $class_txt = ' class="' . $class . '"'; - } + if ($class) { + $class_txt = ' class="' . $class . '"'; + } - $string = get_user_icon($icon,$alt); + $string = get_user_icon($icon,$alt); // Generate a so that it's more compliant with older browsers // (ie :hover actions) and also to unify linkbuttons (w/o ajax) display - $string = "".$string."\n"; + $string = "".$string."\n"; - $string .= self::observe($source,'click',$ajax_string); + $string .= self::observe($source,'click',$ajax_string); return $string; @@ -129,22 +129,22 @@ class Ajax { * This prints out the specified text as a link and setups the required * ajax for the link so it works correctly */ - public static function text($action,$text,$source,$post='',$class='') { + public static function text($action,$text,$source,$post='',$class='') { // Format the string we wanna use - $ajax_string = self::action($action,$source,$post); + $ajax_string = self::action($action,$source,$post); // If they passed a span class - if ($class) { - $class_txt = ' class="' . $class . '"'; - } + if ($class) { + $class_txt = ' class="' . $class . '"'; + } // If we pass a source put it in the ID - $string = "$text\n"; + $string = "$text\n"; - $string .= self::observe($source,'click',$ajax_string); + $string .= self::observe($source,'click',$ajax_string); - return $string; + return $string; } // text @@ -152,11 +152,11 @@ class Ajax { * run * This runs the specified action no questions asked */ - public static function run($action) { + public static function run($action) { - echo ""; + echo ""; } // run @@ -164,22 +164,22 @@ class Ajax { * set_include_override * This sets the cinlduing div override, used only one place kind of a hack */ - public static function set_include_override($value) { + public static function set_include_override($value) { - self::$include_override = make_bool($value); + self::$include_override = make_bool($value); } // set_include_override /** * start_container - * This checks to see if we're AJAX'in if we aren't then it echos out the + * This checks to see if we're AJAX'in if we aren't then it echos out the * html needed to start a container that can be replaced by Ajax */ - public static function start_container($name) { + public static function start_container($name) { - if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; } + if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; } - echo '
'; + echo '
'; } // start_container @@ -187,13 +187,13 @@ class Ajax { * end_container * This ends the container if we're not doing the AJAX thing */ - public static function end_container() { + public static function end_container() { - if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; } + if (AJAX_INCLUDE == '1' AND !self::$include_override) { return true; } - echo "
"; + echo "
"; - self::$include_override = false; + self::$include_override = false; } // end_container diff --git a/lib/class/album.class.php b/lib/class/album.class.php index 144fcf4f..bf8c6d40 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -16,7 +16,7 @@ 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. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -30,20 +30,20 @@ class Album extends database_object { /* Variables from DB */ public $id; public $name; - public $full_name; // Prefix + Name, genereated by format(); - public $disk; + public $full_name; // Prefix + Name, genereated by format(); + public $disk; public $year; public $prefix; public $mbid; // MusicBrainz ID /* Art Related Fields */ public $art; - public $art_mime; - public $thumb; + public $art_mime; + public $thumb; public $thumb_mime; // cached information - public $_songs=array(); + public $_songs=array(); /** * __construct @@ -54,20 +54,20 @@ class Album extends database_object { */ public function __construct($id='') { - if (!$id) { return false; } + if (!$id) { return false; } /* Get the information from the db */ $info = $this->get_info($id); - + // Foreach what we've got - foreach ($info as $key=>$value) { - $this->$key = $value; - } + foreach ($info as $key=>$value) { + $this->$key = $value; + } // Little bit of formating here $this->full_name = trim($info['prefix'] . ' ' . $info['name']); - return true; + return true; } // constructor @@ -76,17 +76,17 @@ class Album extends database_object { * This is often used by the metadata class, it fills out an album object from a * named array, _fake is set to true */ - public static function construct_from_array($data) { + public static function construct_from_array($data) { - $album = new Album(0); - foreach ($data as $key=>$value) { - $album->$key = $value; - } + $album = new Album(0); + foreach ($data as $key=>$value) { + $album->$key = $value; + } // Make sure that we tell em it's fake - $album->_fake = true; + $album->_fake = true; - return $album; + return $album; } // construct_from_array @@ -98,19 +98,19 @@ class Album extends database_object { public static function build_cache($ids,$extra=false) { // Nothing to do if they pass us nothing - if (!is_array($ids) OR !count($ids)) { return false; } + if (!is_array($ids) OR !count($ids)) { return false; } $idlist = '(' . implode(',', $ids) . ')'; $sql = "SELECT * FROM `album` WHERE `id` IN $idlist"; $db_results = Dba::read($sql); - + while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('album',$row['id'],$row); + parent::add_to_cache('album',$row['id'],$row); } // If we're extra'ing cache the extra info as well - if ($extra) { + if ($extra) { $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" . ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`". "FROM `song` " . @@ -118,12 +118,12 @@ class Album extends database_object { "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " . "WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`"; - $db_results = Dba::read($sql); + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $row['has_art'] = make_bool($row['has_art']); - $row['has_thumb'] = make_bool($row['has_thumb']); - parent::add_to_cache('album_extra',$row['album'],$row); + while ($row = Dba::fetch_assoc($db_results)) { + $row['has_art'] = make_bool($row['has_art']); + $row['has_thumb'] = make_bool($row['has_thumb']); + parent::add_to_cache('album_extra',$row['album'],$row); } // while rows } // if extra @@ -136,28 +136,28 @@ class Album extends database_object { * This pulls the extra information from our tables, this is a 3 table join, which is why we don't normally * do it */ - private function _get_extra_info() { + private function _get_extra_info() { - if (parent::is_cached('album_extra',$this->id)) { - return parent::get_from_cache('album_extra',$this->id); - } + if (parent::is_cached('album_extra',$this->id)) { + return parent::get_from_cache('album_extra',$this->id); + } - $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" . + $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" . ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id ". "FROM `song` " . "INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " . - "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " . + "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " . "WHERE `song`.`album`='$this->id' GROUP BY `song`.`album`"; - $db_results = Dba::read($sql); + $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); - if ($results['has_art']) { $results['has_art'] = 1; } - if ($results['has_thumb']) { $results['has_thumb'] = 1; } + if ($results['has_art']) { $results['has_art'] = 1; } + if ($results['has_thumb']) { $results['has_thumb'] = 1; } - parent::add_to_cache('album_extra',$this->id,$results); + parent::add_to_cache('album_extra',$this->id,$results); - return $results; + return $results; } // _get_extra_info @@ -167,19 +167,19 @@ class Album extends database_object { * and an optional artist, if artist is passed it only gets * songs with this album + specified artist */ - public function get_songs($limit = 0,$artist='') { + public function get_songs($limit = 0,$artist='') { $results = array(); - - if ($artist) { + + if ($artist) { $artist_sql = "AND `artist`='" . Dba::escape($artist) . "'"; - } + } $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' $artist_sql ORDER BY `track`, `title`"; if ($limit) { $sql .= " LIMIT $limit"; } $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $results[] = $r['id']; } @@ -189,20 +189,20 @@ class Album extends database_object { /** * has_art - * This returns true or false depending on if we find any art for this - * album. + * This returns true or false depending on if we find any art for this + * album. */ - public function has_art() { + public function has_art() { - $sql = "SELECT `album_id` FROM `album_data` WHERE `album_id`='" . $this->id . "' AND art IS NOT NULL"; - $db_results = Dba::read($sql); + $sql = "SELECT `album_id` FROM `album_data` WHERE `album_id`='" . $this->id . "' AND art IS NOT NULL"; + $db_results = Dba::read($sql); - if (Dba::fetch_assoc($db_results)) { - $this->has_art = true; - return true; - } + if (Dba::fetch_assoc($db_results)) { + $this->has_art = true; + return true; + } - return false; + return false; } // has_art @@ -210,16 +210,16 @@ class Album extends database_object { * has_track * This checks to see if this album has a track of the specified title */ - public function has_track($title) { + public function has_track($title) { - $title = Dba::escape($title); + $title = Dba::escape($title); - $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' AND `title`='$title'"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' AND `title`='$title'"; + $db_results = Dba::read($sql); - $data = Dba::fetch_assoc($db_results); + $data = Dba::fetch_assoc($db_results); - return $data; + return $data; } // has_track @@ -229,48 +229,48 @@ class Album extends database_object { * album information with the base required * f_link, f_name */ - public function format() { + public function format() { $web_path = Config::get('web_path'); /* Pull the advanced information */ - $data = $this->_get_extra_info(); - foreach ($data as $key=>$value) { $this->$key = $value; } - + $data = $this->_get_extra_info(); + foreach ($data as $key=>$value) { $this->$key = $value; } + /* Truncate the string if it's to long */ $this->f_name = truncate_with_ellipsis($this->full_name,Config::get('ellipse_threshold_album')); $this->f_name_link = "id) . "\" title=\"" . scrub_out($this->full_name) . "\">" . $this->f_name; // If we've got a disk append it - if ($this->disk) { + if ($this->disk) { $this->f_name_link .= " disk. "\">[" . _('Disk') . " " . $this->disk . "]"; - } + } $this->f_name_link .=""; - - $this->f_link = $this->f_name_link; - $this->f_title = $full_name; - if ($this->artist_count == '1') { + + $this->f_link = $this->f_name_link; + $this->f_title = $full_name; + if ($this->artist_count == '1') { $artist = scrub_out(truncate_with_ellipsis(trim($this->artist_prefix . ' ' . $this->artist_name),Config::get('ellipse_threshold_artist'))); $this->f_artist_link = "artist_id . "\" title=\"" . scrub_out($this->artist_name) . "\">" . $artist . ""; - $this->f_artist = $artist; + $this->f_artist = $artist; } else { - $this->f_artist_link = "artist_count " . _('Artists') . "\">" . _('Various') . ""; + $this->f_artist_link = "artist_count " . _('Artists') . "\">" . _('Various') . ""; $this->f_artist = _('Various'); } - if ($this->year == '0') { + if ($this->year == '0') { $this->year = "N/A"; } - $tags = Tag::get_top_tags('album',$this->id); - $this->tags = $tags; + $tags = Tag::get_top_tags('album',$this->id); + $this->tags = $tags; + + $this->f_tags = Tag::get_display($tags,$this->id,'album'); - $this->f_tags = Tag::get_display($tags,$this->id,'album'); - // Format the artist name to include the prefix - $this->f_artist_name = trim($this->artist_prefix . ' ' . $this->artist_name); + $this->f_artist_name = trim($this->artist_prefix . ' ' . $this->artist_name); } // format @@ -280,15 +280,15 @@ class Album extends database_object { * it trys to pull the resized art instead, if resized art is found then * it returns an additional resized=true in the array */ - public function get_art($return_raw=false) { + public function get_art($return_raw=false) { // Attempt to get the resized art first - if (!$return_raw) { - $art = $this->get_resized_db_art(); - } - - if (!is_array($art)) { - $art = $this->get_db_art(); + if (!$return_raw) { + $art = $this->get_resized_db_art(); + } + + if (!is_array($art)) { + $art = $this->get_db_art(); } return $art['0']; @@ -300,57 +300,57 @@ class Album extends database_object { * This function searches for album art using all configured methods * for the current album. There is an optional 'limit' passed that will * gather up to the specified number of possible album covers. - * There is also an optional array of options the possible options are + * There is also an optional array of options the possible options are * ['keyword'] = STRING * ['artist'] = STRING * ['album_name'] = STRING */ - public function find_art($options=array(),$limit='') { + public function find_art($options=array(),$limit='') { /* Create Base Vars */ - $results = array(); + $results = array(); /* Attempt to retrive the album art order */ $config_value = Config::get('album_art_order'); - $class_methods = get_class_methods('Album'); - + $class_methods = get_class_methods('Album'); + /* If it's not set */ - if (empty($config_value)) { + if (empty($config_value)) { // They don't want art! - return array(); + return array(); } - elseif (!is_array($config_value)) { - $config_value = array($config_value); + elseif (!is_array($config_value)) { + $config_value = array($config_value); } - - foreach ($config_value AS $method) { - - $data = array(); - + + foreach ($config_value AS $method) { + + $data = array(); + $method_name = "get_" . $method . "_art"; - if (in_array($method_name,$class_methods)) { + if (in_array($method_name,$class_methods)) { // Some of these take options! - switch ($method_name) { + switch ($method_name) { case 'get_amazon_art': - $data = $this->{$method_name}($options['keyword'],$limit); + $data = $this->{$method_name}($options['keyword'],$limit); break; case 'get_lastfm_art': - $data = $this->{$method_name}($limit,$options); + $data = $this->{$method_name}($limit,$options); + break; + case 'get_google_art': + $data = $this->{$method_name}($limit); break; - case 'get_google_art': - $data = $this->{$method_name}($limit); - break; default: - $data = $this->{$method_name}($limit); - break; - } + $data = $this->{$method_name}($limit); + break; + } // Add the results we got to the current set - $total_results += count($data); - // HACK for PHP 5, $data must be cast as array $results = array_merge($results, (array)$data); - $results = array_merge($results,(array)$data); - - if ($total_results > $limit AND $limit > 0) { + $total_results += count($data); + // HACK for PHP 5, $data must be cast as array $results = array_merge($results, (array)$data); + $results = array_merge($results,(array)$data); + + if ($total_results > $limit AND $limit > 0) { return $results; } @@ -358,28 +358,28 @@ class Album extends database_object { } // end foreach - return $results; - + return $results; + } // find_art /** * get_lastfm_art * This returns the art as pulled from lastFM. This doesn't require - * a special account, we just parse and run with it. + * a special account, we just parse and run with it. */ - public function get_lastfm_art($limit,$options='') { + public function get_lastfm_art($limit,$options='') { // Create the parser object - $lastfm = new LastFMSearch(); + $lastfm = new LastFMSearch(); - if (is_array($options)) { + if (is_array($options)) { $artist = $options['artist']; - $album = $options['album_name']; - } - else { - $artist = $this->artist_name; - $album = $this->full_name; - } + $album = $options['album_name']; + } + else { + $artist = $this->artist_name; + $album = $this->full_name; + } if(Config::get('proxy_host') AND Config::get('proxy_port')) { $proxyhost = Config::get('proxy_host'); @@ -389,31 +389,31 @@ class Album extends database_object { debug_event("lastfm", "set Proxy", "5"); $lastfm->setProxy($proxyhost, $proxyport, $proxyuser, $proxypass); } - $raw_data = $lastfm->album_search($artist,$album); + $raw_data = $lastfm->album_search($artist,$album); - if (!count($raw_data)) { return array(); } + if (!count($raw_data)) { return array(); } - $coverart = $raw_data['coverart']; + $coverart = $raw_data['coverart']; - ksort($coverart); - - foreach ($coverart as $key=>$value) { - $i++; - $url = $coverart[$key]; + ksort($coverart); + + foreach ($coverart as $key=>$value) { + $i++; + $url = $coverart[$key]; // We need to check the URL for the /noimage/ stuff - if (strstr($url,"/noimage/")) { - debug_event('LastFM','Detected as noimage, skipped ' . $url,'3'); - continue; - } + if (strstr($url,"/noimage/")) { + debug_event('LastFM','Detected as noimage, skipped ' . $url,'3'); + continue; + } - $results = pathinfo($url); - $mime = 'image/' . $results['extension']; - $data[] = array('url'=>$url,'mime'=>$mime); - if ($i >= $limit) { return $data; } + $results = pathinfo($url); + $mime = 'image/' . $results['extension']; + $data[] = array('url'=>$url,'mime'=>$mime); + if ($i >= $limit) { return $data; } } // end foreach - return $data; + return $data; } // get_lastfm_art @@ -423,29 +423,29 @@ class Album extends database_object { */ public function get_google_art($limit='') { $images = array(); - + $search = $this->full_name; - + if ($this->artist_count == '1') $search = $this->artist_name . ', ' . $search; - + $search = rawurlencode($search); - + //$size = ''; // Any $size = '&imgsz=m'; // Medium //$size = '&imgsz=l'; // Large - + $html = file_get_contents("http://images.google.com/images?source=hp&q=$search&oq=&um=1&ie=UTF-8&sa=N&tab=wi&start=0&tbo=1$size"); - + if(preg_match_all("|\ssrc\=\"(http.+?)\"|", $html, $matches, PREG_PATTERN_ORDER)) foreach ($matches[1] as $match) { $extension = "image/jpeg"; - + if (strrpos($extension, '.') !== false) $extension = substr($extension, strrpos($extension, '.') + 1); - + $images[] = array('url' => $match, 'mime' => $extension); } - + return $images; } // get_google_art @@ -453,39 +453,39 @@ class Album extends database_object { @function get_id3_art @discussion looks for art from the id3 tags */ - function get_id3_art($limit='') { + function get_id3_art($limit='') { // grab the songs and define our results - if (!count($this->_songs)) { - $this->_songs = $this->get_songs(); - } - $data = array(); + if (!count($this->_songs)) { + $this->_songs = $this->get_songs(); + } + $data = array(); // Foreach songs in this album - foreach ($this->_songs as $song_id) { - $song = new Song($song_id); + foreach ($this->_songs as $song_id) { + $song = new Song($song_id); // If we find a good one, stop looking $getID3 = new getID3(); - try { $id3 = $getID3->analyze($song->file); } - catch (Exception $error) { - debug_event('getid3',$error->message,'1'); - } + try { $id3 = $getID3->analyze($song->file); } + catch (Exception $error) { + debug_event('getid3',$error->message,'1'); + } - if ($id3['format_name'] == "WMA") { + if ($id3['format_name'] == "WMA") { $image = $id3['asf']['extended_content_description_object']['content_descriptors']['13']; $data[] = array('song'=>$song->file,'raw'=>$image['data'],'mime'=>$image['mime']); } - elseif (isset($id3['id3v2']['APIC'])) { - // Foreach incase they have more then one - foreach ($id3['id3v2']['APIC'] as $image) { + elseif (isset($id3['id3v2']['APIC'])) { + // Foreach incase they have more then one + foreach ($id3['id3v2']['APIC'] as $image) { $data[] = array('song'=>$song->file,'raw'=>$image['data'],'mime'=>$image['mime']); - } + } } - if (!empty($limit) && $limit < count($data)) { - return $data; + if (!empty($limit) && $limit < count($data)) { + return $data; } - + } // end foreach return $data; @@ -498,32 +498,32 @@ class Album extends database_object { * If a limit is passed or the preferred filename is found the current results set * is returned */ - function get_folder_art($limit='') { + function get_folder_art($limit='') { - if (!count($this->_songs)) { + if (!count($this->_songs)) { $this->_songs = $this->get_songs(); - } - $data = array(); + } + $data = array(); /* See if we are looking for a specific filename */ $preferred_filename = Config::get('album_art_preferred_filename'); // Init a horrible hack array of lameness - $cache =array(); - + $cache =array(); + /* Thanks to dromio for origional code */ /* Added search for any .jpg, png or .gif - Vollmer */ - foreach($this->_songs as $song_id) { + foreach($this->_songs as $song_id) { $song = new Song($song_id); $dir = dirname($song->file); - debug_event('folder_art',"Opening $dir and checking for Album Art",'3'); + debug_event('folder_art',"Opening $dir and checking for Album Art",'3'); /* Open up the directory */ $handle = @opendir($dir); if (!is_resource($handle)) { - Error::add('general',_('Error: Unable to open') . ' ' . $dir); + Error::add('general',_('Error: Unable to open') . ' ' . $dir); debug_event('read',"Error: Unable to open $dir for album art read",'2'); } @@ -532,18 +532,18 @@ class Album extends database_object { $extension = substr($file,strlen($file)-3,4); /* If it's an image file */ - if ($extension == "jpg" || $extension == "gif" || $extension == "png" || $extension == "jp2" || $extension == "bmp") { + if ($extension == "jpg" || $extension == "gif" || $extension == "png" || $extension == "jp2" || $extension == "bmp") { - if ($extension == 'jpg') { $extension = 'jpeg'; } + if ($extension == 'jpg') { $extension = 'jpeg'; } // HACK ALERT this is to prevent duplicate filenames - $full_filename = $dir . '/' . $file; - $index = md5($full_filename); + $full_filename = $dir . '/' . $file; + $index = md5($full_filename); /* Make sure it's got something in it */ - if (!filesize($dir . '/' . $file)) { continue; } + if (!filesize($dir . '/' . $file)) { continue; } - if ($file == $preferred_filename) { + if ($file == $preferred_filename) { // If we found the preferred filename we're done, wipe out previous results $data = array(array('file' => $full_filename, 'mime' => 'image/' . $extension)); return $data; @@ -551,17 +551,17 @@ class Album extends database_object { elseif (!isset($cache[$index])) { $data[] = array('file' => $full_filename, 'mime' => 'image/' . $extension); } - - $cache[$index] = '1'; - + + $cache[$index] = '1'; + } // end if it's an image - + } // end while reading dir @closedir($handle); - - if (!empty($limit) && $limit < count($data)) { - return $data; - } + + if (!empty($limit) && $limit < count($data)) { + return $data; + } } // end foreach songs @@ -574,18 +574,18 @@ class Album extends database_object { * This looks to see if we have a resized thumbnail that we can load rather then taking * the fullsized and resizing that */ - public function get_resized_db_art() { + public function get_resized_db_art() { - $id = Dba::escape($this->id); + $id = Dba::escape($this->id); $sql = "SELECT `thumb` AS `art`,`thumb_mime` AS `art_mime` FROM `album_data` WHERE `album_id`='$id'"; - $db_results = Dba::read($sql); - - $results = Dba::fetch_assoc($db_results); - if (strlen($results['art_mime'])) { - $results['resized'] = true; - } - else { return false; } + $db_results = Dba::read($sql); + + $results = Dba::fetch_assoc($db_results); + if (strlen($results['art_mime'])) { + $results['resized'] = true; + } + else { return false; } $data = array(array('db_resized'=>$this->id,'raw'=>$results['art'],'mime'=>$results['art_mime'])); @@ -604,10 +604,10 @@ class Album extends database_object { $results = Dba::fetch_assoc($db_results); - if (!$results['art']) { return array(); } + if (!$results['art']) { return array(); } + + $data = array(array('db'=>$this->id,'raw'=>$results['art'],'mime'=>$results['art_mime'])); - $data = array(array('db'=>$this->id,'raw'=>$results['art'],'mime'=>$results['art_mime'])); - return $data; } // get_db_art @@ -672,7 +672,7 @@ class Album extends database_object { } // The next bit is based directly on the MusicBrainz server code that displays cover art. - // I'm leaving in the releaseuri info for the moment, though it's not going to be used. + // I'm leaving in the releaseuri info for the moment, though it's not going to be used. $coverartsites[] = array( name => "CD Baby", domain => "cdbaby.com", @@ -729,7 +729,7 @@ class Album extends database_object { imguri => '$matches[1]', releaseuri => '', ); - + foreach ($release->getRelations($mbRelation->TO_URL) as $ar) { $arurl = $ar->getTargetId(); debug_event('mbz-gatherart', "Found URL AR: " . $arurl , '5'); @@ -766,16 +766,16 @@ class Album extends database_object { $images = array(); $final_results = array(); $possible_keys = array("LargeImage","MediumImage","SmallImage"); - + // Prevent the script from timing out set_time_limit(0); - if (empty($keywords)) { + if (empty($keywords)) { $keywords = $this->full_name; /* If this isn't a various album combine with artist name */ if ($this->artist_count == '1') { $keywords .= ' ' . $this->artist_name; } } - + /* Create Base Vars */ $amazon_base_urls = array(); @@ -783,18 +783,18 @@ class Album extends database_object { $config_value = Config::get('amazon_base_urls'); /* If it's not set */ - if (empty($config_value)) { + if (empty($config_value)) { $amazon_base_urls = array('http://webservices.amazon.com'); } - elseif (!is_array($config_value)) { + elseif (!is_array($config_value)) { array_push($amazon_base_urls,$config_value); } - else { + else { $amazon_base_urls = array_merge($amazon_base_urls, Config::get('amazon_base_urls')); } /* Foreach through the base urls that we should check */ - foreach ($amazon_base_urls AS $amazon_base) { + foreach ($amazon_base_urls AS $amazon_base) { // Create the Search Object $amazon = new AmazonSearch(Config::get('amazon_developer_public_key'), Config::get('amazon_developer_private_key'), $amazon_base); @@ -813,24 +813,24 @@ class Album extends database_object { $max_pages_to_search = max(Config::get('max_amazon_results_pages'),$amazon->_default_results_pages); $pages_to_search = $max_pages_to_search; //init to max until we know better. - // while we have pages to search + // while we have pages to search do { - $raw_results = $amazon->search(array('artist'=>$artist,'album'=>$albumname,'keywords'=>$keywords)); + $raw_results = $amazon->search(array('artist'=>$artist,'album'=>$albumname,'keywords'=>$keywords)); - $total = count($raw_results) + count($search_results); + $total = count($raw_results) + count($search_results); // If we've gotten more then we wanted - if (!empty($limit) && $total > $limit) { + if (!empty($limit) && $total > $limit) { // We don't want ot re-count every loop - $i = $total; - while ($i > $limit) { - array_pop($raw_results); + $i = $total; + while ($i > $limit) { + array_pop($raw_results); $i--; - } + } - debug_event('amazon-xml',"Found $total, Limit $limit reducing and breaking from loop",'5'); + debug_event('amazon-xml',"Found $total, Limit $limit reducing and breaking from loop",'5'); // Merge the results and BREAK! - $search_results = array_merge($search_results,$raw_results); + $search_results = array_merge($search_results,$raw_results); break; } // if limit defined @@ -840,10 +840,10 @@ class Album extends database_object { $amazon->_currentPage++; } while($amazon->_currentPage < $pages_to_search); - + // Only do the second search if the first actually returns something - if (count($search_results)) { + if (count($search_results)) { $final_results = $amazon->lookup($search_results); } @@ -851,30 +851,30 @@ class Album extends database_object { debug_event('amazon-xml',"Searched using $keywords with " . Config::get('amazon_developer_key') . " as key " . count($final_results) . " results found",'5'); // If we've hit our limit - if (!empty($limit) && count($final_results) >= $limit) { - break; - } - + if (!empty($limit) && count($final_results) >= $limit) { + break; + } + } // end foreach /* Foreach through what we've found */ - foreach ($final_results as $result) { + foreach ($final_results as $result) { /* Recurse through the images found */ - foreach ($possible_keys as $key) { - if (strlen($result[$key])) { + foreach ($possible_keys as $key) { + if (strlen($result[$key])) { break; - } + } } // foreach // Rudimentary image type detection, only JPG and GIF allowed. if (substr($result[$key], -4 == '.jpg')) { $mime = "image/jpeg"; } - elseif (substr($result[$key], -4 == '.gif')) { + elseif (substr($result[$key], -4 == '.gif')) { $mime = "image/gif"; } - elseif (substr($result[$key], -4 == '.png')) { + elseif (substr($result[$key], -4 == '.png')) { $mime = "image/png"; } else { @@ -884,31 +884,31 @@ class Album extends database_object { $data['url'] = $result[$key]; $data['mime'] = $mime; - + $images[] = $data; - if (!empty($limit)) { - if (count($images) >= $limit) { - return $images; - } - } + if (!empty($limit)) { + if (count($images) >= $limit) { + return $images; + } + } } // if we've got something - + return $images; - } // get_amazon_art + } // get_amazon_art /** * get_random_songs * gets a random number, and a random assortment of songs from this album */ - function get_random_songs() { + function get_random_songs() { $sql = "SELECT `id` FROM `song` WHERE `album`='$this->id' ORDER BY RAND()"; $db_results = Dba::read($sql); - while ($r = Dba::fetch_row($db_results)) { + while ($r = Dba::fetch_row($db_results)) { $results[] = $r['0']; } @@ -921,49 +921,49 @@ class Album extends database_object { * This function takes a key'd array of data and updates this object * as needed, and then throws down with a flag */ - public function update($data) { + public function update($data) { - $year = $data['year']; - $artist = $data['artist']; - $name = $data['name']; + $year = $data['year']; + $artist = $data['artist']; + $name = $data['name']; $disk = $data['disk']; - $mbid = $data['mbid']; + $mbid = $data['mbid']; - $current_id = $this->id; + $current_id = $this->id; - if ($artist != $this->artist_id AND $artist) { + if ($artist != $this->artist_id AND $artist) { // Update every song - $songs = $this->get_songs(); - foreach ($songs as $song_id) { - Song::update_artist($artist,$song_id); - } - $updated = 1; - Catalog::clean_artists(); - } + $songs = $this->get_songs(); + foreach ($songs as $song_id) { + Song::update_artist($artist,$song_id); + } + $updated = 1; + Catalog::clean_artists(); + } - $album_id = Catalog::check_album($name,$year,$disk,$mbid); - if ($album_id != $this->id) { - if (!is_array($songs)) { $songs = $this->get_songs(); } - foreach ($songs as $song_id) { - Song::update_album($album_id,$song_id); + $album_id = Catalog::check_album($name,$year,$disk,$mbid); + if ($album_id != $this->id) { + if (!is_array($songs)) { $songs = $this->get_songs(); } + foreach ($songs as $song_id) { + Song::update_album($album_id,$song_id); Song::update_year($year,$song_id); - } - $current_id = $album_id; - $updated = 1; - Catalog::clean_albums(); - } + } + $current_id = $album_id; + $updated = 1; + Catalog::clean_albums(); + } - if ($updated) { + if ($updated) { // Flag all songs - foreach ($songs as $song_id) { - Flag::add($song_id,'song','retag','Interface Album Update'); - Song::update_utime($song_id); + foreach ($songs as $song_id) { + Flag::add($song_id,'song','retag','Interface Album Update'); + Song::update_utime($song_id); } // foreach song of album - Catalog::clean_stats(); + Catalog::clean_stats(); } // if updated - return $current_id; + return $current_id; } // update @@ -971,8 +971,8 @@ class Album extends database_object { * clear_art * clears the album art from the DB */ - public function clear_art() { - + public function clear_art() { + $sql = "UPDATE `album_data` SET `art`=NULL, `art_mime`=NULL, `thumb`=NULL, `thumb_mime`=NULL WHERE `album_id`='$this->id'"; $db_results = Dba::write($sql); @@ -983,12 +983,12 @@ class Album extends database_object { * this takes a string representation of an image * and inserts it into the database. You must pass the mime type as well */ - public function insert_art($image, $mime) { + public function insert_art($image, $mime) { /* Have to disable this for Demo because people suck and try to - * insert PORN :( + * insert PORN :( */ - if (Config::get('demo_mode')) { return false; } + if (Config::get('demo_mode')) { return false; } // Check for PHP:GD and if we have it make sure this image is of some size if (function_exists('ImageCreateFromString')) { @@ -997,17 +997,17 @@ class Album extends database_object { return false; } } // if we have PHP:GD - elseif (strlen($image) < 5) { - return false; - } + elseif (strlen($image) < 5) { + return false; + } // Default to image/jpeg as a guess if there is no passed mime type - $mime = $mime ? $mime : 'image/jpeg'; + $mime = $mime ? $mime : 'image/jpeg'; // Push the image into the database $sql = "REPLACE INTO `album_data` SET `art` = '" . Dba::escape($image) . "'," . " `art_mime` = '" . Dba::escape($mime) . "'" . - ", `album_id` = '$this->id'," . + ", `album_id` = '$this->id'," . "`thumb` = NULL, `thumb_mime`=NULL"; $db_results = Dba::write($sql); @@ -1020,18 +1020,18 @@ class Album extends database_object { * This takes data from a gd resize operation and saves * it back into the database as a thumbnail */ - public static function save_resized_art($data,$mime,$album) { + public static function save_resized_art($data,$mime,$album) { // Make sure there's actually something to save - if (strlen($data) < '5') { return false; } + if (strlen($data) < '5') { return false; } - $data = Dba::escape($data); - $mime = Dba::escape($mime); - $album = Dba::escape($album); + $data = Dba::escape($data); + $mime = Dba::escape($mime); + $album = Dba::escape($album); - $sql = "UPDATE `album_data` SET `thumb`='$data',`thumb_mime`='$mime' " . + $sql = "UPDATE `album_data` SET `thumb`='$data',`thumb_mime`='$mime' " . "WHERE `album_data`.`album_id`='$album'"; - $db_results = Dba::write($sql); + $db_results = Dba::write($sql); } // save_resized_art @@ -1063,18 +1063,18 @@ class Album extends database_object { while ($row = Dba::fetch_assoc($db_results)) { $results[$row['album_id']] = $row['no_art']; } // end for - + asort($results); $albums = array_keys($results); $results = array_slice($albums,0,$count); - + return $results; } // get_random_albums /** * get_image_from_source - * This gets an image for the album art from a source as + * This gets an image for the album art from a source as * defined in the passed array. Because we don't know where * its comming from we are a passed an array that can look like * ['url'] = URL *** OPTIONAL *** @@ -1090,7 +1090,7 @@ class Album extends database_object { // If it came from the database if (isset($data['db'])) { - // Repull it + // Repull it $album_id = Dba::escape($data['db']); $sql = "SELECT * FROM `album_data` WHERE `album_id`='$album_id'"; $db_results = Dba::read($sql); @@ -1118,18 +1118,18 @@ class Album extends database_object { 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 incase they have more then one + // Foreach incase they have more then one foreach ($id3['id3v2']['APIC'] as $image) { return $image['data']; } @@ -1144,35 +1144,35 @@ class Album extends database_object { * get_art_url * This returns the art URL for the album */ - public static function get_art_url($album_id,$sid=false) { + public static function get_art_url($album_id,$sid=false) { - $sid = $sid ? scrub_out($sid) : session_id(); + $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); + $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); + $row = Dba::fetch_assoc($db_results); - $mime = $row['thumb_mime'] ? $row['thumb_mime'] : $row['art_mime']; + $mime = $row['thumb_mime'] ? $row['thumb_mime'] : $row['art_mime']; - switch ($type) { - case 'image/gif': - $type = 'gif'; - break; - case 'image/png': - $type = 'png'; - break; + switch ($type) { + case 'image/gif': + $type = 'gif'; + break; + case 'image/png': + $type = 'png'; + break; default: - case 'image/jpeg': - $type = 'jpg'; - break; + case 'image/jpeg': + $type = 'jpg'; + break; } // end type translation - $name = 'art.' . $type; + $name = 'art.' . $type; $url = Config::get('web_path') . '/image.php?id=' . scrub_out($album_id) . '&auth=' . $sid . '&name=' . $name; - return $url; + return $url; } // get_art_url diff --git a/lib/class/ampacherss.class.php b/lib/class/ampacherss.class.php index 8276bf77..897601bc 100644 --- a/lib/class/ampacherss.class.php +++ b/lib/class/ampacherss.class.php @@ -17,7 +17,7 @@ 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. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -28,17 +28,17 @@ */ class AmpacheRSS { - private $type; - public $data; + private $type; + public $data; /** * Constructor * This takes a flagged.id and then pulls in the information for said flag entry */ - public function __construct($type) { + public function __construct($type) { + + $this->type = self::validate_type($type); - $this->type = self::validate_type($type); - } // constructor /** @@ -46,19 +46,19 @@ class AmpacheRSS { * This returns the xmldocument for the current rss type, it calls a sub function that gathers the data * and then uses the xmlDATA class to build the document */ - public function get_xml() { + public function get_xml() { // Function call name - $data_function = 'load_' . $this->type; - $pub_date_function = 'pubdate_' . $this->type; + $data_function = 'load_' . $this->type; + $pub_date_function = 'pubdate_' . $this->type; - $data = call_user_func(array('AmpacheRSS',$data_function)); - $pub_date = call_user_func(array('AmpacheRSS',$pub_date_function)); + $data = call_user_func(array('AmpacheRSS',$data_function)); + $pub_date = call_user_func(array('AmpacheRSS',$pub_date_function)); - xmlData::set_type('rss'); - $xml_document = xmlData::rss_feed($data,$this->get_title(),$this->get_description(),$pub_date); + xmlData::set_type('rss'); + $xml_document = xmlData::rss_feed($data,$this->get_title(),$this->get_description(),$pub_date); - return $xml_document; + return $xml_document; } // get_xml @@ -66,14 +66,14 @@ class AmpacheRSS { * get_title * This returns the standardized title for the rss feed based on this->type */ - public function get_title() { + public function get_title() { $titles = array('now_playing'=>_('Now Playing'), 'recently_played'=>_('Recently Played'), 'latest_album'=>_('Newest Albums'), - 'latest_artist'=>_('Newest Artists')); + 'latest_artist'=>_('Newest Artists')); - return scrub_out(Config::get('site_title')) . ' - ' . $titles[$this->type]; + return scrub_out(Config::get('site_title')) . ' - ' . $titles[$this->type]; } // get_title @@ -81,10 +81,10 @@ class AmpacheRSS { * get_description * This returns the standardized description for the rss feed based on this->type */ - public function get_description() { + public function get_description() { //FIXME: For now don't do any kind of translating - return 'Ampache RSS Feeds'; + return 'Ampache RSS Feeds'; } // get_description @@ -92,16 +92,16 @@ class AmpacheRSS { * validate_type * this returns a valid type for an rss feed, if the specified type is invalid it returns a default value */ - public static function validate_type($type) { + public static function validate_type($type) { $valid_types = array('now_playing','recently_played','latest_album','latest_artist','latest_song', - 'popular_song','popular_album','popular_artist'); - - if (!in_array($type,$valid_types)) { - return 'now_playing'; - } + 'popular_song','popular_album','popular_artist'); - return $type; + if (!in_array($type,$valid_types)) { + return 'now_playing'; + } + + return $type; } // validate_type @@ -109,14 +109,14 @@ class AmpacheRSS { * get_display * This dumps out some html and an icon for the type of rss that we specify */ - public static function get_display($type='now_playing') { + public static function get_display($type='now_playing') { // Default to now playing - $type = self::validate_type($type); + $type = self::validate_type($type); - $string = '' . get_user_icon('feed',_('RSS Feed')) . ''; + $string = '' . get_user_icon('feed',_('RSS Feed')) . ''; - return $string; + return $string; } // get_display @@ -127,41 +127,41 @@ class AmpacheRSS { * This loads in the now playing information. This is just the raw data with key=>value pairs that could be turned * into an xml document if we so wished */ - public static function load_now_playing() { + public static function load_now_playing() { - $data = Stream::get_now_playing(); + $data = Stream::get_now_playing(); - $results = array(); + $results = array(); - foreach ($data as $element) { - $song = $element['media']; - $client = $element['user']; + foreach ($data as $element) { + $song = $element['media']; + $client = $element['user']; $xml_array = array('title'=>$song->f_title . ' - ' . $song->f_artist . ' - ' . $song->f_album, 'link'=>$song->link, 'description'=>$song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full, 'comments'=>$client->fullname . ' - ' . $element['agent'], 'pubDate'=>date("r",$element['expire']) - ); - $results[] = $xml_array; - } // end foreach + ); + $results[] = $xml_array; + } // end foreach - return $results; + return $results; } // load_now_playing /** * pubdate_now_playing - * this is the pub date we should use for the now playing information, + * this is the pub date we should use for the now playing information, * this is a little specific as it uses the 'newest' expire we can find */ - public static function pubdate_now_playing() { + public static function pubdate_now_playing() { // Little redundent, should be fixed by an improvement in the get_now_playing stuff - $data = Stream::get_now_playing(); + $data = Stream::get_now_playing(); - $element = array_shift($data); + $element = array_shift($data); - return $element['expire']; + return $element['expire']; } // pubdate_now_playing @@ -169,21 +169,21 @@ class AmpacheRSS { * load_recently_played * This loads in the recently played information and formats it up real nice like */ - public static function load_recently_played() { + public static function load_recently_played() { //FIXME: The time stuff should be centralized, it's currently in two places, lame $time_unit = array('',_('seconds ago'),_('minutes ago'),_('hours ago'),_('days ago'),_('weeks ago'),_('months ago'),_('years ago')); - $data = Song::get_recently_played(); + $data = Song::get_recently_played(); - $results = array(); + $results = array(); - foreach ($data as $item) { - $client = new User($item['user']); - $song = new Song($item['object_id']); - $song->format(); - $amount = intval(time() - $item['date']+2); - $time_place = '0'; + foreach ($data as $item) { + $client = new User($item['user']); + $song = new Song($item['object_id']); + $song->format(); + $amount = intval(time() - $item['date']+2); + $time_place = '0'; while ($amount >= 1) { $final = $amount; $time_place++; @@ -205,7 +205,7 @@ class AmpacheRSS { if ($time_place > '6') { $final = $amount . '+'; break; - } + } } // end while $time_string = $final . ' ' . $time_unit[$time_place]; @@ -214,12 +214,12 @@ class AmpacheRSS { 'link'=>str_replace('&', '&', $song->link), 'description'=>$song->title . ' - ' . $song->f_artist_full . ' - ' . $song->f_album_full . ' - ' . $time_string, 'comments'=>$client->username, - 'pubDate'=>date("r",$item['date'])); - $results[] = $xml_array; + 'pubDate'=>date("r",$item['date'])); + $results[] = $xml_array; - } // end foreach + } // end foreach - return $results; + return $results; } // load_recently_played @@ -227,13 +227,13 @@ class AmpacheRSS { * pubdate_recently_played * This just returns the 'newest' recently played entry */ - public static function pubdate_recently_played() { + public static function pubdate_recently_played() { - $data = Song::get_recently_played(); + $data = Song::get_recently_played(); $element = array_shift($data); - - return $element['date']; + + return $element['date']; } // pubdate_recently_played diff --git a/lib/class/api.class.php b/lib/class/api.class.php index fecab380..5c2575fd 100644 --- a/lib/class/api.class.php +++ b/lib/class/api.class.php @@ -25,15 +25,15 @@ * This handles functions relating to the API written for ampache, initially this is very focused * on providing functionality for Amarok so it can integrate with Ampache */ -class Api { +class Api { + + public static $version = '350001'; - public static $version = '350001'; - /** * constructor * This really isn't anything to do here, so it's private */ - private function __construct() { + private function __construct() { // Rien a faire @@ -45,12 +45,12 @@ class Api { * and vastly simplier way to the end users so we have to do a little handy work to make them * work internally */ - public static function set_filter($filter,$value) { + public static function set_filter($filter,$value) { - if (!strlen($value)) { return false; } + if (!strlen($value)) { return false; } - switch ($filter) { - case 'add': + switch ($filter) { + case 'add': // Check for a range, if no range default to gt if (strpos('/',$value)) { $elements = explode('/',$value); @@ -60,30 +60,30 @@ class Api { else { Browse::set_filter('add_gt',strtotime($value)); } - break; - case 'update': + break; + case 'update': // Check for a range, if no range default to gt - if (strpos('/',$value)) { - $elements = explode('/',$value); - Browse::set_filter('update_lt',strtotime($elements['1'])); - Browse::set_filter('update_gt',strtotime($elements['0'])); + if (strpos('/',$value)) { + $elements = explode('/',$value); + Browse::set_filter('update_lt',strtotime($elements['1'])); + Browse::set_filter('update_gt',strtotime($elements['0'])); } - else { - Browse::set_filter('update_gt',strtotime($value)); + else { + Browse::set_filter('update_gt',strtotime($value)); } - break; + break; case 'alpha_match': - Browse::set_filter('alpha_match',$value); - break; - case 'exact_match': + Browse::set_filter('alpha_match',$value); + break; + case 'exact_match': Browse::set_filter('exact_match',$value); - break; - default: + break; + default: // Rien a faire - break; + break; } // end filter - return true; + return true; } // set_filter @@ -91,106 +91,106 @@ class Api { * handshake * This is the function that handles the verifying a new handshake * this takes a timestamp, auth key, and client IP. Optionally it - * can take a username, if non is passed the ACL must be non-use + * can take a username, if non is passed the ACL must be non-use * specific */ - public static function handshake($input) { + public static function handshake($input) { - $timestamp = $input['timestamp']; - $passphrase = $input['auth']; - $ip = $_SERVER['REMOTE_ADDR']; - $username = $input['user']; - $version = $input['version']; + $timestamp = $input['timestamp']; + $passphrase = $input['auth']; + $ip = $_SERVER['REMOTE_ADDR']; + $username = $input['user']; + $version = $input['version']; // Let them know we're attempting - debug_event('API',"Attempting Handshake IP:$ip User:$username Version:$version",'5'); + debug_event('API',"Attempting Handshake IP:$ip User:$username Version:$version",'5'); - if (intval($version) < self::$version) { - debug_event('API','Login Failed version too old','1'); - Error::add('api','Login Failed version too old'); - return false; - } + if (intval($version) < self::$version) { + debug_event('API','Login Failed version too old','1'); + Error::add('api','Login Failed version too old'); + return false; + } // If the timestamp is over 2hr old sucks to be them - if ($timestamp < (time() - 14400)) { - debug_event('API','Login Failed, timestamp too old','1'); - Error::add('api','Login Failed, timestamp too old'); - return false; - } + if ($timestamp < (time() - 14400)) { + debug_event('API','Login Failed, timestamp too old','1'); + Error::add('api','Login Failed, timestamp too old'); + return false; + } - // First we'll filter by username and IP - if (!trim($username)) { - $user_id = '-1'; - } - else { - $client = User::get_from_username($username); - $user_id =$client->id; - } + // First we'll filter by username and IP + if (!trim($username)) { + $user_id = '-1'; + } + else { + $client = User::get_from_username($username); + $user_id =$client->id; + } // Clean incomming variables - $user_id = Dba::escape($user_id); - $timestamp = intval($timestamp); + $user_id = Dba::escape($user_id); + $timestamp = intval($timestamp); $ip = inet_pton($ip); // Log this attempt - debug_event('API','Login Attempt, IP:' . inet_ntop($ip) . ' Time:' . $timestamp . ' User:' . $username . '(' . $user_id . ') Auth:' . $passphrase,'1'); + debug_event('API','Login Attempt, IP:' . inet_ntop($ip) . ' Time:' . $timestamp . ' User:' . $username . '(' . $user_id . ') Auth:' . $passphrase,'1'); + + $ip = Dba::escape($ip); - $ip = Dba::escape($ip); - // Run the query and return the passphrases as we'll have to mangle them // to figure out if they match what we've got - $sql = "SELECT * FROM `access_list` " . - "WHERE `type`='rpc' AND (`user`='$user_id' OR `access_list`.`user`='-1') " . - "AND `start` <= '$ip' AND `end` >= '$ip'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `access_list` " . + "WHERE `type`='rpc' AND (`user`='$user_id' OR `access_list`.`user`='-1') " . + "AND `start` <= '$ip' AND `end` >= '$ip'"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { - // Now we're sure that there is an ACL line that matches this user or ALL USERS, - // pull the users password and then see what we come out with - $sql = "SELECT * FROM `user` WHERE `id`='$user_id'"; - $user_results = Dba::read($sql); + // Now we're sure that there is an ACL line that matches this user or ALL USERS, + // pull the users password and then see what we come out with + $sql = "SELECT * FROM `user` WHERE `id`='$user_id'"; + $user_results = Dba::read($sql); - $row = Dba::fetch_assoc($user_results); + $row = Dba::fetch_assoc($user_results); - if (!$row['password']) { - debug_event('API','Unable to find user with username of ' . $user_id,'1'); - Error::add('api','Invalid Username/Password'); - return false; - } + if (!$row['password']) { + debug_event('API','Unable to find user with username of ' . $user_id,'1'); + Error::add('api','Invalid Username/Password'); + return false; + } - $sha1pass = hash('sha256',$timestamp . $row['password']); + $sha1pass = hash('sha256',$timestamp . $row['password']); - if ($sha1pass === $passphrase) { + if ($sha1pass === $passphrase) { // Create the Session, in this class for now needs to be moved - $data['username'] = $client->username; - $data['type'] = 'api'; - $data['value'] = $timestamp; - $token = vauth::session_create($data); + $data['username'] = $client->username; + $data['type'] = 'api'; + $data['value'] = $timestamp; + $token = vauth::session_create($data); // Insert the token into the streamer - Stream::insert_session($token,$client->id); - debug_event('API','Login Success, passphrase matched','1'); + Stream::insert_session($token,$client->id); + debug_event('API','Login Success, passphrase matched','1'); // We need to also get the 'last update' of the catalog information in an RFC 2822 Format - $sql = "SELECT MAX(`last_update`) AS `update`,MAX(`last_add`) AS `add`, MAX(`last_clean`) AS `clean` FROM `catalog`"; - $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $sql = "SELECT MAX(`last_update`) AS `update`,MAX(`last_add`) AS `add`, MAX(`last_clean`) AS `clean` FROM `catalog`"; + $db_results = Dba::read($sql); + $row = Dba::fetch_assoc($db_results); // Now we need to quickly get the totals of songs - $sql = "SELECT COUNT(`id`) AS `song`,COUNT(DISTINCT(`album`)) AS `album`," . + $sql = "SELECT COUNT(`id`) AS `song`,COUNT(DISTINCT(`album`)) AS `album`," . "COUNT(DISTINCT(`artist`)) AS `artist` FROM `song`"; - $db_results = Dba::read($sql); - $counts = Dba::fetch_assoc($db_results); + $db_results = Dba::read($sql); + $counts = Dba::fetch_assoc($db_results); // Next the video counts - $sql = "SELECT COUNT(`id`) AS `video` FROM `video`"; - $db_results = Dba::read($sql); - $vcounts = Dba::fetch_assoc($db_results); - - $sql = "SELECT COUNT(`id`) AS `playlist` FROM `playlist`"; + $sql = "SELECT COUNT(`id`) AS `video` FROM `video`"; $db_results = Dba::read($sql); - $playlist = Dba::fetch_assoc($db_results); + $vcounts = Dba::fetch_assoc($db_results); + + $sql = "SELECT COUNT(`id`) AS `playlist` FROM `playlist`"; + $db_results = Dba::read($sql); + $playlist = Dba::fetch_assoc($db_results); echo xmlData::keyed_array(array('auth'=>$token, 'api'=>self::$version, @@ -201,13 +201,13 @@ class Api { 'albums'=>$counts['album'], 'artists'=>$counts['artist'], 'playlists'=>$playlist['playlist'], - 'videos'=>$vcounts['video'])); - } // match + 'videos'=>$vcounts['video'])); + } // match } // end while - debug_event('API','Login Failed, unable to match passphrase','1'); - xmlData::error('401',_('Error Invalid Handshake - ') . _('Invalid Username/Password')); + debug_event('API','Login Failed, unable to match passphrase','1'); + xmlData::error('401',_('Error Invalid Handshake - ') . _('Invalid Username/Password')); } // handshake @@ -216,7 +216,7 @@ class Api { * This can be called without being authenticated, it is useful for determining if what the status * of the server is, and what version it is running/compatible with */ - public static function ping($input) { + public static function ping($input) { $xmldata = array('server'=>Config::get('version'),'version'=>Api::$version,'compatible'=>'350001'); @@ -239,7 +239,7 @@ class Api { * artist objects. This function is deprecated! * //DEPRECATED */ - public static function artists($input) { + public static function artists($input) { Browse::reset_filters(); Browse::set_type('artist'); @@ -266,7 +266,7 @@ class Api { * This returns a single artist based on the UID of said artist * //DEPRECATED */ - public static function artist($input) { + public static function artist($input) { $uid = scrub_in($input['filter']); echo xmlData::artists(array($uid)); @@ -277,7 +277,7 @@ class Api { * artist_albums * This returns the albums of an artist */ - public static function artist_albums($input) { + public static function artist_albums($input) { $artist = new Artist($input['filter']); @@ -295,7 +295,7 @@ class Api { * artist_songs * This returns the songs of the specified artist */ - public static function artist_songs($input) { + public static function artist_songs($input) { $artist = new Artist($input['filter']); $songs = $artist->get_songs(); @@ -312,7 +312,7 @@ class Api { * albums * This returns albums based on the provided search filters */ - public static function albums($input) { + public static function albums($input) { Browse::reset_filters(); Browse::set_type('album'); @@ -336,7 +336,7 @@ class Api { * album * This returns a single album based on the UID provided */ - public static function album($input) { + public static function album($input) { $uid = scrub_in($input['filter']); echo xmlData::albums(array($uid)); @@ -347,7 +347,7 @@ class Api { * album_songs * This returns the songs of a specified album */ - public static function album_songs($input) { + public static function album_songs($input) { $album = new Album($input['filter']); $songs = $album->get_songs(); @@ -359,13 +359,13 @@ class Api { ob_end_clean(); echo xmlData::songs($songs); - } // album_songs + } // album_songs /** * tags * This returns the tags based on the specified filter */ - public static function tags($input) { + public static function tags($input) { Browse::reset_filters(); Browse::set_type('tag'); @@ -388,7 +388,7 @@ class Api { * tag * This returns a single tag based on UID */ - public static function tag($input) { + public static function tag($input) { $uid = scrub_in($input['filter']); ob_end_clean(); @@ -400,7 +400,7 @@ class Api { * tag_artists * This returns the artists assoicated with the tag in question as defined by the UID */ - public static function tag_artists($input) { + public static function tag_artists($input) { $artists = Tag::get_tag_objects('artist',$input['filter']); @@ -416,7 +416,7 @@ class Api { * tag_albums * This returns the albums assoicated with the tag in question */ - public static function tag_albums($input) { + public static function tag_albums($input) { $albums = Tag::get_tag_objects('album',$input['filter']); @@ -432,7 +432,7 @@ class Api { * tag_songs * returns the songs for this tag */ - public static function tag_songs($input) { + public static function tag_songs($input) { $songs = Tag::get_tag_objects('song',$input['filter']); @@ -448,7 +448,7 @@ class Api { * songs * Returns songs based on the specified filter */ - public static function songs($input) { + public static function songs($input) { Browse::reset_filters(); Browse::set_type('song'); @@ -474,7 +474,7 @@ class Api { * song * returns a single song */ - public static function song($input) { + public static function song($input) { $uid = scrub_in($input['filter']); @@ -487,7 +487,7 @@ class Api { * url_to_song * This takes a url and returns the song object in question */ - public static function url_to_song($input) { + public static function url_to_song($input) { // Don't scrub in we need to give her raw and juicy to the function $url = $input['url']; @@ -503,7 +503,7 @@ class Api { * playlists * This returns playlists based on the specified filter */ - public static function playlists($input) { + public static function playlists($input) { Browse::reset_filters(); Browse::set_type('playlist'); @@ -526,7 +526,7 @@ class Api { * playlist * This returns a single playlist */ - public static function playlist($input) { + public static function playlist($input) { $uid = scrub_in($input['filter']); @@ -539,7 +539,7 @@ class Api { * playlist_songs * This returns the songs for a playlist */ - public static function playlist_songs($input) { + public static function playlist_songs($input) { $playlist = new Playlist($input['filter']); $items = $playlist->get_items(); @@ -561,7 +561,7 @@ class Api { * search_songs * This returns the songs and returns... songs */ - public static function search_songs($input) { + public static function search_songs($input) { $array['s_all'] = $input['filter']; ob_end_clean(); @@ -583,7 +583,7 @@ class Api { * videos * This returns video objects! */ - public static function videos($input) { + public static function videos($input) { Browse::reset_filters(); Browse::set_type('video'); @@ -602,10 +602,10 @@ class Api { } // videos /** - * video + * video * This returns a single video */ - public static function video($input) { + public static function video($input) { $video_id = scrub_in($input['filter']); @@ -618,7 +618,7 @@ class Api { * localplay * This is for controling localplay */ - public static function localplay($input) { + public static function localplay($input) { // Load their localplay instance $localplay = new Localplay(Config::get('localplay_controller')); @@ -645,7 +645,7 @@ class Api { * democratic * This is for controlling democratic play */ - public static function democratic($input) { + public static function democratic($input) { // Load up democratic information $democratic = Democratic::get_current_playlist(); diff --git a/lib/class/art.class.php b/lib/class/art.class.php index 2fe672d8..12f76631 100644 --- a/lib/class/art.class.php +++ b/lib/class/art.class.php @@ -23,17 +23,17 @@ /** * Art * This class handles the images / artwork in ampache - * This was initially in the album class, but was pulled out + * This was initially in the album class, but was pulled out * to be more general, and apply to albums, artists, movies etc */ -class Art extends database_object { +class Art extends database_object { /** * Constructor * Art constructor, not sure what's here for now */ - public function __construct() { + public function __construct() { diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php index a0ca2ad3..c30b20e4 100644 --- a/lib/class/artist.class.php +++ b/lib/class/artist.class.php @@ -16,7 +16,7 @@ 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. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -44,16 +44,16 @@ class Artist extends database_object { public function __construct($id='') { /* If they failed to pass in an id, just run for it */ - if (!$id) { return false; } + if (!$id) { return false; } /* Get the information from the db */ $info = $this->get_info($id); - - foreach ($info as $key=>$value) { - $this->$key = $value; + + foreach ($info as $key=>$value) { + $this->$key = $value; } // foreach info - return true; + return true; } //constructor @@ -62,15 +62,15 @@ class Artist extends database_object { * This is used by the metadata class specifically but fills out a Artist object * based on a key'd array, it sets $_fake to true */ - public static function construct_from_array($data) { + public static function construct_from_array($data) { - $artist = new Artist(0); - foreach ($data as $key=>$value) { - $artist->$key = $value; - } + $artist = new Artist(0); + foreach ($data as $key=>$value) { + $artist->$key = $value; + } //Ack that this is not a real object from the DB - $artist->_fake = true; + $artist->_fake = true; return $artist; @@ -88,18 +88,18 @@ class Artist extends database_object { $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('artist',$row['id'],$row); + parent::add_to_cache('artist',$row['id'],$row); } // If we need to also pull the extra information, this is normally only used when we are doing the human display - if ($extra) { + if ($extra) { $sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " . "WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`"; $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('artist_extra',$row['artist'],$row); - } + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('artist_extra',$row['artist'],$row); + } } // end if extra @@ -111,51 +111,51 @@ class Artist extends database_object { * get_from_name * This gets an artist object based on the artist name */ - public static function get_from_name($name) { + public static function get_from_name($name) { - $name = Dba::escape($name); - $sql = "SELECT `id` FROM `artist` WHERE `name`='$name'"; - $db_results = Dba::write($sql); + $name = Dba::escape($name); + $sql = "SELECT `id` FROM `artist` WHERE `name`='$name'"; + $db_results = Dba::write($sql); - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - $object = new Artist($row['id']); + $object = new Artist($row['id']); - return $object; + return $object; - } // get_from_name + } // get_from_name /** * get_albums * gets the album ids that this artist is a part * of */ - public function get_albums() { + public function get_albums() { $results = array(); - $sql = "SELECT `album`.`id` FROM album LEFT JOIN `song` ON `song`.`album`=`album`.`id` " . + $sql = "SELECT `album`.`id` FROM album LEFT JOIN `song` ON `song`.`album`=`album`.`id` " . "WHERE `song`.`artist`='$this->id' GROUP BY `album`.`id` ORDER BY `album`.`name`,`album`.`disk`,`album`.`year`"; $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $results[] = $r['id']; } return $results; - + } // get_albums - /** + /** * get_songs * gets the songs for this artist */ - public function get_songs() { - + public function get_songs() { + $sql = "SELECT `song`.`id` FROM `song` WHERE `song`.`artist`='" . Dba::escape($this->id) . "' ORDER BY album, track"; $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $results[] = $r['id']; } @@ -186,27 +186,27 @@ class Artist extends database_object { * _get_extra info * This returns the extra information for the artist, this means totals etc */ - private function _get_extra_info() { + private function _get_extra_info() { // 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` " . + 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` " . "WHERE `song`.`artist`='$uid' GROUP BY `song`.`artist`"; $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); - parent::add_to_cache('artist_extra',$row['artist'],$row); - } - + $row = Dba::fetch_assoc($db_results); + 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']; + $this->time = $row['time']; - return $row; + return $row; } // _get_extra_info @@ -222,30 +222,30 @@ class Artist extends database_object { /* Combine prefix and name, trim then add ... if needed */ $name = truncate_with_ellipsis(trim($this->prefix . " " . $this->name),Config::get('ellipse_threshold_artist')); $this->f_name = $name; - $this->f_full_name = trim($this->prefix . " " . $this->name); + $this->f_full_name = trim($this->prefix . " " . $this->name); // If this is a fake object, we're done here - if ($this->_fake) { return true; } + if ($this->_fake) { return true; } $this->f_name_link = "id . "\" title=\"" . $this->full_name . "\">" . $name . ""; - $this->f_link = Config::get('web_path') . '/artists.php?action=show&artist=' . $this->id; + $this->f_link = Config::get('web_path') . '/artists.php?action=show&artist=' . $this->id; - // Get the counts - $extra_info = $this->_get_extra_info(); + // Get the counts + $extra_info = $this->_get_extra_info(); //Format the new time thingy that we just got - $min = sprintf("%02d",(floor($extra_info['time']/60)%60)); - - $sec = sprintf("%02d",($extra_info['time']%60)); + $min = sprintf("%02d",(floor($extra_info['time']/60)%60)); + + $sec = sprintf("%02d",($extra_info['time']%60)); $hours = floor($extra_info['time']/3600); - $this->f_time = ltrim($hours . ':' . $min . ':' . $sec,'0:'); + $this->f_time = ltrim($hours . ':' . $min . ':' . $sec,'0:'); - $this->tags = Tag::get_top_tags('artist',$this->id); + $this->tags = Tag::get_top_tags('artist',$this->id); - $this->f_tags = Tag::get_display($this->tags,$this->id,'artist'); + $this->f_tags = Tag::get_display($this->tags,$this->id,'artist'); - return true; + return true; } // format @@ -254,30 +254,30 @@ class Artist extends database_object { * This takes a key'd array of data and updates the current artist * it will flag songs as neeed */ - public function update($data) { + public function update($data) { // Save our current ID - $current_id = $this->id; + $current_id = $this->id; - $artist_id = Catalog::check_artist($data['name'], $this->mbid); + $artist_id = Catalog::check_artist($data['name'], $this->mbid); // If it's changed we need to update - if ($artist_id != $this->id) { - $songs = $this->get_songs(); - foreach ($songs as $song_id) { - Song::update_artist($artist_id,$song_id); - } - $updated = 1; - $current_id = $artist_id; - Catalog::clean_artists(); + if ($artist_id != $this->id) { + $songs = $this->get_songs(); + foreach ($songs as $song_id) { + Song::update_artist($artist_id,$song_id); + } + $updated = 1; + $current_id = $artist_id; + Catalog::clean_artists(); } // end if it changed - if ($updated) { - foreach ($songs as $song_id) { - Flag::add($song_id,'song','retag','Interface Artist Update'); - Song::update_utime($song_id); - } - Catalog::clean_stats(); + if ($updated) { + foreach ($songs as $song_id) { + Flag::add($song_id,'song','retag','Interface Artist Update'); + Song::update_utime($song_id); + } + Catalog::clean_stats(); } // if updated return $current_id; @@ -293,8 +293,8 @@ class Artist extends database_object { debug_event("lyrics", "Initialized Function", "5"); $sql = "SELECT `song_data`.`lyrics` FROM `song_data` WHERE `song_id`='" . Dba::escape($song_id) . "'"; - $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $db_results = Dba::read($sql); + $results = Dba::fetch_assoc($db_results); // Get Lyrics From id3tag (Lyrics3) $rs = Dba::read("SELECT `song`.`file` FROM `song` WHERE `id`='" . Dba::escape($song_id) . "'"); diff --git a/lib/class/browse.class.php b/lib/class/browse.class.php index 8a176bb0..17408a37 100644 --- a/lib/class/browse.class.php +++ b/lib/class/browse.class.php @@ -27,29 +27,29 @@ * it also handles pulling back the object_ids and then * calling the correct template for the object we are displaying */ -class Browse extends Query { +class Browse extends Query { // Public static vars that are cached - public static $sql; + public static $sql; public static $start; - public static $offset; - public static $total_objects; - public static $type; + public static $offset; + public static $total_objects; + public static $type; // Boolean if this is a simple browse method (use different paging code) - public static $simple_browse; + public static $simple_browse; // Static Content, this is defaulted to false, if set to true then when we can't - // apply any filters that would change the result set. - public static $static_content = false; - private static $_cache = array(); + // apply any filters that would change the result set. + public static $static_content = false; + private static $_cache = array(); /** * constructor * This should never be called */ - private function __construct() { + private function __construct() { // Rien a faire @@ -60,9 +60,9 @@ class Browse extends Query { * This sets the current browse object to a 'simple' browse method * which means use the base query provided and expand from there */ - public static function set_simple_browse($value) { + public static function set_simple_browse($value) { - parent::set_is_simple($value); + parent::set_is_simple($value); } // set_simple_browse @@ -70,11 +70,11 @@ class Browse extends Query { * add_supplemental_object * Legacy function, need to find a better way to do that */ - public static function add_supplemental_object($class,$uid) { + public static function add_supplemental_object($class,$uid) { - $_SESSION['browse']['supplemental'][$class] = intval($uid); + $_SESSION['browse']['supplemental'][$class] = intval($uid); - return true; + return true; } // add_supplemental_object @@ -83,36 +83,36 @@ class Browse extends Query { * This returns an array of 'class','id' for additional objects that need to be * created before we start this whole browsing thing */ - public static function get_supplemental_objects() { + public static function get_supplemental_objects() { - $objects = $_SESSION['browse']['supplemental']; - - if (!is_array($objects)) { $objects = array(); } + $objects = $_SESSION['browse']['supplemental']; - return $objects; + if (!is_array($objects)) { $objects = array(); } + + return $objects; } // get_supplemental_objects - /** + /** * is_enabled * This checks if the specified function/feature * of browsing is enabled, not sure if this is the best * way to go about it, but hey. Returns boolean t/f */ - public static function is_enabled($item) { - - switch ($item) { - case 'show_art': - if (Browse::get_filter('show_art')) { - return true; - } - if (Config::get('bandwidth') > 25) { - return true; - } - break; + public static function is_enabled($item) { + + switch ($item) { + case 'show_art': + if (Browse::get_filter('show_art')) { + return true; + } + if (Config::get('bandwidth') > 25) { + return true; + } + break; } // end switch - return false; + return false; } // is_enabled @@ -122,147 +122,147 @@ class Browse extends Query { * and requires the correct template based on the * type that we are currently browsing */ - public static function show_objects($object_ids=false) { - - if (parent::is_simple()) { - $object_ids = parent::get_saved(); - } - else { + public static function show_objects($object_ids=false) { + + if (parent::is_simple()) { + $object_ids = parent::get_saved(); + } + else { $object_ids = is_array($object_ids) ? $object_ids : parent::get_saved(); - parent::save_objects($object_ids); - } - + parent::save_objects($object_ids); + } + // Reset the total items - self::$total_objects = parent::get_total($object_ids); - + self::$total_objects = parent::get_total($object_ids); + // Limit is based on the users preferences if this is not a simple browse because we've got too much here - if (count($object_ids) > parent::get_start() AND !parent::is_simple()) { - $object_ids = array_slice($object_ids,parent::get_start(),parent::get_offset(),TRUE); - } + if (count($object_ids) > parent::get_start() AND !parent::is_simple()) { + $object_ids = array_slice($object_ids,parent::get_start(),parent::get_offset(),TRUE); + } // Load any additional object we need for this - $extra_objects = self::get_supplemental_objects(); + $extra_objects = self::get_supplemental_objects(); - foreach ($extra_objects as $class_name => $id) { - ${$class_name} = new $class_name($id); - } + foreach ($extra_objects as $class_name => $id) { + ${$class_name} = new $class_name($id); + } // Format any matches we have so we can show them to the masses - if ($filter_value = parent::get_filter('alpha_match')) { - $match = ' (' . $filter_value . ')'; + if ($filter_value = parent::get_filter('alpha_match')) { + $match = ' (' . $filter_value . ')'; + } + elseif ($filter_value = parent::get_filter('starts_with')) { + $match = ' (' . $filter_value . ')'; } - elseif ($filter_value = parent::get_filter('starts_with')) { - $match = ' (' . $filter_value . ')'; - } // Set the correct classes based on type $class = "box browse_".self::$type; Ajax::start_container('browse_content'); // Switch on the type of browsing we're doing - switch (parent::get_type()) { - case 'song': - show_box_top(_('Songs') . $match, $class); - Song::build_cache($object_ids); - require_once Config::get('prefix') . '/templates/show_songs.inc.php'; - show_box_bottom(); + switch (parent::get_type()) { + case 'song': + show_box_top(_('Songs') . $match, $class); + Song::build_cache($object_ids); + require_once Config::get('prefix') . '/templates/show_songs.inc.php'; + show_box_bottom(); break; - case 'album': - show_box_top(_('Albums') . $match, $class); + case 'album': + show_box_top(_('Albums') . $match, $class); Album::build_cache($object_ids,'extra'); require_once Config::get('prefix') . '/templates/show_albums.inc.php'; - show_box_bottom(); + show_box_bottom(); break; case 'user': - show_box_top(_('Manage Users') . $match, $class); - require_once Config::get('prefix') . '/templates/show_users.inc.php'; - show_box_bottom(); + show_box_top(_('Manage Users') . $match, $class); + require_once Config::get('prefix') . '/templates/show_users.inc.php'; + show_box_bottom(); break; case 'artist': - show_box_top(_('Artists') . $match, $class); - Artist::build_cache($object_ids,'extra'); - require_once Config::get('prefix') . '/templates/show_artists.inc.php'; - show_box_bottom(); + show_box_top(_('Artists') . $match, $class); + Artist::build_cache($object_ids,'extra'); + require_once Config::get('prefix') . '/templates/show_artists.inc.php'; + show_box_bottom(); break; - case 'live_stream': - require_once Config::get('prefix') . '/templates/show_live_stream.inc.php'; - show_box_top(_('Radio Stations') . $match, $class); + case 'live_stream': + require_once Config::get('prefix') . '/templates/show_live_stream.inc.php'; + show_box_top(_('Radio Stations') . $match, $class); require_once Config::get('prefix') . '/templates/show_live_streams.inc.php'; - show_box_bottom(); + show_box_bottom(); break; - case 'playlist': - Playlist::build_cache($object_ids); + case 'playlist': + Playlist::build_cache($object_ids); show_box_top(_('Playlists') . $match, $class); - require_once Config::get('prefix') . '/templates/show_playlists.inc.php'; - show_box_bottom(); + require_once Config::get('prefix') . '/templates/show_playlists.inc.php'; + show_box_bottom(); break; - case 'playlist_song': - show_box_top(_('Playlist Songs') . $match,$class); - require_once Config::get('prefix') . '/templates/show_playlist_songs.inc.php'; - show_box_bottom(); - break; - case 'playlist_localplay': - show_box_top(_('Current Playlist')); - require_once Config::get('prefix') . '/templates/show_localplay_playlist.inc.php'; - show_box_bottom(); + case 'playlist_song': + show_box_top(_('Playlist Songs') . $match,$class); + require_once Config::get('prefix') . '/templates/show_playlist_songs.inc.php'; + show_box_bottom(); break; - case 'catalog': - show_box_top(_('Catalogs'), $class); + case 'playlist_localplay': + show_box_top(_('Current Playlist')); + require_once Config::get('prefix') . '/templates/show_localplay_playlist.inc.php'; + show_box_bottom(); + break; + case 'catalog': + show_box_top(_('Catalogs'), $class); require_once Config::get('prefix') . '/templates/show_catalogs.inc.php'; - show_box_bottom(); + show_box_bottom(); + break; + case 'shoutbox': + show_box_top(_('Shoutbox Records'),$class); + require_once Config::get('prefix') . '/templates/show_manage_shoutbox.inc.php'; + show_box_bottom(); break; - case 'shoutbox': - show_box_top(_('Shoutbox Records'),$class); - require_once Config::get('prefix') . '/templates/show_manage_shoutbox.inc.php'; - show_box_bottom(); - break; case 'flagged': - show_box_top(_('Flagged Records'),$class); - require_once Config::get('prefix') . '/templates/show_flagged.inc.php'; - show_box_bottom(); + show_box_top(_('Flagged Records'),$class); + require_once Config::get('prefix') . '/templates/show_flagged.inc.php'; + show_box_bottom(); break; - case 'tag': - Tag::build_cache($tags); - show_box_top(_('Tag Cloud'),$class); - require_once Config::get('prefix') . '/templates/show_tagcloud.inc.php'; - show_box_bottom(); - break; - case 'video': - Video::build_cache($object_ids); - show_box_top(_('Videos'),$class); - require_once Config::get('prefix') . '/templates/show_videos.inc.php'; - show_box_bottom(); - break; - case 'democratic': - show_box_top(_('Democratic Playlist'),$class); - require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php'; - show_box_bottom(); - default: + case 'tag': + Tag::build_cache($tags); + show_box_top(_('Tag Cloud'),$class); + require_once Config::get('prefix') . '/templates/show_tagcloud.inc.php'; + show_box_bottom(); + break; + case 'video': + Video::build_cache($object_ids); + show_box_top(_('Videos'),$class); + require_once Config::get('prefix') . '/templates/show_videos.inc.php'; + show_box_bottom(); + break; + case 'democratic': + show_box_top(_('Democratic Playlist'),$class); + require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php'; + show_box_bottom(); + default: // Rien a faire break; } // end switch on type - Ajax::end_container(); + Ajax::end_container(); } // show_object /** * _auto_init - * this function reloads information back from the session + * this function reloads information back from the session * it is called on creation of the class */ - public static function _auto_init() { + public static function _auto_init() { $offset = Config::get('offset_limit') ? Config::get('offset_limit') : '25'; - parent::set_offset($offset); + parent::set_offset($offset); } // _auto_init - + /** * set_filter_from_request * //FIXME - */ - public static function set_filter_from_request($r) { + */ + public static function set_filter_from_request($r) { foreach($r as $k=>$v) { //reinterpret v as a list of int $vl = explode(',', $v); diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 99e750ab..96766b92 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -30,7 +30,7 @@ class Catalog extends database_object { public $name; public $last_update; public $last_add; - public $last_clean; + public $last_clean; public $key; public $rename_pattern; public $sort_pattern; @@ -88,15 +88,15 @@ class Catalog extends database_object { $this->_filecache[strtolower($results['file'])] = $results['id']; } - $sql = "SELECT `id`,`file` FROM `video` WHERE `catalog`='$catalog_id'"; - $db_results = Dba::read($sql); + $sql = "SELECT `id`,`file` FROM `video` WHERE `catalog`='$catalog_id'"; + $db_results = Dba::read($sql); - while ($results = Dba::fetch_assoc($db_results)) { - $this->_filecache[strtolower($results['file'])] = 'v_' . $results['id']; - } + while ($results = Dba::fetch_assoc($db_results)) { + $this->_filecache[strtolower($results['file'])] = 'v_' . $results['id']; + } } // end if empty filecache - return true; + return true; } // _create_filecache @@ -105,33 +105,33 @@ class Catalog extends database_object { * Try to figure out which catalog path most closely resembles this one * This is useful when creating a new catalog to make sure we're not doubling up here */ - public static function get_from_path($path) { + public static function get_from_path($path) { // First pull a list of all of the paths for the different catalogs - $sql = "SELECT `id`,`path` FROM `catalog` WHERE `catalog_type`='local'"; - $db_results = Dba::read($sql); + $sql = "SELECT `id`,`path` FROM `catalog` WHERE `catalog_type`='local'"; + $db_results = Dba::read($sql); - $catalog_paths = array(); - $component_path = $path; + $catalog_paths = array(); + $component_path = $path; - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { $catalog_paths[$row['path']] = $row['id']; - } + } // Break it down into its component parts and start looking for a catalog - do { - if ($catalog_paths[$component_path]) { - return $catalog_paths[$component_path]; - } + do { + if ($catalog_paths[$component_path]) { + return $catalog_paths[$component_path]; + } // Keep going until the path stops changing - $old_path = $component_path; - $component_path = realpath($component_path . '/../'); + $old_path = $component_path; + $component_path = realpath($component_path . '/../'); - } while (strcmp($component_path,$old_path) != 0); + } while (strcmp($component_path,$old_path) != 0); - return false; + return false; } // get_from_path @@ -146,7 +146,7 @@ class Catalog extends database_object { $this->f_path = truncate_with_ellipsis($this->path,Config::get('ellipse_threshold_title')); $this->f_update = $this->last_update ? date('d/m/Y h:i',$this->last_update) : _('Never'); $this->f_add = $this->last_add ? date('d/m/Y h:i',$this->last_add) : _('Never'); - $this->f_clean = $this->last_clean ? date('d/m/Y h:i',$this->last_clean) : _('Never'); + $this->f_clean = $this->last_clean ? date('d/m/Y h:i',$this->last_clean) : _('Never'); } // format @@ -197,8 +197,8 @@ class Catalog extends database_object { $results = self::count_songs($catalog_id); $results = array_merge(self::count_users($catalog_id),$results); - $results['tags'] = self::count_tags(); - $results = array_merge(self::count_video($catalog_id),$results); + $results['tags'] = self::count_tags(); + $results = array_merge(self::count_video($catalog_id),$results); $hours = floor($results['time']/3600); // Calculate catalog size in bytes, divided by 1000 @@ -347,7 +347,7 @@ class Catalog extends database_object { $this->get_album_art('',1); } - if ($options['parse_m3u'] AND count($this->_playlists)) { + if ($options['parse_m3u'] AND count($this->_playlists)) { foreach ($this->_playlists as $playlist_file) { $result = $this->import_m3u($playlist_file); } @@ -361,31 +361,31 @@ class Catalog extends database_object { * count_video * This returns the current # of video files we've got in the db */ - public static function count_video($catalog_id=0) { + public static function count_video($catalog_id=0) { - $catalog_search = $catalog_id ? "WHERE `catalog`='" . Dba::escape($catalog_id) . "'" : ''; + $catalog_search = $catalog_id ? "WHERE `catalog`='" . Dba::escape($catalog_id) . "'" : ''; - $sql = "SELECT COUNT(`id`) AS `video` FROM `video` $catalog_search"; - $db_results = Dba::read($sql); + $sql = "SELECT COUNT(`id`) AS `video` FROM `video` $catalog_search"; + $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); - - return $row; + $row = Dba::fetch_assoc($db_results); - } // count_video + return $row; + + } // count_video /** * count_tags * This returns the current # of unique tags that exist in the database */ - public static function count_tags($catalog_id=0) { + public static function count_tags($catalog_id=0) { - $sql = "SELECT COUNT(`id`) FROM `tag`"; - $db_results = Dba::read($sql); + $sql = "SELECT COUNT(`id`) FROM `tag`"; + $db_results = Dba::read($sql); - $info = Dba::fetch_row($db_results); + $info = Dba::fetch_row($db_results); - return $info['0']; + return $info['0']; } // count_tags @@ -396,7 +396,7 @@ class Catalog extends database_object { */ public static function count_songs($catalog_id='') { - $catalog_search = $catalog_id ? "WHERE `catalog`='" . Dba::escape($catalog_id) . "'" : ''; + $catalog_search = $catalog_id ? "WHERE `catalog`='" . Dba::escape($catalog_id) . "'" : ''; $sql = "SELECT COUNT(`id`),SUM(`time`),SUM(`size`) FROM `song` $catalog_search"; $db_results = Dba::read($sql); @@ -462,13 +462,13 @@ class Catalog extends database_object { public function add_files($path,$options) { // Profile the memory a bit - debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1); + debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1); // See if we want a non-root path for the add - if (isset($options['subdirectory'])) { - $path = $options['subdirectory']; - unset($options['subdirectory']); - } + if (isset($options['subdirectory'])) { + $path = $options['subdirectory']; + unset($options['subdirectory']); + } // Correctly detect the slash we need to use here if (strstr($path,"/")) { @@ -497,10 +497,10 @@ class Catalog extends database_object { // Ensure that we've got our cache $this->_create_filecache(); - debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1); + debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1); // Set the base "ticker" we will only update ever 5+ seconds - $ticker = time(); + $ticker = time(); /* Recurse through this dir and create the files array */ while ( false !== ( $file = readdir($handle) ) ) { @@ -509,7 +509,7 @@ class Catalog extends database_object { if (substr($file,0,1) == '.') { continue; } debug_event('read',"Starting work on $file inside $path",'5','ampache-catalog'); - debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1); + debug_event('Memory',memory_get_usage(true)/1024/1024 . "MB",1); /* Create the new path */ $full_file = $path.$slash_type.$file; @@ -520,7 +520,7 @@ class Catalog extends database_object { if (isset($this->_filecache[strtolower($full_file)])) { continue; } - + // Incase this is the second time through clear this variable // if it was set the day before unset($failed_check); @@ -559,12 +559,12 @@ class Catalog extends database_object { $pattern .= ")$/i"; } - $is_audio_file = preg_match($pattern,$file); - + $is_audio_file = preg_match($pattern,$file); + // Define the Video file pattern if (!$is_audio_file AND Config::get('catalog_video_pattern')) { - $video_pattern = "/\.(" . Config::get('catalog_video_pattern') . ")$/i"; - $is_video_file = preg_match($video_pattern,$file); + $video_pattern = "/\.(" . Config::get('catalog_video_pattern') . ")$/i"; + $is_video_file = preg_match($video_pattern,$file); } /* see if this is a valid audio file or playlist file */ @@ -603,9 +603,9 @@ class Catalog extends database_object { else { if ($is_audio_file) { $this->insert_local_song($full_file,$file_size); } - else { $this->insert_local_video($full_file,$file_size); } + else { $this->insert_local_video($full_file,$file_size); } - $this->count++; + $this->count++; if ( (time() > $ticker+1)) { $file = str_replace(array('(',')','\''),'',$full_file); echo "\n"; flush(); - $ticker = time(); + $ticker = time(); } // update our current state } // if it's not an m3u @@ -691,7 +691,7 @@ class Catalog extends database_object { } // Start the ticker - $ticker = time(); + $ticker = time(); // Run through them an get the art! foreach ($albums as $album_id) { @@ -700,19 +700,19 @@ class Catalog extends database_object { $album = new Album($album_id); // We're going to need the name here $album->format(); - + debug_event('gather_art','Gathering art for ' . $album->name,'5'); - + // Define the options we want to use for the find art function $options = array( 'album_name' => $album->full_name, 'artist' => $album->artist_name, - 'keyword' => $album->artist_name . ' ' . $album->full_name + 'keyword' => $album->artist_name . ' ' . $album->full_name ); // Return results $results = $album->find_art($options,1); - + if (count($results)) { // Pull the string representation from the source $image = Album::get_image_from_source($results['0']); @@ -733,9 +733,9 @@ class Catalog extends database_object { echo "update_txt('" . addslashes($album->name) . "','read_art_" . $this->id . "');"; echo "\n\n"; flush(); - $ticker = time(); + $ticker = time(); } //echos song count - + unset($found); } // foreach albums @@ -830,9 +830,9 @@ class Catalog extends database_object { // Setup the base SQL $sql = "SELECT song.id AS song,artist.id AS artist,album.id AS album,title,COUNT(title) AS ctitle". - " FROM `song` LEFT JOIN `artist` ON `artist`.`id`=`song`.`artist` " . + " FROM `song` LEFT JOIN `artist` ON `artist`.`id`=`song`.`artist` " . " LEFT JOIN `album` ON `album`.`id`=`song`.`album` $where_sql GROUP BY `song`.`title`"; - + // Add any Additional constraints if ($search_method == "artist_title" OR $search_method == "artist_album_title") { $sql = $sql.",artist.name"; @@ -924,7 +924,7 @@ class Catalog extends database_object { else { $extension = substr($image['0']['mime'],strlen($image['0']['mime'])-3,3); } - + // Try the preferred filename, if that fails use folder.??? $preferred_filename = Config::get('album_art_preferred_filename'); if (!$preferred_filename || strstr($preferred_filename,"%")) { $preferred_filename = "folder.$extension"; } @@ -1002,11 +1002,11 @@ class Catalog extends database_object { * update_last_clean * This updates the last clean information */ - public function update_last_clean() { + public function update_last_clean() { - $date = time(); - $sql = "UPDATE `catalog` SET `last_clean`='$date' WHERE `id`='$this->id'"; - $db_results = Dba::write($sql); + $date = time(); + $sql = "UPDATE `catalog` SET `last_clean`='$date' WHERE `id`='$this->id'"; + $db_results = Dba::write($sql); } // update_last_clean @@ -1075,7 +1075,7 @@ class Catalog extends database_object { } } // foreach songs - self::clean(); + self::clean(); } // update_single_item @@ -1084,33 +1084,33 @@ class Catalog extends database_object { * This is a 'wrapper' function calls the update function for the media type * in question */ - public static function update_media_from_tags(&$media,$sort_pattern='',$rename_pattern='') { + public static function update_media_from_tags(&$media,$sort_pattern='',$rename_pattern='') { // Check for patterns - if (!$sort_pattern OR !$rename_pattern) { - $catalog = new Catalog($media->catalog); - $sort_pattern = $catalog->sort_pattern; - $rename_pattern = $catalog->rename_pattern; - } + if (!$sort_pattern OR !$rename_pattern) { + $catalog = new Catalog($media->catalog); + $sort_pattern = $catalog->sort_pattern; + $rename_pattern = $catalog->rename_pattern; + } - debug_event('tag-read','Reading tags from ' . $media->file,'5','ampache-catalog'); + debug_event('tag-read','Reading tags from ' . $media->file,'5','ampache-catalog'); - $vainfo = new vainfo($media->file,'','','',$sort_pattern,$rename_pattern); - $vainfo->get_info(); + $vainfo = new vainfo($media->file,'','','',$sort_pattern,$rename_pattern); + $vainfo->get_info(); - $key = vainfo::get_tag_type($vainfo->tags); + $key = vainfo::get_tag_type($vainfo->tags); - $results = vainfo::clean_tag_info($vainfo->tags,$key,$media->file); + $results = vainfo::clean_tag_info($vainfo->tags,$key,$media->file); // Figure out what type of object this is and call the right function // giving it the stuff we've figured out above - $name = (get_class($media) == 'Song') ? 'song' : 'video'; + $name = (get_class($media) == 'Song') ? 'song' : 'video'; - $function = 'update_' . $name . '_from_tags'; + $function = 'update_' . $name . '_from_tags'; - $return = call_user_func(array('Catalog',$function),$results,$media); + $return = call_user_func(array('Catalog',$function),$results,$media); - return $return; + return $return; } // update_media_from_tags @@ -1119,10 +1119,10 @@ class Catalog extends database_object { * updates the video info based on tags this is called from a bunch of different places * and passes in a full song object and the vainfo results */ - public static function update_video_from_tags($results,$video) { + public static function update_video_from_tags($results,$video) { // Pretty sweet function here - return $results; + return $results; } // update_video_from_tags @@ -1140,20 +1140,20 @@ class Catalog extends database_object { $new_song->title = $results['title']; $new_song->year = $results['year']; $new_song->comment = $results['comment']; - $new_song->language = $results['language']; - $new_song->lyrics = $results['lyrics']; + $new_song->language = $results['language']; + $new_song->lyrics = $results['lyrics']; $new_song->bitrate = $results['bitrate']; $new_song->rate = $results['rate']; - $new_song->mode = ($results['mode'] == 'cbr') ? 'cbr' : 'vbr'; + $new_song->mode = ($results['mode'] == 'cbr') ? 'cbr' : 'vbr'; $new_song->size = $results['size']; $new_song->time = $results['time']; - $new_song->mime = $results['mime']; - $new_song->track = intval($results['track']); - $new_song->mbid = $results['mb_trackid']; + $new_song->mime = $results['mime']; + $new_song->track = intval($results['track']); + $new_song->mbid = $results['mb_trackid']; $artist = $results['artist']; - $artist_mbid = $results['mb_artistid']; + $artist_mbid = $results['mb_artistid']; $album = $results['album']; - $album_mbid = $results['mb_albumid']; + $album_mbid = $results['mb_albumid']; $disk = $results['disk']; $tags = $results['genre']; // multiple genre support makes this an array @@ -1166,7 +1166,7 @@ class Catalog extends database_object { $new_song->album = self::check_album($album,$new_song->year,$disk,$album_mbid); $new_song->f_album = $album . " - " . $new_song->year; $new_song->title = self::check_title($new_song->title,$new_song->file); - + // Nothing to assign here this is a multi-value doodly // multiple genre support foreach ($tags as $tag) { @@ -1271,7 +1271,7 @@ class Catalog extends database_object { * the XML RPC stuff and a key to be passed */ public function get_remote_catalog($type=0) { - + if (!class_exists('XML_RPC_Client')) { debug_event('xmlrpc',"Unable to load pear XMLRPC library",'1'); echo "" . _("Error") . ": " . _('Unable to load pear XMLRPC library, make sure XML-RPC is enabled') . "
\n"; @@ -1317,9 +1317,9 @@ class Catalog extends database_object { echo "

$error_msg

"; return; } - + $data = XML_RPC_Decode($response->value()); - + // Print out the catalogs we are going to sync foreach ($data as $vars) { $catalog_name = $vars['name']; @@ -1343,13 +1343,13 @@ class Catalog extends database_object { echo "

" . _('Completed updating remote catalog(s)') . ".


\n"; flush(); - + // Try to sync the album images from the remote catalog echo "

" . _('Starting synchronisation of album images') . ".


\n"; $this->get_remote_album_images($client, $token, $path); echo "

" . _('Completed synchronisation of album images') . ".


\n"; flush(); - + // Update the last update value $this->update_last_update(); @@ -1400,11 +1400,11 @@ class Catalog extends database_object { * This function retrieves the album information from the remote server */ public function get_remote_album_images($client,$token,$path) { - + $encoded_key = new XML_RPC_Value($token,'string'); $query_array = array($encoded_key); $xmlrpc_message = new XML_RPC_Message('xmlrpcserver.get_album_images',$query_array); - + /* Depending upon the size of the target catalog this can be a very slow/long process */ set_time_limit(0); @@ -1427,7 +1427,7 @@ class Catalog extends database_object { return; } // get_album_images - + /** * update_remote_catalog * actually updates from the remote data, takes an array of songs that are base64 encoded and parses them @@ -1444,7 +1444,7 @@ class Catalog extends database_object { // Prevent a timeout set_time_limit(0); - + $song = unserialize($serialized_song); $song->artist = self::check_artist($song->artist); $song->album = self::check_album($song->album,$song->year); @@ -1473,7 +1473,7 @@ class Catalog extends database_object { */ public function update_remote_album_images($data, $remote_server, $auth, $path) { $label = "catalog.class.php::update_remote_album_images"; - + $total_updated = 0; /* If album images don't exist, return value will be 0. */ @@ -1491,15 +1491,15 @@ class Catalog extends database_object { $remote_album = new Album(); $remote_album = unserialize($serialized_album); $remote_album->format(); //this will set the fullname - + $debug_text = "remote_album id, name, year: "; - $debug_text.= $remote_album->id . ", " . $remote_album->name . ", " . $remote_album->year; + $debug_text.= $remote_album->id . ", " . $remote_album->name . ", " . $remote_album->year; debug_event($label, $debug_text, '4'); - + // check the album if it exists by checking the name and the year of the album $local_album_id = self::check_album($remote_album->name, $remote_album->year,"","", true); - debug_event($label, "local_album_id: " . $local_album_id, '4'); - + debug_event($label, "local_album_id: " . $local_album_id, '4'); + if ($local_album_id != 0) { // Local album found lets add the cover if(isset($path) AND !preg_match("/^\//", $path)) { $path = "/".$path; } @@ -1509,23 +1509,23 @@ class Catalog extends database_object { $server_path.= "&auth=" . $auth; debug_event($label, "image_url: " . $server_path,'4'); $data['url'] = $server_path; - + $local_album = new Album($local_album_id); $image_data = $local_album->get_image_from_source($data); - + // If we got something back insert it - if ($image_data) { + if ($image_data) { $local_album->insert_art($image_data,""); $total_updated++; debug_event($label, "adding album image succes", '4'); - } else { + } else { debug_event($label, "adding album image failed ", '4'); - } + } } } - + return $total_updated; - + } // update_remote_album_images /** @@ -1537,9 +1537,9 @@ class Catalog extends database_object { // Added set time limit because this runs out of time for some people set_time_limit(0); - - $dead_video = array(); - $dead_song = array(); + + $dead_video = array(); + $dead_song = array(); require_once Config::get('prefix') . '/templates/show_clean_catalog.inc.php'; flush(); @@ -1555,15 +1555,15 @@ class Catalog extends database_object { } /* Get all songs in this catalog */ - $sql = "SELECT `id`,`file`,'song' AS `type` FROM `song` WHERE `catalog`='$this->id' AND `enabled`='1' " . - "UNION ALL " . - "SELECT `id`,`file`,'video' AS `type` FROM `video` WHERE `catalog`='$this->id' AND `enabled`='1'"; + $sql = "SELECT `id`,`file`,'song' AS `type` FROM `song` WHERE `catalog`='$this->id' AND `enabled`='1' " . + "UNION ALL " . + "SELECT `id`,`file`,'video' AS `type` FROM `video` WHERE `catalog`='$this->id' AND `enabled`='1'"; $db_results = Dba::read($sql); // Set to 0 our starting point $dead_files = 0; - $ticker = time(); + $ticker = time(); /* Recurse through files, put @ to prevent errors poping up */ while ($results = Dba::fetch_assoc($db_results)) { @@ -1577,31 +1577,31 @@ class Catalog extends database_object { echo "update_txt('" . addslashes(htmlentities($file)) . "','clean_dir_" . $this->id . "');"; echo "\n\n"; flush(); - $ticker = time(); + $ticker = time(); } //echos song count - + /* Also check the file information */ if($this->catalog_type == 'local') { $file_info = filesize($results['file']); - + /* If it errors somethings splated, or the files empty */ if (!file_exists($results['file']) OR $file_info < 1) { - + /* Add Error */ Error::add('general',_('Error File Not Found or 0 Bytes:') . $results['file']); - $table = ($results['type'] == 'video') ? 'dead_video' : 'dead_song'; + $table = ($results['type'] == 'video') ? 'dead_video' : 'dead_song'; - // Store it in an array we'll delete it later... - ${$table}[] = $results['id']; + // Store it in an array we'll delete it later... + ${$table}[] = $results['id']; // Count em! $dead_files++; } //if error - if (!is_readable($results['file'])) { - debug_event('Clean','Error ' . $results['file'] . ' is not readable, but does exist','1'); - } + if (!is_readable($results['file'])) { + debug_event('Clean','Error ' . $results['file'] . ' is not readable, but does exist','1'); + } } // if localtype else { //do remote url check @@ -1613,10 +1613,10 @@ class Catalog extends database_object { Error::add('general',_('Error Remote File Not Found or 0 Bytes:') . $results['file']); - $table = ($results['type'] == 'video') ? 'dead_video' : 'dead_song'; + $table = ($results['type'] == 'video') ? 'dead_video' : 'dead_song'; - // Store it in an array we'll delete it later... - ${$table}[] = $results['id']; + // Store it in an array we'll delete it later... + ${$table}[] = $results['id']; // Count em! $dead_files++; @@ -1628,21 +1628,21 @@ class Catalog extends database_object { // Check and see if _everything_ has gone away, might indicate a dead mount // We call this the AlmightyOatmeal Sanity check - if ($dead_files == $count) { - Error::add('general',_('Error All songs would be removed, doing nothing')); - return false; - } - else { - if (count($dead_video)) { - $idlist = '(' . implode(',',$dead_video) . ')'; - $sql = "DELETE FROM `video` WHERE `id` IN $idlist"; - $db_results = Dba::write($sql); - } - if (count($dead_song)) { - $idlist = '(' . implode(',',$dead_song) . ')'; - $sql = "DELETE FROM `song` WHERE `id` IN $idlist"; - $db_results = Dba::write($sql); - } + if ($dead_files == $count) { + Error::add('general',_('Error All songs would be removed, doing nothing')); + return false; + } + else { + if (count($dead_video)) { + $idlist = '(' . implode(',',$dead_video) . ')'; + $sql = "DELETE FROM `video` WHERE `id` IN $idlist"; + $db_results = Dba::write($sql); + } + if (count($dead_song)) { + $idlist = '(' . implode(',',$dead_song) . ')'; + $sql = "DELETE FROM `song` WHERE `id` IN $idlist"; + $db_results = Dba::write($sql); + } } /* Step two find orphaned Arists/Albums @@ -1665,7 +1665,7 @@ class Catalog extends database_object { flush(); // Set the last clean date - $this->update_last_clean(); + $this->update_last_clean(); } //clean_catalog @@ -1677,7 +1677,7 @@ class Catalog extends database_object { public static function clean_tags() { $sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `song` ON `song`.`id`=`tag_map`.`object_id` " . - "WHERE `tag_map`.`object_type`='song' AND `song`.`id` IS NULL"; + "WHERE `tag_map`.`object_type`='song' AND `song`.`id` IS NULL"; $db_results = Dba::write($sql); $sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `album` ON `album`.`id`=`tag_map`.`object_id` " . @@ -1688,13 +1688,13 @@ class Catalog extends database_object { "WHERE `tag_map`.`object_type`='artist' AND `artist`.`id` IS NULL"; $db_results = Dba::write($sql); - $sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `video` ON `video`.`id`=`tag_map`.`object_id` " . - "WHERE `tag_map`.`object_type`='video' AND `video`.`id` IS NULL"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `tag_map` USING `tag_map` LEFT JOIN `video` ON `video`.`id`=`tag_map`.`object_id` " . + "WHERE `tag_map`.`object_type`='video' AND `video`.`id` IS NULL"; + $db_results = Dba::write($sql); // Now nuke the tags themselves $sql = "DELETE FROM `tag` USING `tag` LEFT JOIN `tag_map` ON `tag`.`id`=`tag_map`.`tag_id` " . - "WHERE `tag_map`.`id` IS NULL"; + "WHERE `tag_map`.`id` IS NULL"; $db_results = Dba::write($sql); } // clean_tags @@ -1707,7 +1707,7 @@ class Catalog extends database_object { // Clean songs $sql = "DELETE FROM `user_shout` USING `user_shout` LEFT JOIN `song` ON `song`.`id`=`user_shout`.`object_id` " . - "WHERE `song`.`id` IS NULL AND `user_shout`.`object_type`='song'"; + "WHERE `song`.`id` IS NULL AND `user_shout`.`object_type`='song'"; $db_results = Dba::write($sql); // Clean albums @@ -1780,7 +1780,7 @@ class Catalog extends database_object { // Clear TMP Playlist information as well $sql = "DELETE FROM `tmp_playlist_data` USING `tmp_playlist_data` LEFT JOIN `song` ON `tmp_playlist_data`.`object_id` = `song`.`id` " . - "WHERE `song`.`id` IS NULL"; + "WHERE `song`.`id` IS NULL"; $db_results = Dba::write($sql); } // clean_playlists @@ -1792,7 +1792,7 @@ class Catalog extends database_object { public static function clean_ext_info() { $sql = "DELETE FROM `song_data` USING `song_data` LEFT JOIN `song` ON `song`.`id` = `song_data`.`song_id` " . - "WHERE `song`.`id` IS NULL"; + "WHERE `song`.`id` IS NULL"; $db_results = Dba::write($sql); } // clean_ext_info @@ -1820,9 +1820,9 @@ class Catalog extends database_object { $db_results = Dba::write($sql); // Clean the stats - $sql = "DELETE FROM `object_count` USING `object_count` LEFT JOIN `video` ON `video`.`id`=`object_count`.`object_id` " . - "WHERE `object_count`.`object_type`='video' AND `video`.`id` IS NULL"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `object_count` USING `object_count` LEFT JOIN `video` ON `video`.`id`=`object_count`.`object_id` " . + "WHERE `object_count`.`object_type`='video' AND `video`.`id` IS NULL"; + $db_results = Dba::write($sql); // Delete Song Ratings information $sql = "DELETE FROM rating USING rating LEFT JOIN song ON song.id=rating.object_id WHERE object_type='song' AND song.id IS NULL"; @@ -1837,8 +1837,8 @@ class Catalog extends database_object { $db_results = Dba::write($sql); // Delete the Video Rating Informations - $sql = "DELETE FROM `rating` USING `rating` LEFT JOIN `video` ON `video`.`id`=`rating`.`object_id` " . - "WHERE `rating`.`object_type`='video' AND `video`.`id` IS NULL"; + $sql = "DELETE FROM `rating` USING `rating` LEFT JOIN `video` ON `video`.`id`=`rating`.`object_id` " . + "WHERE `rating`.`object_type`='video' AND `video`.`id` IS NULL"; $db_results = Dba::write($sql); } // clean_stats @@ -1852,44 +1852,44 @@ class Catalog extends database_object { // Create the object so we have some information on it $catalog = new Catalog($catalog_id); - $cache = array(); - $songs = array(); + $cache = array(); + $songs = array(); // Record that we're caching this stuff so it makes debugging easier debug_event('Verify','Starting Verify of '. $catalog->name . ' caching data...','5'); /* First get the filenames for the catalog */ $sql = "SELECT `id`,`file`,`artist`,`album`,'song' AS `type` FROM `song` WHERE `song`.`catalog`='$catalog_id' "; - $db_results = Dba::read($sql); - - while ($row = Dba::fetch_assoc($db_results)) { - $cache[] = $row['id']; - $artists[] = $row['artist']; - $albums[] = $row['album']; - $songs[] = $row; - } + $db_results = Dba::read($sql); - Song::build_cache($cache); - Flag::build_map_cache($cache,'song'); - Tag::build_map_cache('album',$albums); - Tag::build_map_cache('artist',$artists); - Tag::build_map_cache('song',$cache); - - $cache = array(); - $videos = array(); - $sql = "SELECT `id`,`file`,'video' AS `type` FROM `video` WHERE `video`.`catalog`='$catalog_id'"; - $db_results = Dba::read($sql); - - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { $cache[] = $row['id']; - $videos[] = $row; - } - Video::build_cache($cache); - Flag::build_map_cache($cache,'video'); + $artists[] = $row['artist']; + $albums[] = $row['album']; + $songs[] = $row; + } - $cached_results = array_merge($songs,$videos); + Song::build_cache($cache); + Flag::build_map_cache($cache,'song'); + Tag::build_map_cache('album',$albums); + Tag::build_map_cache('artist',$artists); + Tag::build_map_cache('song',$cache); - $number = count($cached_results); + $cache = array(); + $videos = array(); + $sql = "SELECT `id`,`file`,'video' AS `type` FROM `video` WHERE `video`.`catalog`='$catalog_id'"; + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + $cache[] = $row['id']; + $videos[] = $row; + } + Video::build_cache($cache); + Flag::build_map_cache($cache,'video'); + + $cached_results = array_merge($songs,$videos); + + $number = count($cached_results); require_once Config::get('prefix') . '/templates/show_verify_catalog.inc.php'; flush(); @@ -1899,18 +1899,18 @@ class Catalog extends database_object { // Caching array for album art, save us some time here $album_art_check_cache = array(); - $ticker = time(); + $ticker = time(); /* Recurse through this catalogs files * and get the id3 tage information, * if it's not blank, and different in * in the file then update! */ - foreach ($cached_results as $results) { + foreach ($cached_results as $results) { debug_event('verify',"Starting work on " . $results['file'],'5','ampache-catalog'); $type = ($results['type'] == 'video') ? 'video' : 'song'; - + if (is_readable($results['file'])) { /* Create the object from the existing database information */ @@ -1923,9 +1923,9 @@ class Catalog extends database_object { $skip = true; } - if (filemtime($results['file']) <= $media->update_time) { - $skip = true; - } + if (filemtime($results['file']) <= $media->update_time) { + $skip = true; + } // if the file hasn't been modified since the last_update if (!$skip) { @@ -1951,7 +1951,7 @@ class Catalog extends database_object { echo "update_txt('" . scrub_out($file) . "','verify_dir_" . $catalog_id . "');"; echo "\n\n"; flush(); - $ticker = time(); + $ticker = time(); } //echos song count } // end if file exists @@ -2014,8 +2014,8 @@ class Catalog extends database_object { public static function optimize_tables() { $sql = "OPTIMIZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" . - ",`artist`,`ip_history`,`flagged`,`now_playing`,`user_preference`,`tag`,`tag_map`,`tmp_playlist`" . - ",`tmp_playlist_data`,`playlist`,`playlist_data`,`session_stream`,`video`"; + ",`artist`,`ip_history`,`flagged`,`now_playing`,`user_preference`,`tag`,`tag_map`,`tmp_playlist`" . + ",`tmp_playlist_data`,`playlist`,`playlist_data`,`session_stream`,`video`"; $db_results = Dba::write($sql); $sql = "ANALYZE TABLE `song_data`,`song`,`rating`,`catalog`,`session`,`object_count`,`album`,`album_data`" . @@ -2098,7 +2098,7 @@ class Catalog extends database_object { unset($id_array); } } // fuzzy matching - + /* If not found create */ if (!$readonly && !$exists) { @@ -2205,7 +2205,7 @@ class Catalog extends database_object { } // Save the cache - self::$albums[$album][$album_year][$disk][$mbid] = $album_id; + self::$albums[$album][$album_year][$disk][$mbid] = $album_id; return $album_id; @@ -2213,18 +2213,18 @@ class Catalog extends database_object { /** * check_tag - * This checks the tag we've been passed (name) + * This checks the tag we've been passed (name) * and sees if it exists, and if so if it's mapped * to this object, this is only done for songs for now */ - public static function check_tag($value,$object_id,$object_type='song') { + public static function check_tag($value,$object_id,$object_type='song') { - $map_id = Tag::add($object_type,$object_id,$value,'0'); + $map_id = Tag::add($object_type,$object_id,$value,'0'); - return $map_id; + return $map_id; } // check_tag - + /** * check_title * this checks to make sure something is @@ -2294,21 +2294,21 @@ class Catalog extends database_object { debug_event('insert',"Unable to insert $file -- $sql" . Dba::error(),'5','ampache-catalog'); Error::add('catalog_add','SQL Error Adding ' . $file); } - + $song_id = Dba::insert_id(); // multiple genre support foreach ($tags as $tag) { $tag = trim($tag); self::check_tag($tag,$song_id); - self::check_tag($tag,$album_id,'album'); + self::check_tag($tag,$album_id,'album'); self::check_tag($tag,$artist_id,'artist'); } /* Add the EXT information */ $sql = "INSERT INTO `song_data` (`song_id`,`comment`,`lyrics`) " . - " VALUES ('$song_id','$comment','$lyrics')"; + " VALUES ('$song_id','$comment','$lyrics')"; $db_results = Dba::write($sql); if (!$db_results) { @@ -2339,7 +2339,7 @@ class Catalog extends database_object { echo "Error Adding Remote $url
$sql
\n"; flush(); } - + } // insert_remote_song /** @@ -2348,36 +2348,36 @@ class Catalog extends database_object { * information we can get is super sketchy so it's kind of a crap shoot * here */ - public function insert_local_video($file,$filesize) { + public function insert_local_video($file,$filesize) { /* Create the vainfo object and get info */ $vainfo = new vainfo($file,'','','',$this->sort_pattern,$this->rename_pattern); $vainfo->get_info(); - $tag_name = vainfo::get_tag_type($vainfo->tags); - $results = vainfo::clean_tag_info($vainfo->tags,$tag_name,$file); + $tag_name = vainfo::get_tag_type($vainfo->tags); + $results = vainfo::clean_tag_info($vainfo->tags,$tag_name,$file); - $file = Dba::escape($file); - $catalog_id = Dba::escape($this->id); - $title = Dba::escape($results['title']); - $vcodec = $results['video_codec']; - $acodec = $results['audio_codec']; - $rezx = intval($results['resolution_x']); - $rezy = intval($results['resolution_y']); - $filesize = Dba::escape($filesize); - $time = Dba::escape($results['time']); - $mime = Dba::escape($results['mime']); + $file = Dba::escape($file); + $catalog_id = Dba::escape($this->id); + $title = Dba::escape($results['title']); + $vcodec = $results['video_codec']; + $acodec = $results['audio_codec']; + $rezx = intval($results['resolution_x']); + $rezy = intval($results['resolution_y']); + $filesize = Dba::escape($filesize); + $time = Dba::escape($results['time']); + $mime = Dba::escape($results['mime']); // UNUSED CURRENTLY - $comment = Dba::escape($results['comment']); - $year = Dba::escape($results['year']); - $disk = Dba::escape($results['disk']); + $comment = Dba::escape($results['comment']); + $year = Dba::escape($results['year']); + $disk = Dba::escape($results['disk']); - $sql = "INSERT INTO `video` (`file`,`catalog`,`title`,`video_codec`,`audio_codec`,`resolution_x`,`resolution_y`,`size`,`time`,`mime`) " . - " VALUES ('$file','$catalog_id','$title','$vcodec','$acodec','$rezx','$rezy','$filesize','$time','$mime')"; - $db_results = Dba::write($sql); + $sql = "INSERT INTO `video` (`file`,`catalog`,`title`,`video_codec`,`audio_codec`,`resolution_x`,`resolution_y`,`size`,`time`,`mime`) " . + " VALUES ('$file','$catalog_id','$title','$vcodec','$acodec','$rezx','$rezy','$filesize','$time','$mime')"; + $db_results = Dba::write($sql); - return true; + return true; } // insert_local_video @@ -2541,7 +2541,7 @@ class Catalog extends database_object { $name = "M3U - " . basename($filename,'.m3u'); $playlist_id = Playlist::create($name,'public'); - if (!$playlist_id) { + if (!$playlist_id) { $reason = _('Playlist creation error.'); return false; } @@ -2549,13 +2549,13 @@ class Catalog extends database_object { /* Recreate the Playlist */ $playlist = new Playlist($playlist_id); $playlist->add_songs($songs); - $reason = sprintf(ngettext('Playlist Import and Recreate Successful. Total: %d Song', + $reason = sprintf(ngettext('Playlist Import and Recreate Successful. Total: %d Song', 'Playlist Import and Recreate Successful. Total: %d Songs', count($songs)), count($songs)); return true; } /* HINT: filename */ - $reason = sprintf(ngettext('Parsing %s - Not Found: %d Song. Please check your m3u file.', + $reason = sprintf(ngettext('Parsing %s - Not Found: %d Song. Please check your m3u file.', 'Parsing %s - Not Found: %d Songs. Please check your m3u file.', count($songs)), $filename, count($songs)); return false; @@ -2578,10 +2578,10 @@ class Catalog extends database_object { // Only if the previous one works do we go on if (!$db_results) { return false; } - $sql = "DELETE FROM `video` WHERE `catalog` = '$catalog_id'"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `video` WHERE `catalog` = '$catalog_id'"; + $db_results = Dba::write($sql); - if (!$db_results) { return false; } + if (!$db_results) { return false; } // Next Remove the Catalog Entry it's self $sql = "DELETE FROM `catalog` WHERE `id` = '$catalog_id'"; @@ -2601,7 +2601,7 @@ class Catalog extends database_object { // Select all songs in catalog if($this->id) { $sql = "SELECT id FROM song WHERE catalog = '$this->id' ORDER BY album,track"; - } + } else { $sql = "SELECT id FROM song ORDER BY album,track"; } @@ -2642,9 +2642,9 @@ class Catalog extends database_object { $song = new Song($results['id']); $song->format(); echo '"' . $song->id . '","' . $song->title . '","' . $song->f_artist_full . '","' . $song->f_album_full . - '","' . $song->f_genre . '","' . $song->f_time . '","' . $song->f_track . '","' . $song->year . - '","' . date("Y-m-d\TH:i:s\Z",$song->addition_time) . '","' . $song->f_bitrate . - '","' . $song->played . '","' . $song->file . "\n"; + '","' . $song->f_genre . '","' . $song->f_time . '","' . $song->f_track . '","' . $song->year . + '","' . date("Y-m-d\TH:i:s\Z",$song->addition_time) . '","' . $song->f_bitrate . + '","' . $song->played . '","' . $song->file . "\n"; } break; } // end switch diff --git a/lib/class/config.class.php b/lib/class/config.class.php index 1bd18806..601a7813 100644 --- a/lib/class/config.class.php +++ b/lib/class/config.class.php @@ -23,25 +23,25 @@ /* config class * used to store static arrays of * config values, can read from ini files - * + * * has static methods, this uses the global config * creating a 'Config' object will allow for local * config overides and/or local configs (for like dba) - * The class should be a static var in the other classes + * The class should be a static var in the other classes */ class Config { // These are the settings for this specific class - private $_local = array(); + private $_local = array(); // These are the global settings they go where it goes - private static $_global = array(); + private static $_global = array(); /** * constructor * This is what is called when the class is loaded */ - public function __construct() { + public function __construct() { // Rien a faire @@ -62,12 +62,12 @@ class Config { * get_all * This returns all of the current config variables as an array */ - public static function get_all() { + public static function get_all() { - return self::$_global; + return self::$_global; } // get_all - + /** * set * This checks to see if this is an instance or procedure calls @@ -75,13 +75,13 @@ class Config { */ public static function set($name, $value, $clobber = 0) { - if (isset(self::$_global[$name]) && !$clobber) { - Error::add('Config Global',"Trying to clobber'$name' without setting clobber"); + if (isset(self::$_global[$name]) && !$clobber) { + Error::add('Config Global',"Trying to clobber'$name' without setting clobber"); return; } - else { - self::$_global[$name] = $value; - } + else { + self::$_global[$name] = $value; + } } // set @@ -90,12 +90,12 @@ class Config { * This is the same as the set function except it takes an array as input */ public static function set_by_array($array, $clobber = 0) { - - foreach ($array as $name => $value) { - self::set($name,$value,$clobber); - } + + foreach ($array as $name => $value) { + self::set($name,$value,$clobber); + } } // set_by_array - + } // end Config class ?> diff --git a/lib/class/core.class.php b/lib/class/core.class.php index 5162c20b..683107d3 100644 --- a/lib/class/core.class.php +++ b/lib/class/core.class.php @@ -31,9 +31,9 @@ class Core { * constructor * This doesn't do anything */ - private function __construct() { + private function __construct() { - return false; + return false; } // construction @@ -42,25 +42,25 @@ class Core { * This registers a form with a SID, inserts it into the session variables * and then returns a string for use in the HTML form */ - public static function form_register($name,$type='post') { + public static function form_register($name,$type='post') { // Make ourselves a nice little sid $sid = md5(uniqid(rand(), true)); // Register it - $_SESSION['forms'][$name] = array('sid'=>$sid,'expire'=>time() + Config::get('session_length')); + $_SESSION['forms'][$name] = array('sid'=>$sid,'expire'=>time() + Config::get('session_length')); - switch ($type) { - default: - case 'post': - $string = ''; - break; - case 'get': - $string = $sid; - break; + switch ($type) { + default: + case 'post': + $string = ''; + break; + case 'get': + $string = $sid; + break; } // end switch on type - return $string; + return $string; } // form_register @@ -69,30 +69,30 @@ class Core { * This takes a form name and then compares it with the posted sid, if they don't match * then it returns false and doesn't let the person continue */ - public static function form_verify($name,$method='post') { + public static function form_verify($name,$method='post') { - switch ($method) { - case 'post': - $source = $_POST['form_validation']; - break; - case 'get': + switch ($method) { + case 'post': + $source = $_POST['form_validation']; + break; + case 'get': $source = $_GET['form_validation']; - break; - case 'cookie': - $source = $_COOKIE['form_validation']; - break; - case 'request': - $source = $_REQUEST['form_validation']; - break; - } + break; + case 'cookie': + $source = $_COOKIE['form_validation']; + break; + case 'request': + $source = $_REQUEST['form_validation']; + break; + } - if ($source == $_SESSION['forms'][$name]['sid'] AND $_SESSION['forms'][$name]['expire'] > time()) { - unset($_SESSION['forms'][$name]); - return true; - } + if ($source == $_SESSION['forms'][$name]['sid'] AND $_SESSION['forms'][$name]['expire'] > time()) { + unset($_SESSION['forms'][$name]); + return true; + } - unset($_SESSION['forms'][$name]); - return false; + unset($_SESSION['forms'][$name]); + return false; } // form_verify @@ -101,21 +101,21 @@ class Core { * This returns the dimensions of the passed song of the passed type * returns an empty array if PHP-GD is not currently installed, returns * false on error - */ - public static function image_dimensions($image_data) { + */ + public static function image_dimensions($image_data) { - if (!function_exists('ImageCreateFromString')) { return false; } + if (!function_exists('ImageCreateFromString')) { return false; } - $image = ImageCreateFromString($image_data); + $image = ImageCreateFromString($image_data); - if (!$image) { return false; } + if (!$image) { return false; } - $width = imagesx($image); - $height = imagesy($image); + $width = imagesx($image); + $height = imagesy($image); - if (!$width || !$height) { return false; } + if (!$width || !$height) { return false; } - return array('width'=>$width,'height'=>$height); + return array('width'=>$width,'height'=>$height); } // image_dimensions diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php index 4d592b0b..1c6afbdc 100644 --- a/lib/class/democratic.class.php +++ b/lib/class/democratic.class.php @@ -27,32 +27,32 @@ */ class Democratic extends tmpPlaylist { - public $name; - public $cooldown; - public $level; - public $user; - public $primary; - public $base_playlist; + public $name; + public $cooldown; + public $level; + public $user; + public $primary; + public $base_playlist; // Build local, buy local - public $tmp_playlist; - public $object_ids = array(); - public $vote_ids = array(); - public $user_votes = array(); + public $tmp_playlist; + public $object_ids = array(); + public $vote_ids = array(); + public $user_votes = array(); /** * constructor * We need a constructor for this class. It does it's own thing now */ - public function __construct($id='') { + public function __construct($id='') { - if (!$id) { return false; } + if (!$id) { return false; } - $info = $this->get_info($id); - - foreach ($info as $key=>$value) { - $this->$key = $value; - } + $info = $this->get_info($id); + + foreach ($info as $key=>$value) { + $this->$key = $value; + } } // constructor @@ -60,20 +60,20 @@ class Democratic extends tmpPlaylist { * build_vote_cache * This builds a vote cache of the objects we've got in the playlist */ - public static function build_vote_cache($ids) { + public static function build_vote_cache($ids) { - if (!is_array($ids) OR !count($ids)) { return false; } + if (!is_array($ids) OR !count($ids)) { return false; } - $idlist = '(' . implode(',',$ids) . ')'; + $idlist = '(' . implode(',',$ids) . ')'; - $sql = "SELECT `object_id`,COUNT(`user`) AS `count` FROM user_vote WHERE `object_id` IN $idlist GROUP BY `object_id`"; - $db_results = Dba::read($sql); + $sql = "SELECT `object_id`,COUNT(`user`) AS `count` FROM user_vote WHERE `object_id` IN $idlist GROUP BY `object_id`"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('democratic_vote',$row['object_id'],$row['count']); - } + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('democratic_vote',$row['object_id'],$row['count']); + } - return true; + return true; } // build_vote_cache @@ -82,11 +82,11 @@ class Democratic extends tmpPlaylist { * This function just returns true / false if the current democraitc playlist * is currently enabled / configured */ - public function is_enabled() { + public function is_enabled() { - if ($this->tmp_playlist) { return true; } + if ($this->tmp_playlist) { return true; } - return false; + return false; } // is_enabled @@ -94,16 +94,16 @@ class Democratic extends tmpPlaylist { * set_parent * This returns the tmpPlaylist for this democratic play instance */ - public function set_parent() { + public function set_parent() { - $demo_id = Dba::escape($this->id); + $demo_id = Dba::escape($this->id); - $sql = "SELECT * FROM `tmp_playlist` WHERE `session`='$demo_id'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `tmp_playlist` WHERE `session`='$demo_id'"; + $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - $this->tmp_playlist = $row['id']; + $this->tmp_playlist = $row['id']; } // set_parent @@ -111,24 +111,24 @@ class Democratic extends tmpPlaylist { /** * set_user_preferences * This sets up a (or all) user(s) to use democratic play. This sets their play method - * and playlist method (clear on send) If no user is passed it does it for everyone and + * and playlist method (clear on send) If no user is passed it does it for everyone and * also locks down the ability to change to admins only */ - public static function set_user_preferences($user=NULL) { + public static function set_user_preferences($user=NULL) { //FIXME: Code in single user stuff - $preference_id = Preference::id_from_name('play_type'); - Preference::update_level($preference_id,'75'); - Preference::update_all($preference_id,'democratic'); + $preference_id = Preference::id_from_name('play_type'); + Preference::update_level($preference_id,'75'); + Preference::update_all($preference_id,'democratic'); - $allow_demo = Preference::id_from_name('allow_democratic_playback'); - Preference::update_all($allow_demo,'1'); + $allow_demo = Preference::id_from_name('allow_democratic_playback'); + Preference::update_all($allow_demo,'1'); - $play_method = Preference::id_from_name('playlist_method'); - Preference::update_all($play_method,'clear'); + $play_method = Preference::id_from_name('playlist_method'); + Preference::update_all($play_method,'clear'); - return true; + return true; } // set_user_preferences @@ -136,28 +136,28 @@ class Democratic extends tmpPlaylist { * format * This makes the objects variables all purrty so that they can be displayed */ - public function format() { + public function format() { - $this->f_cooldown = $this->cooldown . ' ' . _('minutes'); - $this->f_primary = $this->primary ? _('Primary') : ''; + $this->f_cooldown = $this->cooldown . ' ' . _('minutes'); + $this->f_primary = $this->primary ? _('Primary') : ''; - switch ($this->level) { - case '5': - $this->f_level = _('Guest'); - break; - case '25': - $this->f_level = _('User'); - break; - case '50': - $this->f_level = _('Content Manager'); - break; - case '75': - $this->f_level = _('Catalog Manager'); - break; - case '100': - $this->f_level = _('Admin'); - break; - } + switch ($this->level) { + case '5': + $this->f_level = _('Guest'); + break; + case '25': + $this->f_level = _('User'); + break; + case '50': + $this->f_level = _('Content Manager'); + break; + case '75': + $this->f_level = _('Catalog Manager'); + break; + case '100': + $this->f_level = _('Admin'); + break; + } } // format @@ -166,21 +166,21 @@ class Democratic extends tmpPlaylist { * This returns all of the current valid 'Democratic' Playlists * that have been created. */ - public static function get_playlists() { + public static function get_playlists() { - // Pull all tmp playlsits with a session of < 0 (as those are fake) + // Pull all tmp playlsits with a session of < 0 (as those are fake) // This is kind of hackish, should really think about tweaking the db - // and doing this right. - $sql = "SELECT `id` FROM `democratic` ORDER BY `name`"; - $db_results = Dba::read($sql); + // and doing this right. + $sql = "SELECT `id` FROM `democratic` ORDER BY `name`"; + $db_results = Dba::read($sql); - $results = array(); + $results = array(); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['id']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } - return $results; + return $results; } // get_playlists @@ -189,22 +189,22 @@ class Democratic extends tmpPlaylist { * This returns the curren users current playlist, or if specified * this current playlist of the user */ - public static function get_current_playlist() { + public static function get_current_playlist() { - $democratic_id = Config::get('democratic_id'); + $democratic_id = Config::get('democratic_id'); - if (!$democratic_id) { - $level = Dba::escape($GLOBALS['user']->access); - $sql = "SELECT `id` FROM `democratic` WHERE `level` <= '$level' " . - " ORDER BY `level` DESC,`primary` DESC"; - $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + if (!$democratic_id) { + $level = Dba::escape($GLOBALS['user']->access); + $sql = "SELECT `id` FROM `democratic` WHERE `level` <= '$level' " . + " ORDER BY `level` DESC,`primary` DESC"; + $db_results = Dba::read($sql); + $row = Dba::fetch_assoc($db_results); $democratic_id = $row['id']; - } + } - $object = new Democratic($democratic_id); + $object = new Democratic($democratic_id); - return $object; + return $object; } // get_current_playlist @@ -214,7 +214,7 @@ class Democratic extends tmpPlaylist { * has gotten a little more complicated because of type, the values are an array * 0 being ID 1 being TYPE * FIXME: This is too complex, it makes my brain hurt - * [VOTE COUNT] + * [VOTE COUNT] * [DATE OF NEWEST VOTE] * [ROW ID] * [OBJECT_ID] @@ -237,46 +237,46 @@ class Democratic extends tmpPlaylist { /* Define the array */ $items = array(); - $votes = array(); - $object_ids = array(); + $votes = array(); + $object_ids = array(); // Itterate and build the sortable array while ($results = Dba::fetch_assoc($db_results)) { - + // Extra set of data for caching! - $this->object_ids[] = $results['object_id']; - $this->vote_ids[] = $results['vote_id']; + $this->object_ids[] = $results['object_id']; + $this->vote_ids[] = $results['vote_id']; // First build a variable that holds the number of votes for an object $name = 'vc_' . $results['object_id']; // Check if the vote is older then our current vote for this object - if ($votes[$results['object_id']] < $results['date'] OR !isset($votes[$results['object_id']])) { - $votes[$results['object_id']] = $results['date']; - } + if ($votes[$results['object_id']] < $results['date'] OR !isset($votes[$results['object_id']])) { + $votes[$results['object_id']] = $results['date']; + } // Append one to the vote - ${$name}++; - $primary_key = ${$name}; - $secondary_key = $votes[$results['object_id']]; + ${$name}++; + $primary_key = ${$name}; + $secondary_key = $votes[$results['object_id']]; $items[$primary_key][$secondary_key][$results['id']] = array('object_id'=>$results['object_id'],'object_type'=>$results['object_type'],'id'=>$results['id']); } // gather data // Sort highest voted stuff to the top - krsort($items); + krsort($items); - $sorted_items = array(); + $sorted_items = array(); // re-collapse the array - foreach ($items as $vote_count=>$date_array) { - ksort($date_array); - foreach ($date_array as $object_array) { - foreach ($object_array as $key=>$sorted_array) { + foreach ($items as $vote_count=>$date_array) { + ksort($date_array); + foreach ($date_array as $object_array) { + foreach ($object_array as $key=>$sorted_array) { $sorted_items[$key] = $sorted_array; - } - } - } + } + } + } return $sorted_items; @@ -288,7 +288,7 @@ class Democratic extends tmpPlaylist { */ public function play_url() { - $link = Stream::get_base_url() . 'uid=' . scrub_out($GLOBALS['user']->id) . '&demo_id=' . scrub_out($this->id); + $link = Stream::get_base_url() . 'uid=' . scrub_out($GLOBALS['user']->id) . '&demo_id=' . scrub_out($this->id); return $link; @@ -296,22 +296,22 @@ class Democratic extends tmpPlaylist { /** * get_next_object - * This returns the next object in the tmp_playlist most of the time this + * 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($offset='') { - - $offset = $offset ? intval($offset) : '0'; + + $offset = $offset ? intval($offset) : '0'; // We have to get all because of the pysco sorting - $items = self::get_items(); + $items = self::get_items(); - if (count($items) > $offset) { - $array = array_slice($items,$offset,1); - $item = array_shift($array); + if (count($items) > $offset) { + $array = array_slice($items,$offset,1); + $item = array_shift($array); $results['object_id'] = $item['object_id']; - } + } /* If nothing was found and this is a voting playlist then get from base_playlist */ if (!$results['object_id']) { @@ -321,7 +321,7 @@ class Democratic extends tmpPlaylist { /* We need to pull a random one from the base_playlist */ $base_playlist = new Playlist($this->base_playlist); $data = $base_playlist->get_random_items(1); - $results['object_id'] = $data['0']['object_id']; + $results['object_id'] = $data['0']['object_id']; } else { $sql = "SELECT `id` as `object_id` FROM `song` WHERE `enabled`='1' ORDER BY RAND() LIMIT 1"; @@ -338,42 +338,42 @@ class Democratic extends tmpPlaylist { * get_uid_from_object_id * This takes an object_id and an object type and returns the ID for the row */ - public function get_uid_from_object_id($object_id,$object_type='') { + public function get_uid_from_object_id($object_id,$object_type='') { - $object_id = Dba::escape($object_id); - $object_type = $object_type ? Dba::escape($object_type) : 'song'; + $object_id = Dba::escape($object_id); + $object_type = $object_type ? Dba::escape($object_type) : 'song'; $tmp_id = Dba::escape($this->tmp_playlist); - $sql = "SELECT `tmp_playlist_data`.`id` FROM `tmp_playlist_data` WHERE `object_type`='$object_type' AND " . - "`tmp_playlist`='$tmp_id' AND `object_id`='$object_id'"; - $db_results = Dba::read($sql); + $sql = "SELECT `tmp_playlist_data`.`id` FROM `tmp_playlist_data` WHERE `object_type`='$object_type' AND " . + "`tmp_playlist`='$tmp_id' AND `object_id`='$object_id'"; + $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - return $row['id']; + return $row['id']; } // get_uid_from_object_id /** * get_cool_songs * This returns all of the song_ids for songs that have happened within the last 'cooldown' - * for this user. + * for this user. */ - public function get_cool_songs() { + public function get_cool_songs() { // Convert cooldown time to a timestamp in the past - $cool_time = time() - ($this->cooldown * 60); + $cool_time = time() - ($this->cooldown * 60); - $song_ids = Stats::get_object_history($GLOBALS['user']->id,$cool_time); + $song_ids = Stats::get_object_history($GLOBALS['user']->id,$cool_time); - return $song_ids; + return $song_ids; } // get_cool_songs /** * vote * This function is called by users to vote on a system wide playlist - * This adds the specified objects to the tmp_playlist and adds a 'vote' + * This adds the specified objects to the tmp_playlist and adds a 'vote' * by this user, naturally it checks to make sure that the user hasn't * already voted on any of these objects */ @@ -381,8 +381,8 @@ class Democratic extends tmpPlaylist { /* Itterate through the objects if no vote, add to playlist and vote */ foreach ($items as $element) { - $type = array_shift($element); - $object_id = array_shift($element); + $type = array_shift($element); + $object_id = array_shift($element); if (!$this->has_vote($object_id,$type)) { $this->add_vote($object_id,$type); } @@ -397,9 +397,9 @@ class Democratic extends tmpPlaylist { public function has_vote($object_id,$type='') { $tmp_id = Dba::escape($this->tmp_playlist); - $object_id = Dba::escape($object_id); - $type = $type ? Dba::escape($type) : 'song'; - $user_id = Dba::escape($GLOBALS['user']->id); + $object_id = Dba::escape($object_id); + $type = $type ? Dba::escape($type) : 'song'; + $user_id = Dba::escape($GLOBALS['user']->id); /* Query vote table */ $sql = "SELECT tmp_playlist_data.object_id FROM `user_vote` " . @@ -423,13 +423,13 @@ class Democratic extends tmpPlaylist { * This takes a object id and user and actually inserts the row */ public function add_vote($object_id,$object_type='') { - + $object_id = Dba::escape($object_id); $tmp_playlist = Dba::escape($this->tmp_playlist); - $object_type = $object_type ? Dba::escape($object_type) : 'song'; - $media = new $object_type($object_id); - $track = isset($media->track) ? "'" . intval($media->track) . "'" : "NULL"; - + $object_type = $object_type ? Dba::escape($object_type) : 'song'; + $media = new $object_type($object_id); + $track = isset($media->track) ? "'" . intval($media->track) . "'" : "NULL"; + /* If it's on the playlist just vote */ $sql = "SELECT `id` FROM `tmp_playlist_data` " . "WHERE `tmp_playlist_data`.`object_id`='$object_id' AND `tmp_playlist_data`.`tmp_playlist`='$tmp_playlist'"; @@ -478,17 +478,17 @@ class Democratic extends tmpPlaylist { * delete_votes * This removes the votes for the specified object on the current playlist */ - public function delete_votes($row_id) { + public function delete_votes($row_id) { - $row_id = Dba::escape($row_id); + $row_id = Dba::escape($row_id); - $sql = "DELETE FROM `user_vote` WHERE `object_id`='$row_id'"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `user_vote` WHERE `object_id`='$row_id'"; + $db_results = Dba::write($sql); - $sql = "DELETE FROM `tmp_playlist_data` WHERE `id`='$row_id'"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `tmp_playlist_data` WHERE `id`='$row_id'"; + $db_results = Dba::write($sql); - return true; + return true; } // delete_votes @@ -496,19 +496,19 @@ class Democratic extends tmpPlaylist { * delete * This deletes a democratic playlist */ - public static function delete($democratic_id) { - - $democratic_id = Dba::escape($democratic_id); + public static function delete($democratic_id) { - $sql = "DELETE FROM `democratic` WHERE `id`='$democratic_id'"; - $db_results = Dba::write($sql); + $democratic_id = Dba::escape($democratic_id); - $sql = "DELETE FROM `tmp_playlist` WHERE `session`='$democratic_id'"; - $db_results = Dba::write($sql); - - self::prune_tracks(); + $sql = "DELETE FROM `democratic` WHERE `id`='$democratic_id'"; + $db_results = Dba::write($sql); - return true; + $sql = "DELETE FROM `tmp_playlist` WHERE `session`='$democratic_id'"; + $db_results = Dba::write($sql); + + self::prune_tracks(); + + return true; } // delete @@ -516,17 +516,17 @@ class Democratic extends tmpPlaylist { * update * This updates an existing democratic playlist item. It takes a key'd array just like the create */ - public function update($data) { + public function update($data) { - $name = Dba::escape($data['name']); - $base = Dba::escape($data['democratic']); - $cool = Dba::escape($data['cooldown']); - $id = Dba::escape($this->id); + $name = Dba::escape($data['name']); + $base = Dba::escape($data['democratic']); + $cool = Dba::escape($data['cooldown']); + $id = Dba::escape($this->id); - $sql = "UPDATE `democratic` SET `name`='$name', `base_playlist`='$base',`cooldown`='$cool' WHERE `id`='$id'"; - $db_results = Dba::write($sql); + $sql = "UPDATE `democratic` SET `name`='$name', `base_playlist`='$base',`cooldown`='$cool' WHERE `id`='$id'"; + $db_results = Dba::write($sql); - return true; + return true; } // update @@ -534,26 +534,26 @@ class Democratic extends tmpPlaylist { * create * This is the democratic play create function it inserts this into the democratic table */ - public static function create($data) { + public static function create($data) { // Clean up the input - $name = Dba::escape($data['name']); - $base = Dba::escape($data['democratic']); - $cool = Dba::escape($data['cooldown']); - $level = Dba::escape($data['level']); - $default = Dba::escape($data['make_default']); - $user = Dba::escape($GLOBALS['user']->id); + $name = Dba::escape($data['name']); + $base = Dba::escape($data['democratic']); + $cool = Dba::escape($data['cooldown']); + $level = Dba::escape($data['level']); + $default = Dba::escape($data['make_default']); + $user = Dba::escape($GLOBALS['user']->id); - $sql = "INSERT INTO `democratic` (`name`,`base_playlist`,`cooldown`,`level`,`user`,`primary`) " . - "VALUES ('$name','$base','$cool','$level','$user','$default')"; - $db_results = Dba::write($sql); + $sql = "INSERT INTO `democratic` (`name`,`base_playlist`,`cooldown`,`level`,`user`,`primary`) " . + "VALUES ('$name','$base','$cool','$level','$user','$default')"; + $db_results = Dba::write($sql); - if ($db_results) { - $insert_id = Dba::insert_id(); - parent::create($insert_id,'vote','song'); - } + if ($db_results) { + $insert_id = Dba::insert_id(); + parent::create($insert_id,'vote','song'); + } - return $db_results; + return $db_results; } // create @@ -562,7 +562,7 @@ class Democratic extends tmpPlaylist { * This replaces the normal prune tracks and correctly removes the votes * as well */ - public static function prune_tracks() { + public static function prune_tracks() { // This deletes data without votes, if it's a voting democratic playlist $sql = "DELETE FROM `tmp_playlist_data` USING `tmp_playlist_data` " . @@ -578,7 +578,7 @@ class Democratic extends tmpPlaylist { /** * clear * This is really just a wrapper function, it clears the entire playlist - * including all votes etc. + * including all votes etc. */ public function clear() { @@ -594,7 +594,7 @@ class Democratic extends tmpPlaylist { self::prune_tracks(); // Clean the votes - self::clear_votes(); + self::clear_votes(); return true; @@ -604,14 +604,14 @@ class Democratic extends tmpPlaylist { * clean_votes * This removes in left over garbage in the votes table */ - public function clear_votes() { + public function clear_votes() { - $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`.`id` IS NULL"; - $db_results = Dba::write($sql); + $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`.`id` IS NULL"; + $db_results = Dba::write($sql); - return true; + return true; } // clear_votes @@ -621,9 +621,9 @@ class Democratic extends tmpPlaylist { */ public function get_vote($object_id) { - if (parent::is_cached('democratic_vote',$object_id)) { - return parent::get_from_cache('democratic_vote',$object_id); - } + if (parent::is_cached('democratic_vote',$object_id)) { + return parent::get_from_cache('democratic_vote',$object_id); + } $object_id = Dba::escape($object_id); @@ -642,9 +642,9 @@ class Democratic extends tmpPlaylist { * This returns the users that voted for the specified object * This is an array of user ids */ - public function get_voters($object_id) { + public function get_voters($object_id) { - return parent::get_from_cache('democratic_voters',$object_id); + return parent::get_from_cache('democratic_voters',$object_id); } // get_voters diff --git a/lib/class/error.class.php b/lib/class/error.class.php index 2da2a7d1..2ed4a034 100644 --- a/lib/class/error.class.php +++ b/lib/class/error.class.php @@ -16,7 +16,7 @@ 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, + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -26,7 +26,7 @@ * This is the baic error class, its better now that we can use php5 * hello static functions and variables */ -class Error { +class Error { private static $state = false; // set to one when an error occurs private static $errors = array(); // Errors array key'd array with errors that have occured @@ -35,62 +35,62 @@ class Error { * __constructor * This does nothing... amazing isn't it! */ - private function __construct() { + private function __construct() { // Rien a faire - + } // __construct /** * __destruct * This saves all of the errors that are left into the session */ - public function __destruct() { + public function __destruct() { - foreach (self::$errors as $key=>$error) { - $_SESSION['errors'][$key] = $error; - } + foreach (self::$errors as $key=>$error) { + $_SESSION['errors'][$key] = $error; + } } // __destruct /** * add - * This is a public static function it adds a new error message to the array + * This is a public static function it adds a new error message to the array * It can optionally clobber rather then adding to the error message */ - public static function add($name,$message,$clobber=0) { + public static function add($name,$message,$clobber=0) { - // Make sure its set first - if (!isset(Error::$errors[$name])) { - Error::$errors[$name] = $message; + // Make sure its set first + if (!isset(Error::$errors[$name])) { + Error::$errors[$name] = $message; Error::$state = 1; - $_SESSION['errors'][$key] = $message; - } + $_SESSION['errors'][$key] = $message; + } // They want us to clobber it - elseif ($clobber) { + elseif ($clobber) { Error::$state = 1; Error::$errors[$name] = $message; - $_SESSION['errors'][$key] = $message; - } + $_SESSION['errors'][$key] = $message; + } // They want us to append the error, add a BR\n and then the message - else { + else { Error::$state = 1; Error::$errors[$name] .= "
\n" . $message; - $_SESSION['errors'][$key] .= "
\n" . $message; - } + $_SESSION['errors'][$key] .= "
\n" . $message; + } } // add - /** + /** * occurred * This returns true / false if an error has occured anywhere */ - public static function occurred() { + public static function occurred() { - if (self::$state == '1') { return true; } + if (self::$state == '1') { return true; } - return false; + return false; } // occurred @@ -98,9 +98,9 @@ class Error { * get * This returns an error by name */ - public static function get($name) { + public static function get($name) { - if (!isset(Error::$errors[$name])) { return ''; } + if (!isset(Error::$errors[$name])) { return ''; } return Error::$errors[$name]; @@ -111,27 +111,27 @@ class Error { * This prints the error out with a standard Error class span * Ben Goska: Renamed from print to display, print is reserved */ - public static function display($name) { + public static function display($name) { // Be smart about this, if no error don't print - if (!isset(Error::$errors[$name])) { return ''; } + if (!isset(Error::$errors[$name])) { return ''; } echo '' . Error::$errors[$name] . ''; } // display /** - * auto_init + * auto_init * This loads the errors from the session back into Ampache */ - public static function auto_init() { + public static function auto_init() { - if (!is_array($_SESSION['errors'])) { return false; } + if (!is_array($_SESSION['errors'])) { return false; } - // Re-insert them - foreach ($_SESSION['errors'] as $key=>$error) { + // Re-insert them + foreach ($_SESSION['errors'] as $key=>$error) { self::add($key,$error); - } + } } // auto_init diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php index 8105a247..3394019d 100644 --- a/lib/class/flag.class.php +++ b/lib/class/flag.class.php @@ -17,17 +17,17 @@ 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. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** * Flag Class - * This handles flagging of songs, albums and artists + * This handles flagging of songs, albums and artists */ class Flag extends database_object { - public $id; + public $id; public $user; public $object_id; public $object_type; @@ -44,13 +44,13 @@ class Flag extends database_object { * Constructor * This takes a flagged.id and then pulls in the information for said flag entry */ - public function __construct($flag_id) { + public function __construct($flag_id) { $info = $this->get_info($flag_id,'flagged'); - - foreach ($info as $key=>$value) { - $this->$key = $value; - } + + foreach ($info as $key=>$value) { + $this->$key = $value; + } return true; @@ -61,18 +61,18 @@ class Flag extends database_object { * This takes an array of ids and builds up a nice little cache * for us */ - public static function build_cache($ids) { + public static function build_cache($ids) { - if (!is_array($ids) OR !count($ids)) { return false; } + if (!is_array($ids) OR !count($ids)) { return false; } - $idlist = '(' . implode(',',$ids) . ')'; + $idlist = '(' . implode(',',$ids) . ')'; - $sql = "SELECT * FROM `flagged` WHERE `id` IN $idlist"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `flagged` WHERE `id` IN $idlist"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('flagged',$row['id'],$row); - } + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('flagged',$row['id'],$row); + } } // build_cache @@ -81,27 +81,27 @@ class Flag extends database_object { * This takes an array of ids and builds a map cache to avoid some of the object_type calls * we would normally have to make */ - public static function build_map_cache($ids,$type) { + public static function build_map_cache($ids,$type) { - if (!is_array($ids) OR !count($ids)) { return false; } + if (!is_array($ids) OR !count($ids)) { return false; } - $idlist = '(' . implode(',',$ids) . ')'; - $type = Dba::escape($type); + $idlist = '(' . implode(',',$ids) . ')'; + $type = Dba::escape($type); - $sql = "SELECT * FROM `flagged` " . - "WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id` IN $idlist"; - $db_results = Dba::read($sql); - - while ($row = Dba::fetch_assoc($db_results)) { - $results[$row['object_id']] = $row; - } - - // Itterate through the passed ids as we need to cache 'nulls' - foreach ($ids as $id) { - parent::add_to_cache('flagged_' . $type,$id,$results[$id]); - } + $sql = "SELECT * FROM `flagged` " . + "WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id` IN $idlist"; + $db_results = Dba::read($sql); - return true; + while ($row = Dba::fetch_assoc($db_results)) { + $results[$row['object_id']] = $row; + } + + // Itterate through the passed ids as we need to cache 'nulls' + foreach ($ids as $id) { + parent::add_to_cache('flagged_' . $type,$id,$results[$id]); + } + + return true; } // build_map_cache @@ -109,23 +109,23 @@ class Flag extends database_object { * has_flag * Static function, tries to check the cache, but falls back on a query */ - public static function has_flag($id,$type) { + public static function has_flag($id,$type) { + + if (parent::is_cached('flagged_' . $type,$id)) { + $data = parent::get_from_cache('flagged_' . $type,$id); + return $data['date']; + } - if (parent::is_cached('flagged_' . $type,$id)) { - $data = parent::get_from_cache('flagged_' . $type,$id); - return $data['date']; - } - // Ok we have to query this - $type = Dba::escape($type); + $type = Dba::escape($type); - $sql = "SELECT * FROM `flagged` WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id`='$id'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `flagged` WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id`='$id'"; + $db_results = Dba::read($sql); $row = Dba::fetch_assoc($db_results); - parent::add_to_cache('flagged_' . $type,$row['object_id'],$row); + parent::add_to_cache('flagged_' . $type,$row['object_id'],$row); - return $row['date']; + return $row['date']; } // has_flag @@ -134,19 +134,19 @@ class Flag extends database_object { * This returns the id's of the most recently flagged songs, it takes an int * as an argument which is the count of the object you want to return */ - public static function get_recent($count=0) { + public static function get_recent($count=0) { - if ($count) { $limit = " LIMIT " . intval($count); } + if ($count) { $limit = " LIMIT " . intval($count); } $results = array(); $sql = "SELECT id FROM flagged ORDER BY date " . $limit; $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $results[] = $r['id']; } - + return $results; } // get_recent @@ -156,18 +156,18 @@ class Flag extends database_object { * This returns all of the songs that have been disabled, this is * a form of being flagged */ - public static function get_disabled() { + public static function get_disabled() { - $sql = "SELECT `id` FROM `song` WHERE `enabled`='0'"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `song` WHERE `enabled`='0'"; + $db_results = Dba::read($sql); - $results = array(); - - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['id']; - } + $results = array(); - return $results; + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } + + return $results; } // get_disabled @@ -176,10 +176,10 @@ class Flag extends database_object { * This returns an array of ids of flagged songs if no limit is passed * it gets everything */ - public static function get_all($count=0) { + public static function get_all($count=0) { + + if ($count) { $limit_clause = "LIMIT " . intval($count); } - if ($count) { $limit_clause = "LIMIT " . intval($count); } - $sql = "SELECT `id` FROM `flagged` $limit_clause"; $db_results = Dba::read($sql); @@ -187,7 +187,7 @@ class Flag extends database_object { $results = array(); /* While the query */ - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { $results[] = $row['id']; } @@ -199,17 +199,17 @@ class Flag extends database_object { * get_approved * This returns an array of approved flagged songs */ - public static function get_approved() { + public static function get_approved() { $sql = "SELECT `id` FROM `flagged` WHERE `approved`='1'"; - $db_results = Dba::read($sql); + $db_results = Dba::read($sql); /* Default the results array */ - $results = array(); + $results = array(); /* While it */ - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $results[] = $r['id']; } @@ -222,8 +222,8 @@ class Flag extends database_object { * 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 */ - public static function add($id,$type,$flag,$comment) { - + public static function add($id,$type,$flag,$comment) { + $id = Dba::escape($id); $type = Dba::escape($type); $flag = self::validate_flag($flag); @@ -233,9 +233,9 @@ class Flag extends database_object { $approved = '0'; /* If they are an content manager or higher, it's auto approved */ - if (Access::check('interface','75')) { $approved = '1'; } + if (Access::check('interface','75')) { $approved = '1'; } - $sql = "INSERT INTO `flagged` (`object_id`,`object_type`,`flag`,`comment`,`date`,`approved`,`user`) VALUES " . + $sql = "INSERT INTO `flagged` (`object_id`,`object_type`,`flag`,`comment`,`date`,`approved`,`user`) VALUES " . " ('$id','$type','$flag','$comment','$time','$approved','$user')"; $db_results = Dba::write($sql); @@ -249,18 +249,18 @@ class Flag extends database_object { * state, in a perfect world, I could just roll the changes back... not until 3.4 * or.. haha 3.5! */ - public function delete() { + public function delete() { // Re-scan the file - $song = new Song($this->object_id); - $info = Catalog::update_media_from_tags($song); + $song = new Song($this->object_id); + $info = Catalog::update_media_from_tags($song); // Delete the row $sql = "DELETE FROM `flagged` WHERE `id`='$this->id'"; $db_results = Dba::write($sql); - // Reset the Last-Updated date so that it'll get re-scaned - $song->update_utime($song->id,1); + // Reset the Last-Updated date so that it'll get re-scaned + $song->update_utime($song->id,1); return true; @@ -271,44 +271,44 @@ class Flag extends database_object { * This approves the current flag object ($this->id) by setting approved to * 1 */ - public function approve() { + public function approve() { $sql = "UPDATE `flagged` SET `approved`='1' WHERE `id`='$this->id'"; $db_results = Dba::write($sql); - $this->approved = 1; + $this->approved = 1; return true; - + } // approve - + /** * format * This function figures out what kind of object we've got and sets up all the * vars all nice and fuzzy like */ - public function format() { + public function format() { - switch ($this->object_type) { - case 'song': + switch ($this->object_type) { + case 'song': $song = new Song($this->object_id); - $song->format(); + $song->format(); $this->f_name = $song->f_link; break; - } // end switch on type + } // end switch on type $client = new User($this->user); - $client->format(); - $this->f_user = $client->f_link; + $client->format(); + $this->f_user = $client->f_link; } // format - + /** * print_status * This prints out a userfriendly version of the current status for this flagged * object */ - public function print_status() { + public function print_status() { if ($this->approved) { echo _('Approved'); } else { echo _('Pending'); } @@ -319,20 +319,20 @@ class Flag extends database_object { * print_flag * This prints out a userfriendly version of the current flag type */ - public function print_flag() { + public function print_flag() { - switch ($this->flag) { + switch ($this->flag) { case 'delete': $name = _('Delete'); break; case 'retag': - $name = _('Re-Tag'); + $name = _('Re-Tag'); break; case 'reencode': $name = _('Re-encode'); break; case 'other': - $name = _('Other'); + $name = _('Other'); break; default: $name = _('Unknown'); @@ -340,7 +340,7 @@ class Flag extends database_object { } // end switch echo $name; - + } // print_flag /** @@ -348,17 +348,17 @@ class Flag extends database_object { * This takes a flag input and makes sure it's one of the reigstered * and valid 'flag' values */ - public static function validate_flag($flag) { + public static function validate_flag($flag) { - switch ($flag) { - case 'delete': - case 'retag': - case 'reencode': - case 'other': - return $flag; + switch ($flag) { + case 'delete': + case 'retag': + case 'reencode': + case 'other': + return $flag; break; - default: - return 'other'; + default: + return 'other'; break; } // end switch @@ -366,14 +366,14 @@ class Flag extends database_object { /** * fill_tags - * This is used by the write_tags script. + * This is used by the write_tags script. */ public static function fill_tags( $tagWriter, $song, $type = 'comment' ) { // Set all of the attributes for the tag to be written(All pulled from the song object) // Use a function since ID3v1, ID3v2, and vorbis/flac/ape are different - switch ($type) { - case 'comment': + switch ($type) { + case 'comment': $tagWriter->comments['title'] = $song->title; $tagWriter->comments['date'] = $song->year; $tagWriter->comments['year'] = $song->year; @@ -384,7 +384,7 @@ class Flag extends database_object { $tagWriter->comments['artist'] = $song->get_artist_name(); $tagWriter->comments['genre'] = $song->get_genre_name(); $tagWriter->comments['track'] = $song->track; - break; + break; case 'id3v1': $tagWriter->title = $song->title; $tagWriter->year = $song->year; diff --git a/lib/class/localplay.abstract.php b/lib/class/localplay.abstract.php index 6cc3d078..c544c14c 100644 --- a/lib/class/localplay.abstract.php +++ b/lib/class/localplay.abstract.php @@ -23,85 +23,85 @@ /* * This is the abstract class for any localplay controller */ -abstract class localplay_controller { - +abstract class localplay_controller { + // Required Functions abstract public function add($objects); // Takes an array of song_ids abstract public function delete_track($object_id); // Takes a single object_id and removes it from the playlist - abstract public function play(); - abstract public function stop(); - abstract public function get(); - abstract public function connect(); - abstract public function status(); + abstract public function play(); + abstract public function stop(); + abstract public function get(); + abstract public function connect(); + abstract public function status(); abstract public function get_version(); // Returns the version of this plugin - abstract public function get_description(); // Returns the description - abstract public function is_installed(); // Returns an boolean t/f - abstract public function install(); - abstract public function uninstall(); + abstract public function get_description(); // Returns the description + abstract public function is_installed(); // Returns an boolean t/f + abstract public function install(); + abstract public function uninstall(); // For display we need the following 'instance' functions - abstract public function add_instance($data); - abstract public function delete_instance($id); - abstract public function update_instance($id,$post); - abstract public function get_instances(); + abstract public function add_instance($data); + abstract public function delete_instance($id); + abstract public function update_instance($id,$post); + abstract public function get_instances(); abstract public function instance_fields(); - abstract public function set_active_instance($uid); - abstract public function get_active_instance(); + abstract public function set_active_instance($uid); + abstract public function get_active_instance(); /** * get_url * This returns the URL for the passed object */ - public function get_url($object) { + public function get_url($object) { // This might not be an object! - if (!is_object($object)) { + if (!is_object($object)) { // Stupiidly we'll just blindly add it for now - return $object; - } + return $object; + } - $class = get_class($object); - - $url = call_user_func(array($class,'play_url'),$object->id); + $class = get_class($object); + + $url = call_user_func(array($class,'play_url'),$object->id); return $url; - } // get_url + } // get_url /** * get_file * This returns the Filename for the passed object, not * always possible */ - public function get_file($object) { + public function get_file($object) { - } // get_file + } // get_file /** - * parse_url + * parse_url * This takes an Ampache URL and then returns the 'primary' part of it * So that it's easier for localplay modules to return valid song information */ - public function parse_url($url) { + public function parse_url($url) { // Define possible 'primary' keys - $primary_array = array('oid','demo_id','random'); - $data = array(); + $primary_array = array('oid','demo_id','random'); + $data = array(); - $variables = parse_url($url,PHP_URL_QUERY); - parse_str($variables,$data); + $variables = parse_url($url,PHP_URL_QUERY); + parse_str($variables,$data); - foreach ($primary_array as $pkey) { - if ($data[$pkey]) { - $data['primary_key'] = $pkey; - return $data; + foreach ($primary_array as $pkey) { + if ($data[$pkey]) { + $data['primary_key'] = $pkey; + return $data; } } // end foreach return $data; - } // parse_url + } // parse_url } // end localplay_controller interface diff --git a/lib/class/localplay.class.php b/lib/class/localplay.class.php index 186bea7e..26b39aba 100644 --- a/lib/class/localplay.class.php +++ b/lib/class/localplay.class.php @@ -26,10 +26,10 @@ class Localplay { public $type; /* Built Variables */ - private $_function_map = array(); + private $_function_map = array(); private $_template; private $_preferences = array(); - private $_player; + private $_player; /** * Constructor @@ -37,7 +37,7 @@ class Localplay { * file for the specified type and attempts to load in the function * map, the preferences and the template */ - public function __construct($type) { + public function __construct($type) { $this->type = $type; @@ -47,12 +47,12 @@ class Localplay { /** * _get_info - * This functions takes the type and attempts to get all the + * This functions takes the type and attempts to get all the * information needed to load it. Will log errors if there are * any failures, fatal errors will actually return something to the * gui */ - private function _get_info() { + private function _get_info() { $this->_load_player(); @@ -63,29 +63,29 @@ class Localplay { * This returns true / false if the player load * failed / worked */ - public function player_loaded() { + public function player_loaded() { - if (is_object($this->_player)) { - return true; - } - else { - return false; - } + if (is_object($this->_player)) { + return true; + } + else { + return false; + } } // player_loaded /** * format - * This makes the localplay/plugin information - * human readable + * This makes the localplay/plugin information + * human readable */ - public function format() { + public function format() { - if (!is_object($this->_player)) { return false; } + if (!is_object($this->_player)) { return false; } - $this->f_name = ucfirst($this->type); - $this->f_description = $this->_player->get_description(); - $this->f_version = $this->_player->get_version(); + $this->f_name = ucfirst($this->type); + $this->f_description = $this->_player->get_description(); + $this->f_version = $this->_player->get_version(); } // format @@ -96,40 +96,40 @@ class Localplay { * Will interface with in order to make all this magical stuf work * all LocalPlay modules should be located in /modules//.class.php */ - private function _load_player() { + private function _load_player() { - if (!$this->type) { return false; } + if (!$this->type) { return false; } $filename = Config::get('prefix') . '/modules/localplay/' . $this->type . '.controller.php'; $include = require_once ($filename); - - if (!$include) { + + if (!$include) { /* Throw Error Here */ debug_event('localplay','Unable to load ' . $this->type . ' controller','2'); - return false; + return false; } // include - else { + else { $class_name = "Ampache" . $this->type; $this->_player = new $class_name(); - if (!($this->_player instanceof localplay_controller)) { - debug_event('Localplay',$this->type . ' not an instance of controller abstract, unable to load','1'); - unset($this->_player); - return false; - } + if (!($this->_player instanceof localplay_controller)) { + debug_event('Localplay',$this->type . ' not an instance of controller abstract, unable to load','1'); + unset($this->_player); + return false; + } } - + } // _load_player /** * format_name - * This function takes the track name and checks to see if 'skip' + * This function takes the track name and checks to see if 'skip' * is supported in the current player, if so it returns a 'skip to' * link, otherwise it returns just the text */ - public function format_name($name,$id) { + public function format_name($name,$id) { $name = scrub_out($name); - $name = Ajax::text('?page=localplay&action=command&command=skip&id=' . $id,$name,'localplay_skip_' . $id); + $name = Ajax::text('?page=localplay&action=command&command=skip&id=' . $id,$name,'localplay_skip_' . $id); return $name; } // format_name @@ -138,31 +138,31 @@ class Localplay { * get_controllers * This returns the controllers that are currently loaded into this instance */ - public static function get_controllers() { + public static function get_controllers() { /* First open the dir */ - $handle = opendir(Config::get('prefix') . '/modules/localplay'); - - if (!is_resource($handle)) { - debug_event('Localplay','Error: Unable to read localplay controller directory','1'); - return array(); + $handle = opendir(Config::get('prefix') . '/modules/localplay'); + + if (!is_resource($handle)) { + debug_event('Localplay','Error: Unable to read localplay controller directory','1'); + return array(); } - $results = array(); + $results = array(); - while ($file = readdir($handle)) { + while ($file = readdir($handle)) { - if (substr($file,-14,14) != 'controller.php') { continue; } + if (substr($file,-14,14) != 'controller.php') { continue; } /* Make sure it isn't a dir */ - if (!is_dir($file)) { + if (!is_dir($file)) { /* Get the basename and then everything before controller */ - $filename = basename($file,'.controller.php'); - $results[] = $filename; - } + $filename = basename($file,'.controller.php'); + $results[] = $filename; + } } // end while - return $results; + return $results; } // get_controllers @@ -171,14 +171,14 @@ class Localplay { * This returns true or false depending on if the specified controller * is currently enabled */ - public static function is_enabled($controller) { + public static function is_enabled($controller) { // Load the controller and then check for its preferences - $localplay = new Localplay($controller); - // If we can't even load it no sense in going on - if (!isset($localplay->_player)) { return false; } + $localplay = new Localplay($controller); + // If we can't even load it no sense in going on + if (!isset($localplay->_player)) { return false; } - return $localplay->_player->is_installed(); + return $localplay->_player->is_installed(); } // is_enabled @@ -187,48 +187,48 @@ class Localplay { * This runs the install for the localplay controller we've * currently got pimped out */ - public function install() { + public function install() { // Run the player's installer - $installed = $this->_player->install(); - - return $installed; + $installed = $this->_player->install(); + + return $installed; } // install /** * uninstall - * This runs the uninstall for the localplay controller we've + * This runs the uninstall for the localplay controller we've * currently pimped out */ - public function uninstall() { + public function uninstall() { // Run the players uninstaller - $this->_player->uninstall(); + $this->_player->uninstall(); // If its our current player, reset player to nothing - if (Config::get('localplay_controller') == $this->type) { - Preference::update('localplay_controller',$GLOBALS['user']->id,''); - } + if (Config::get('localplay_controller') == $this->type) { + Preference::update('localplay_controller',$GLOBALS['user']->id,''); + } - return true; + return true; } // uninstall /** * connect - * This function attempts to connect to the localplay + * This function attempts to connect to the localplay * player that we are using */ - public function connect() { + public function connect() { - if (!$this->_player->connect()) { + if (!$this->_player->connect()) { debug_event('localplay','Error Unable to connect, check ' . $this->type . ' controller','1'); return false; } return true; - + } // connect /** @@ -236,13 +236,13 @@ class Localplay { * This function passes NULL and calls the play function of the player * object */ - public function play() { - - if (!$this->_player->play()) { + public function play() { + + if (!$this->_player->play()) { debug_event('localplay','Error Unable to start playback, check ' . $this->type . ' controller','1'); return false; } - + return true; } // play @@ -252,9 +252,9 @@ class Localplay { * This functions passes NULl and calls the stop function of the player * object, it should recieve a true/false boolean value */ - public function stop() { + public function stop() { - if (!$this->_player->stop()) { + if (!$this->_player->stop()) { debug_event('localplay','Error Unable to stop playback, check ' . $this->type . ' controller','1'); return false; } @@ -266,48 +266,48 @@ class Localplay { /** * add * This function takes a single object and then passes it to - * to the player, this is a required function. + * to the player, this is a required function. */ - public function add($object) { + public function add($object) { - if (!$this->_player->add($object)) { + if (!$this->_player->add($object)) { debug_event('localplay','Error Unable to add songs, check ' . $this->type . ' controller','1'); return false; } - + return true; } // add /** - * add_url + * add_url * This directly adds an array of URLs to the localplay module. This is really how I should * have done add, will migrate to this eventually */ - public function add_url($urls) { + public function add_url($urls) { $function = $this->_function_map['add_url']; - - if (!$this->_player->$function($urls)) { + + if (!$this->_player->$function($urls)) { debug_event('localplay','Error Unable to add urls, check ' . $this->type . ' controller','1'); - return false; - } + return false; + } - return true; + return true; } // add_url /** * repeat - * This turns the repeat feature of a localplay method on or + * This turns the repeat feature of a localplay method on or * off, takes a 0/1 value */ - public function repeat($state) { + public function repeat($state) { $data = $this->_player->repeat($state); - if (!$data) { + if (!$data) { debug_event('localplay',"Error Unable to set Repeat to $state",'1'); } @@ -318,16 +318,16 @@ class Localplay { /** * random * This turns on the random feature of a localplay method - * It takes a 0/1 value + * It takes a 0/1 value */ - public function random($state) { - - $data = $this->_player->random($state); + public function random($state) { - if (!$data) { + $data = $this->_player->random($state); + + if (!$data) { debug_event('localplay',"Error Unable to set Random to $state",'1'); } - + return $data; } // random @@ -337,11 +337,11 @@ class Localplay { * This returns current information about the state of the player * There is an expected array format */ - public function status() { + public function status() { $data = $this->_player->status(); - if (!count($data)) { + if (!count($data)) { debug_event('localplay','Error Unable to get status, check ' . $this->type . ' controller','1'); return false; } @@ -356,15 +356,15 @@ class Localplay { * the array of current songs for display or whatever * an empty array is passed on failure */ - public function get() { + public function get() { $data = $this->_player->get(); - - if (!count($data) OR !is_array($data)) { + + if (!count($data) OR !is_array($data)) { debug_event('localplay','Error Unable to get song info, check ' . $this->type . ' controller','1'); - return array(); + return array(); } - + return $data; } // get @@ -372,18 +372,18 @@ class Localplay { /** * volume_set * This isn't a required function, it sets the volume to a specified value - * as passed in the variable it is a 0 - 100 scale the controller is + * as passed in the variable it is a 0 - 100 scale the controller is * responsible for adjusting the scale if nessecary */ - public function volume_set($value) { - + public function volume_set($value) { + /* Make sure it's int and 0 - 100 */ $value = int($value); /* Make sure that it's between 0 and 100 */ if ($value > 100 OR $value < 0) { return false; } - if (!$this->_player->volume($value)) { + if (!$this->_player->volume($value)) { debug_event('localplay','Error: Unable to set volume, check ' . $this->type . ' controller','1'); return false; } @@ -397,11 +397,11 @@ class Localplay { * This function isn't required. It tells the daemon to increase the volume * by a pre-defined amount controlled by the controller */ - public function volume_up() { + public function volume_up() { - if (!$this->_player->volume_up()) { + if (!$this->_player->volume_up()) { debug_event('localplay','Error: Unable to increase volume, check ' . $this->type . ' controller','1'); - return false; + return false; } return true; @@ -413,12 +413,12 @@ class Localplay { * This function isn't required. It tells the daemon to decrese the volume * by a pre-defined amount controlled by the controller. */ - public function volume_down() { + public function volume_down() { - if (!$this->_player->volume_down()) { + if (!$this->_player->volume_down()) { debug_event('localplay','Error: Unable to decrese volume, check ' . $this->type . ' controller','1'); - return false; - } + return false; + } return true; @@ -429,14 +429,14 @@ class Localplay { * This function isn't required, It tells the daemon to mute all output * It's up to the controller to decide what that actually entails */ - public function volume_mute() { + public function volume_mute() { - if (!$this->_player->volume(0)){ + if (!$this->_player->volume(0)){ debug_event('localplay','Error: Unable to mute volume, check ' . $this->type . ' controller','1'); - return false; + return false; } - return true; + return true; } // volume_mute @@ -444,11 +444,11 @@ class Localplay { * skip * This isn't a required function, it tells the daemon to skip to the specified song */ - public function skip($track_id) { + public function skip($track_id) { - if (!$this->_player->skip($track_id)) { + if (!$this->_player->skip($track_id)) { debug_event('localplay','Error: Unable to skip to next song, check ' . $this->type . ' controller','1'); - return false; + return false; } return true; @@ -457,14 +457,14 @@ class Localplay { /** * next - * This isn't a required function, it tells the daemon to go to the next + * This isn't a required function, it tells the daemon to go to the next * song */ - public function next() { + public function next() { - if (!$this->_player->next()) { + if (!$this->_player->next()) { debug_event('localplay','Error: Unable to skip to next song, check ' . $this->type . ' controller','1'); - return false; + return false; } return true; @@ -476,10 +476,10 @@ class Localplay { * This isn't a required function, it tells the daemon to go the the previous * song */ - public function prev() { - + public function prev() { - if (!$this->_player->prev()) { + + if (!$this->_player->prev()) { debug_event('localplay','Error: Unable to skip to previous song, check ' . $this->type . ' controller','1'); return false; } @@ -508,11 +508,11 @@ class Localplay { * get_instances * This returns the instances of the current type */ - public function get_instances() { + public function get_instances() { - $instances = $this->_player->get_instances(); + $instances = $this->_player->get_instances(); - return $instances; + return $instances; } // get_instances @@ -520,11 +520,11 @@ class Localplay { * current_instance * This returns the UID of the current Instance */ - public function current_instance() { + public function current_instance() { - $data = $this->_player->get_instance(); + $data = $this->_player->get_instance(); - return $data['id']; + return $data['id']; } // current_instance @@ -532,11 +532,11 @@ class Localplay { * get_instance * This returns the specified instance */ - public function get_instance($uid) { + public function get_instance($uid) { - $data = $this->_player->get_instance($uid); - - return $data; + $data = $this->_player->get_instance($uid); + + return $data; } // get_instance @@ -544,11 +544,11 @@ class Localplay { * update_instance * This updates the specified instance with a named array of data (_POST most likely) */ - public function update_instance($uid,$data) { + public function update_instance($uid,$data) { - $data = $this->_player->update_instance($uid,$data); + $data = $this->_player->update_instance($uid,$data); - return $data; + return $data; } // update_instance @@ -556,9 +556,9 @@ class Localplay { * add_instance * This adds a new instance for the current controller type */ - public function add_instance($data) { + public function add_instance($data) { - $this->_player->add_instance($data); + $this->_player->add_instance($data); } // add_instance @@ -566,9 +566,9 @@ class Localplay { * delete_instance * This removes an instance (it actually calls the players function) */ - public function delete_instance($instance_uid) { + public function delete_instance($instance_uid) { - $this->_player->delete_instance($instance_uid); + $this->_player->delete_instance($instance_uid); } // delete_instance @@ -576,9 +576,9 @@ class Localplay { * set_active_instance * This sets the active instance of the localplay controller */ - public function set_active_instance($instance) { + public function set_active_instance($instance) { - $this->_player->set_active_instance($instance); + $this->_player->set_active_instance($instance); } // set_active_instance @@ -587,9 +587,9 @@ class Localplay { * This removes songs from the players playlist it takes a single ID as provided * by the get command */ - public function delete_track($object_id) { + public function delete_track($object_id) { - if (!$this->_player->delete_track($object_id)) { + if (!$this->_player->delete_track($object_id)) { debug_event('localplay','Error: Unable to remove songs, check ' . $this->type . ' controller','1'); return false; } @@ -604,11 +604,11 @@ class Localplay { * This removes every song from the players playlist as defined by the delete_all function * map */ - public function delete_all() { + public function delete_all() { - if (!$this->_player->clear_playlist()) { + if (!$this->_player->clear_playlist()) { debug_event('localplay','Error: Unable to delete entire playlist, check ' . $this->type . ' controller','1'); - return false; + return false; } return true; @@ -617,12 +617,12 @@ class Localplay { /** * get_instance_fields - * This loads the fields from the localplay - * player and returns them + * This loads the fields from the localplay + * player and returns them */ - public function get_instance_fields() { + public function get_instance_fields() { - $fields = $this->_player->instance_fields(); + $fields = $this->_player->instance_fields(); return $fields; @@ -633,9 +633,9 @@ class Localplay { * This function returns a user friendly version * of the current player state */ - public function get_user_state($state) { - - switch ($state) { + public function get_user_state($state) { + + switch ($state) { case 'play': return _('Now Playing'); break; @@ -648,7 +648,7 @@ class Localplay { default: return _('Unknown'); break; - } // switch on state + } // switch on state } // get_user_state @@ -657,10 +657,10 @@ class Localplay { * This attempts to return a nice user friendly * currently playing string */ - public function get_user_playing() { + public function get_user_playing() { $status = $this->status(); - + /* Format the track name */ $track_name = $status['track_artist'] . ' - ' . $status['track_album'] . ' - ' . $status['track_title']; @@ -672,7 +672,7 @@ class Localplay { $track_name = "[" . $status['track'] . "] - " . $track_name; return $track_name; - + } // get_user_playing diff --git a/lib/class/media.interface.php b/lib/class/media.interface.php index 14bfd4f4..60d01967 100644 --- a/lib/class/media.interface.php +++ b/lib/class/media.interface.php @@ -25,13 +25,13 @@ * work, this lists all required functions and the expected * input */ -interface media { +interface media { - public function format(); - public function native_stream(); - public static function play_url($oid); - public function stream_cmd(); - public function has_flag(); + public function format(); + public function native_stream(); + public static function play_url($oid); + public function stream_cmd(); + public function has_flag(); } // end interface diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php index 8c4eb7f9..042716b2 100644 --- a/lib/class/playlist.class.php +++ b/lib/class/playlist.class.php @@ -24,50 +24,50 @@ * Playlist Class * This class handles playlists in ampache. it references the playlist* tables */ -class Playlist extends database_object { +class Playlist extends database_object { /* Variables from the Datbase */ public $id; public $name; public $user; public $type; - public $genre; + public $genre; public $date; /* Generated Elements */ public $items = array(); /** - * Constructor + * 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 + * if not playlist_id is passed returns false (or if it isn't found */ - public function __construct($id) { + public function __construct($id) { $info = $this->get_info($id); - foreach ($info as $key=>$value) { - $this->$key = $value; - } - + foreach ($info as $key=>$value) { + $this->$key = $value; + } + } // Playlist /** * build_cache * This is what builds the cache from the objects */ - public static function build_cache($ids) { - - if (!count($ids)) { return false; } + public static function build_cache($ids) { - $idlist = '(' . implode(',',$ids) . ')'; + if (!count($ids)) { return false; } - $sql = "SELECT * FROM `playlist` WHERE `id` IN $idlist"; - $db_results = Dba::read($sql); + $idlist = '(' . implode(',',$ids) . ')'; - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('playlist',$row['id'],$row); - } + $sql = "SELECT * FROM `playlist` WHERE `id` IN $idlist"; + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('playlist',$row['id'],$row); + } } // build_cache @@ -76,16 +76,16 @@ class Playlist extends database_object { * This takes the current playlist object and gussies it up a little * bit so it is presentable to the users */ - public function format() { + public function format() { $this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipse_threshold_title')); - $this->f_link = '' . $this->f_name . ''; + $this->f_link = '' . $this->f_name . ''; - $this->f_type = ($this->type == 'private') ? get_user_icon('lock',_('Private')) : ''; + $this->f_type = ($this->type == 'private') ? get_user_icon('lock',_('Private')) : ''; - $client = new User($this->user); + $client = new User($this->user); - $this->f_user = $client->fullname; + $this->f_user = $client->fullname; } // format @@ -94,19 +94,19 @@ class Playlist extends database_object { * This function returns true or false if the current user * has access to this playlist */ - public function has_access() { + public function has_access() { - if (!Access::check('interface','25')) { - return false; - } - if ($this->user == $GLOBALS['user']->id) { - return true; - } + if (!Access::check('interface','25')) { + return false; + } + if ($this->user == $GLOBALS['user']->id) { + return true; + } else { - return Access::check('interface','100'); - } + return Access::check('interface','100'); + } - return false; + return false; } // has_access @@ -115,17 +115,17 @@ class Playlist extends database_object { * Returns the single item on the playlist and all of it's information, restrict * it to this Playlist */ - public function get_track($track_id) { + public function get_track($track_id) { - $track_id = Dba::escape($track_id); - $playlist_id = Dba::escape($this->id); + $track_id = Dba::escape($track_id); + $playlist_id = Dba::escape($this->id); $sql = "SELECT * FROM `playlist_data` WHERE `id`='$track_id' AND `playlist`='$playlist_id'"; $db_results = Dba::read($sql); $row = Dba::fetch_assoc($db_results); - return $row; + return $row; } // get_track @@ -134,15 +134,15 @@ class Playlist extends database_object { * This returns an array of playlist songs that are in this playlist. Because the same * song can be on the same playlist twice they are key'd by the uid from playlist_data */ - public function get_items() { + public function get_items() { - $results = array(); + $results = array(); $sql = "SELECT `id`,`object_id`,`object_type`,`track` FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`"; $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id'],'track'=>$row['track'],'track_id'=>$row['id']); + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id'],'track'=>$row['track'],'track_id'=>$row['id']); } // end while return $results; @@ -153,17 +153,17 @@ class Playlist extends database_object { * get_random_items * This is the same as before but we randomize the buggers! */ - public function get_random_items($limit='') { + public function get_random_items($limit='') { - $results = array(); + $results = array(); - $limit_sql = $limit ? 'LIMIT ' . intval($limit) : ''; + $limit_sql = $limit ? 'LIMIT ' . intval($limit) : ''; - $sql = "SELECT `object_id`,`object_type` FROM `playlist_data` " . - "WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY RAND() $limit_sql"; - $db_results = Dba::read($sql); + $sql = "SELECT `object_id`,`object_type` FROM `playlist_data` " . + "WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY RAND() $limit_sql"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { + while ($row = Dba::fetch_assoc($db_results)) { $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id']); } // end while @@ -177,21 +177,21 @@ class Playlist extends database_object { * This is called by the batch script, because we can't pass in Dynamic objects they pulled once and then their * target song.id is pushed into the array */ - function get_songs() { + function get_songs() { $results = array(); $sql = "SELECT * FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`"; $db_results = Dba::read($sql); - while ($r = Dba::fetch_assoc($db_results)) { - if ($r['dyn_song']) { + while ($r = Dba::fetch_assoc($db_results)) { + if ($r['dyn_song']) { $array = $this->get_dyn_songs($r['dyn_song']); $results = array_merge($array,$results); } - else { + else { $results[] = $r['object_id']; - } + } } // end while @@ -204,7 +204,7 @@ class Playlist extends database_object { * This simply returns a int of how many song elements exist in this playlist * For now let's consider a dyn_song a single entry */ - public function get_song_count() { + public function get_song_count() { $sql = "SELECT COUNT(`id`) FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "'"; $db_results = Dba::read($sql); @@ -220,19 +220,19 @@ class Playlist extends database_object { * This returns the specified users playlists as an array of * playlist ids */ - public static function get_users($user_id) { + public static function get_users($user_id) { - $user_id = Dba::escape($user_id); - $results = array(); + $user_id = Dba::escape($user_id); + $results = array(); - $sql = "SELECT `id` FROM `playlist` WHERE `user`='$user_id' ORDER BY `name`"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `playlist` WHERE `user`='$user_id' ORDER BY `name`"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['id']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } - return $results; + return $results; } // get_users @@ -240,24 +240,24 @@ class Playlist extends database_object { * update * This function takes a key'd array of data and runs updates */ - public function update($data) { + public function update($data) { - if ($data['name'] != $this->name) { - $this->update_name($data['name']); - } - if ($data['pl_type'] != $this->type) { - $this->update_type($data['pl_type']); - } + if ($data['name'] != $this->name) { + $this->update_name($data['name']); + } + if ($data['pl_type'] != $this->type) { + $this->update_type($data['pl_type']); + } } // update /** * update_type - * This updates the playlist type, it calls the generic update_item function + * This updates the playlist type, it calls the generic update_item function */ - private function update_type($new_type) { + private function update_type($new_type) { - if ($this->_update_item('type',$new_type,'50')) { + if ($this->_update_item('type',$new_type,'50')) { $this->type = $new_type; } @@ -267,9 +267,9 @@ class Playlist extends database_object { * update_name * This updates the playlist name, it calls the generic update_item function */ - private function update_name($new_name) { + private function update_name($new_name) { - if ($this->_update_item('name',$new_name,'50')) { + if ($this->_update_item('name',$new_name,'50')) { $this->name = $new_name; } @@ -279,10 +279,10 @@ class Playlist extends database_object { * _update_item * This is the generic update function, it does the escaping and error checking */ - private function _update_item($field,$value,$level) { + private function _update_item($field,$value,$level) { - if ($GLOBALS['user']->id != $this->user AND !Access::check('interface',$level)) { - return false; + if ($GLOBALS['user']->id != $this->user AND !Access::check('interface',$level)) { + return false; } $value = Dba::escape($value); @@ -298,14 +298,14 @@ class Playlist extends database_object { * update_track_number * This takes a playlist_data.id and a track (int) and updates the track value */ - public function update_track_number($track_id,$track) { + public function update_track_number($track_id,$track) { - $playlist_id = Dba::escape($this->id); - $track_id = Dba::escape($track_id); - $track = Dba::escape($track); + $playlist_id = Dba::escape($this->id); + $track_id = Dba::escape($track_id); + $track = Dba::escape($track); - $sql = "UPDATE `playlist_data` SET `track`='$track' WHERE `id`='$track_id' AND `playlist`='$playlist_id'"; - $db_results = Dba::write($sql); + $sql = "UPDATE `playlist_data` SET `track`='$track' WHERE `id`='$track_id' AND `playlist`='$playlist_id'"; + $db_results = Dba::write($sql); } // update_track_number @@ -315,10 +315,10 @@ class Playlist extends database_object { * if you want to add a dyn_song you need to use the one shot function * add_dyn_song */ - public function add_songs($song_ids=array(),$ordered=false) { + public function add_songs($song_ids=array(),$ordered=false) { /* We need to pull the current 'end' track and then use that to - * append, rather then integrate take end track # and add it to + * append, rather then integrate take end track # and add it to * $song->track add one to make sure it really is 'next' */ $sql = "SELECT `track` FROM `playlist_data` WHERE `playlist`='" . $this->id . "' ORDER BY `track` DESC LIMIT 1"; @@ -327,24 +327,24 @@ class Playlist extends database_object { $base_track = $data['track']; debug_event('add_songs', 'Track number: '.$base_track, '5'); - foreach ($song_ids as $song_id) { + foreach ($song_ids as $song_id) { /* We need the songs track */ $song = new Song($song_id); - + // Based on the ordered prop we use track + base or just $i++ - if (!$ordered) { + if (!$ordered) { $track = Dba::escape($song->track+$base_track); - } - else { - $i++; - $track = Dba::escape($base_track+$i); - } + } + else { + $i++; + $track = Dba::escape($base_track+$i); + } $id = Dba::escape($song->id); $pl_id = Dba::escape($this->id); /* Don't insert dead songs */ - if ($id) { - $sql = "INSERT INTO `playlist_data` (`playlist`,`object_id`,`object_type`,`track`) " . + if ($id) { + $sql = "INSERT INTO `playlist_data` (`playlist`,`object_id`,`object_type`,`track`) " . " VALUES ('$pl_id','$id','song','$track')"; $db_results = Dba::write($sql); } // if valid id @@ -358,14 +358,14 @@ class Playlist extends database_object { * This function creates an empty playlist, gives it a name and type * Assumes $GLOBALS['user']->id as the user */ - public static function create($name,$type) { + public static function create($name,$type) { $name = Dba::escape($name); $type = Dba::escape($type); $user = Dba::escape($GLOBALS['user']->id); $date = time(); - $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`date`) " . + $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`date`) " . " VALUES ('$name','$user','$type','$date')"; $db_results = Dba::write($sql); @@ -379,7 +379,7 @@ class Playlist extends database_object { * set_items * This calles the get_items function and sets it to $this->items which is an array in this object */ - function set_items() { + function set_items() { $this->items = $this->get_items(); @@ -391,7 +391,7 @@ class Playlist extends database_object { * and numbers them in a liner fashion, not allowing for * the same track # twice, this is an optional funcition */ - public function normalize_tracks() { + public function normalize_tracks() { /* First get all of the songs in order of their tracks */ $sql = "SELECT `id` FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track` ASC"; @@ -400,7 +400,7 @@ class Playlist extends database_object { $i = 1; $results = array(); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $new_data = array(); $new_data['id'] = $r['id']; $new_data['track'] = $i; @@ -408,8 +408,8 @@ class Playlist extends database_object { $i++; } // end while results - foreach($results as $data) { - $sql = "UPDATE `playlist_data` SET `track`='" . $data['track'] . "' WHERE" . + foreach($results as $data) { + $sql = "UPDATE `playlist_data` SET `track`='" . $data['track'] . "' WHERE" . " `id`='" . $data['id'] . "'"; $db_results = Dba::write($sql); } // foreach re-ordered results @@ -417,42 +417,42 @@ class Playlist extends database_object { return true; } // normalize_tracks - + /** * delete_track * this deletes a single track, you specify the playlist_data.id here */ - public function delete_track($id) { + public function delete_track($id) { - $this_id = Dba::escape($this->id); - $id = Dba::escape($id); - - $sql = "DELETE FROM `playlist_data` WHERE `playlist_data`.`playlist`='$this_id' AND `playlist_data`.`id`='$id' LIMIT 1"; - $db_results = Dba::write($sql); + $this_id = Dba::escape($this->id); + $id = Dba::escape($id); - return true; + $sql = "DELETE FROM `playlist_data` WHERE `playlist_data`.`playlist`='$this_id' AND `playlist_data`.`id`='$id' LIMIT 1"; + $db_results = Dba::write($sql); - } // delete_track + return true; + + } // delete_track /** * delete * This deletes the current playlist and all assoicated data */ - public function delete() { + public function delete() { + + $id = Dba::escape($this->id); - $id = Dba::escape($this->id); - $sql = "DELETE FROM `playlist_data` WHERE `playlist` = '$id'"; $db_results = Dba::write($sql); $sql = "DELETE FROM `playlist` WHERE `id`='$id'"; $db_results = Dba::write($sql); - $sql = "DELETE FROM `object_count` WHERE `object_type`='playlist' AND `object_id`='$id'"; - $db_results = Dba::write($sql); - + $sql = "DELETE FROM `object_count` WHERE `object_type`='playlist' AND `object_id`='$id'"; + $db_results = Dba::write($sql); + return true; - + } // delete } // class Playlist diff --git a/lib/class/plugin.class.php b/lib/class/plugin.class.php index 3e0d70a9..63eeb593 100644 --- a/lib/class/plugin.class.php +++ b/lib/class/plugin.class.php @@ -26,21 +26,21 @@ class Plugin { public $name; /* constructed objects */ - public $_plugin; + public $_plugin; /** * Constructor - * This constructor loads the Plugin config file which defines how to + * This constructor loads the Plugin config file which defines how to * install/uninstall the plugin from Ampache's database */ - public function __construct($name) { + public function __construct($name) { /* Load the plugin */ - if (!$this->_get_info($name)) { - return false; + if (!$this->_get_info($name)) { + return false; } - return true; + return true; } // Constructor @@ -50,20 +50,20 @@ class Plugin { * This actually loads the config file for the plugin the name of the * class contained within the config file must be Plugin[NAME OF FILE] */ - public function _get_info($name) { + public function _get_info($name) { /* Require the file we want */ require_once Config::get('prefix') . '/modules/plugins/' . $name . '.plugin.php'; $plugin_name = "Ampache$name"; - $this->_plugin = new $plugin_name(); + $this->_plugin = new $plugin_name(); - if (!$this->is_valid()) { - return false; + if (!$this->is_valid()) { + return false; } - return true; + return true; } // _get_info @@ -71,33 +71,33 @@ class Plugin { * get_plugins * This returns an array of plugin names */ - public static function get_plugins() { + public static function get_plugins() { - $results = array(); + $results = array(); // Open up the plugin dir - $handle = opendir(Config::get('prefix') . '/modules/plugins'); + $handle = opendir(Config::get('prefix') . '/modules/plugins'); - if (!is_resource($handle)) { - debug_event('Plugins','Unable to read plugins directory','1'); - } + if (!is_resource($handle)) { + debug_event('Plugins','Unable to read plugins directory','1'); + } // Recurse the directory - while ($file = readdir($handle)) { + while ($file = readdir($handle)) { // Ignore non-plugin files - if (substr($file,-10,10) != 'plugin.php') { continue; } - if (is_dir($file)) { continue; } + if (substr($file,-10,10) != 'plugin.php') { continue; } + if (is_dir($file)) { continue; } // It's a plugin record it - $plugin_name = basename($file,'.plugin.php'); - $results[$plugin_name] = $plugin_name; + $plugin_name = basename($file,'.plugin.php'); + $results[$plugin_name] = $plugin_name; } // end while // Little stupid but hey - ksort($results); + ksort($results); - return $results; + return $results; } // get_plugins @@ -108,41 +108,41 @@ class Plugin { * install & uninstall method and Ampache must be within the min/max * version specifications */ - function is_valid() { + function is_valid() { - /* Check the plugin to make sure it's got the needed vars */ - if (!strlen($this->_plugin->name)) { - return false; + /* Check the plugin to make sure it's got the needed vars */ + if (!strlen($this->_plugin->name)) { + return false; } - if (!strlen($this->_plugin->description)) { - return false; + if (!strlen($this->_plugin->description)) { + return false; + } + if (!strlen($this->_plugin->version)) { + return false; } - if (!strlen($this->_plugin->version)) { - return false; - } /* Make sure we've got the required methods */ - if (!method_exists($this->_plugin,'install')) { - return false; + if (!method_exists($this->_plugin,'install')) { + return false; } - if (!method_exists($this->_plugin,'uninstall')) { - return false; - } + if (!method_exists($this->_plugin,'uninstall')) { + return false; + } /* Make sure it's within the version confines */ - $db_version = $this->get_ampache_db_version(); + $db_version = $this->get_ampache_db_version(); - if ($db_version < $this->_plugin->min_ampache) { - return false; - } + if ($db_version < $this->_plugin->min_ampache) { + return false; + } - if ($db_version > $this->_plugin->max_ampache) { - return false; - } + if ($db_version > $this->_plugin->max_ampache) { + return false; + } /* We've passed all of the tests its good */ - return true; + return true; } // is_valid @@ -151,42 +151,42 @@ class Plugin { * This checks to see if the specified plugin is currently installed in the * database, it doesn't check the files for integrity */ - public static function is_installed($plugin_name) { + public static function is_installed($plugin_name) { - /* All we do is check the version */ - return self::get_plugin_version($plugin_name); + /* All we do is check the version */ + return self::get_plugin_version($plugin_name); } // is_installed /** * install - * This runs the install function of the plugin (must be called install) + * This runs the install function of the plugin (must be called install) * at the end it inserts a row into the update_info table to indicate * That it's installed */ - public function install() { + public function install() { - $installed = $this->_plugin->install(); + $installed = $this->_plugin->install(); - $version = $this->set_plugin_version($this->_plugin->version); + $version = $this->set_plugin_version($this->_plugin->version); - if (!$installed OR !$version) { return false; } + if (!$installed OR !$version) { return false; } - return true; + return true; } // install - /** + /** * uninstall - * This runs the uninstall function of the plugin (must be called uninstall) + * This runs the uninstall function of the plugin (must be called uninstall) * at the end it removes the row from the update_info table to indicate * that it isn't installed */ - public function uninstall() { + public function uninstall() { - $this->_plugin->uninstall(); + $this->_plugin->uninstall(); - $this->remove_plugin_version(); + $this->remove_plugin_version(); } // uninstall @@ -194,15 +194,15 @@ class Plugin { * get_plugin_version * This returns the version of the specified plugin */ - public static function get_plugin_version($plugin_name) { + public static function get_plugin_version($plugin_name) { - $name = Dba::escape('Plugin_' . $plugin_name); + $name = Dba::escape('Plugin_' . $plugin_name); - $sql = "SELECT * FROM `update_info` WHERE `key`='$name'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `update_info` WHERE `key`='$name'"; + $db_results = Dba::read($sql); + + $results = Dba::fetch_assoc($db_results); - $results = Dba::fetch_assoc($db_results); - return $results['value']; } // get_plugin_version @@ -211,12 +211,12 @@ class Plugin { * get_ampache_db_version * This function returns the Ampache database version */ - function get_ampache_db_version() { + function get_ampache_db_version() { - $sql = "SELECT * FROM `update_info` WHERE `key`='db_version'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `update_info` WHERE `key`='db_version'"; + $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); return $results['value']; @@ -226,15 +226,15 @@ class Plugin { * set_plugin_version * This sets the plugin version in the update_info table */ - public function set_plugin_version($version) { + public function set_plugin_version($version) { $name = Dba::escape('Plugin_' . $this->_plugin->name); $version = Dba::escape($version); $sql = "INSERT INTO `update_info` SET `key`='$name', `value`='$version'"; - $db_results = Dba::read($sql); + $db_results = Dba::read($sql); - return true; + return true; } // set_plugin_version @@ -242,14 +242,14 @@ class Plugin { * 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'"; - $db_results = Dba::read($sql); + public function remove_plugin_version() { - return true; + $name = Dba::escape('Plugin_' . $this->_plugin->name); + + $sql = "DELETE FROM `update_info` WHERE `key`='$name'"; + $db_results = Dba::read($sql); + + return true; } // remove_plugin_version diff --git a/lib/class/preference.class.php b/lib/class/preference.class.php index 766859ea..528e6de9 100644 --- a/lib/class/preference.class.php +++ b/lib/class/preference.class.php @@ -1,7 +1,7 @@ username . ' attempted to update ' . $name . ' but does not have sufficient permissions','3'); } - return false; + // Now do + if (self::has_access($name)) { + $value = Dba::escape($value); + $user_id = Dba::escape($user_id); + $sql = "UPDATE `user_preference` SET `value`='$value' " . + "WHERE `preference`='$id'$user_check"; + $db_results = Dba::write($sql); + Preference::clear_from_session(); + return true; + } + else { + debug_event('denied',$GLOBALS['user']->username . ' attempted to update ' . $name . ' but does not have sufficient permissions','3'); + } + + return false; } // update /** * update_level * This takes a preference ID and updates the level required to update it (performed by an admin) */ - public static function update_level($preference,$level) { + public static function update_level($preference,$level) { // First prepare - if (!is_numeric($preference)) { + if (!is_numeric($preference)) { $preference_id = self::id_from_name($preference); - } - else { + } + else { $preference_id = $preference; - } + } $preference_id = Dba::escape($preference_id); - $level = Dba::escape($level); + $level = Dba::escape($level); - $sql = "UPDATE `preference` SET `level`='$level' WHERE `id`='$preference_id'"; - $db_results = Dba::write($sql); + $sql = "UPDATE `preference` SET `level`='$level' WHERE `id`='$preference_id'"; + $db_results = Dba::write($sql); - return true; + return true; } // update_level @@ -105,15 +105,15 @@ class Preference { * update_all * This takes a preference id and a value and updates all users with the new info */ - public static function update_all($preference_id,$value) { + public static function update_all($preference_id,$value) { $preference_id = Dba::escape($preference_id); - $value = Dba::escape($value); + $value = Dba::escape($value); - $sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$preference_id'"; - $db_results = Dba::write($sql); + $sql = "UPDATE `user_preference` SET `value`='$value' WHERE `preference`='$preference_id'"; + $db_results = Dba::write($sql); - return true; + return true; } // update_all @@ -121,14 +121,14 @@ class Preference { * exists * This just checks to see if a preference currently exists */ - public static function exists($preference) { + public static function exists($preference) { // We assume it's the name - $name = Dba::escape($preference); - $sql = "SELECT * FROM `preference` WHERE `name`='$name'"; - $db_results = Dba::read($sql); + $name = Dba::escape($preference); + $sql = "SELECT * FROM `preference` WHERE `name`='$name'"; + $db_results = Dba::read($sql); - return Dba::num_rows($db_results); + return Dba::num_rows($db_results); } // exists @@ -137,22 +137,22 @@ class Preference { * This checks to see if the current user has access to modify this preference * as defined by the preference name */ - public static function has_access($preference) { + public static function has_access($preference) { // Nothing for those demo thugs - if (Config::get('demo_mode')) { return false; } + if (Config::get('demo_mode')) { return false; } - $preference = Dba::escape($preference); + $preference = Dba::escape($preference); - $sql = "SELECT `level` FROM `preference` WHERE `name`='$preference'"; - $db_results = Dba::read($sql); + $sql = "SELECT `level` FROM `preference` WHERE `name`='$preference'"; + $db_results = Dba::read($sql); $data = Dba::fetch_assoc($db_results); - if (Access::check('interface',$data['level'])) { - return true; - } + if (Access::check('interface',$data['level'])) { + return true; + } - return false; + return false; } // has_access @@ -160,16 +160,16 @@ class Preference { * id_from_name * This takes a name and returns the id */ - public static function id_from_name($name) { + public static function id_from_name($name) { - $name = Dba::escape($name); + $name = Dba::escape($name); - $sql = "SELECT `id` FROM `preference` WHERE `name`='$name'"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `preference` WHERE `name`='$name'"; + $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - return $row['id']; + return $row['id']; } // id_from_name @@ -178,16 +178,16 @@ class Preference { * This returns the name from an id, it's the exact opposite * of the function above it, amazing! */ - public static function name_from_id($id) { + public static function name_from_id($id) { - $id = Dba::escape($id); + $id = Dba::escape($id); - $sql = "SELECT `name` FROM `preference` WHERE `id`='$id'"; - $db_results = Dba::read($sql); + $sql = "SELECT `name` FROM `preference` WHERE `id`='$id'"; + $db_results = Dba::read($sql); - $row = Dba::fetch_assoc($db_results); + $row = Dba::fetch_assoc($db_results); - return $row['name']; + return $row['name']; } // name_from_id @@ -196,20 +196,20 @@ class Preference { * This returns an array of the names of the different possible sections * it ignores the 'internal' catagory */ - public static function get_catagories() { + public static function get_catagories() { - $sql = "SELECT `preference`.`catagory` FROM `preference` GROUP BY `catagory` ORDER BY `catagory`"; - $db_results = Dba::read($sql); + $sql = "SELECT `preference`.`catagory` FROM `preference` GROUP BY `catagory` ORDER BY `catagory`"; + $db_results = Dba::read($sql); - $results = array(); + $results = array(); - while ($row = Dba::fetch_assoc($db_results)) { - if ($row['catagory'] != 'internal') { - $results[] = $row['catagory']; + while ($row = Dba::fetch_assoc($db_results)) { + if ($row['catagory'] != 'internal') { + $results[] = $row['catagory']; } } // end while - return $results; + return $results; } // get_catagories @@ -217,52 +217,52 @@ class Preference { * get_all * This returns a nice flat array of all of the possible preferences for the specified user */ - public static function get_all($user_id) { + public static function get_all($user_id) { - $user_id = Dba::escape($user_id); + $user_id = Dba::escape($user_id); if ($user_id != '-1') { $user_limit = "AND `preference`.`catagory` != 'system'"; } - - $sql = "SELECT `preference`.`name`,`preference`.`description`,`user_preference`.`value` FROM `preference` " . - " INNER JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` " . - " WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit " . - " ORDER BY `preference`.`description`"; - $db_results = Dba::read($sql); - $results = array(); + $sql = "SELECT `preference`.`name`,`preference`.`description`,`user_preference`.`value` FROM `preference` " . + " INNER JOIN `user_preference` ON `user_preference`.`preference`=`preference`.`id` " . + " WHERE `user_preference`.`user`='$user_id' AND `preference`.`catagory` != 'internal' $user_limit " . + " ORDER BY `preference`.`description`"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { $results[] = array('name'=>$row['name'],'level'=>$row['level'],'description'=>$row['description'],'value'=>$row['value']); - } + } - return $results; + return $results; - } // get_all + } // get_all /** * insert * This inserts a new preference into the preference table * it does NOT sync up the users, that should be done independtly */ - public static function insert($name,$description,$default,$level,$type,$catagory) { + public static function insert($name,$description,$default,$level,$type,$catagory) { - // Clean em up - $name = Dba::escape($name); - $description = Dba::escape($description); - $default = Dba::escape($default); - $level = Dba::escape($level); - $type = Dba::escape($type); - $catagory = Dba::escape($catagory); + // Clean em up + $name = Dba::escape($name); + $description = Dba::escape($description); + $default = Dba::escape($default); + $level = Dba::escape($level); + $type = Dba::escape($type); + $catagory = Dba::escape($catagory); - $sql = "INSERT INTO `preference` (`name`,`description`,`value`,`level`,`type`,`catagory`) " . - "VALUES ('$name','$description','$default','$level','$type','$catagory')"; - $db_results = Dba::write($sql); + $sql = "INSERT INTO `preference` (`name`,`description`,`value`,`level`,`type`,`catagory`) " . + "VALUES ('$name','$description','$default','$level','$type','$catagory')"; + $db_results = Dba::write($sql); - if (!$db_results) { return false; } + if (!$db_results) { return false; } - return true; + return true; } // insert @@ -270,21 +270,21 @@ class Preference { * delete * This deletes the specified preference, a name or a ID can be passed */ - public static function delete($preference) { + public static function delete($preference) { // First prepare if (!is_numeric($preference)) { - $name = Dba::escape($preference); - $sql = "DELETE FROM `preference` WHERE `name`='$name'"; + $name = Dba::escape($preference); + $sql = "DELETE FROM `preference` WHERE `name`='$name'"; } else { - $id = Dba::escape($preference); - $sql = "DELETE FROM `preference` WHERE `id`='$id'"; + $id = Dba::escape($preference); + $sql = "DELETE FROM `preference` WHERE `id`='$id'"; } - $db_results = Dba::write($sql); + $db_results = Dba::write($sql); - self::rebuild_preferences(); + self::rebuild_preferences(); } // delete @@ -292,34 +292,34 @@ class Preference { * rebuild_preferences * This removes any garbage and then adds back in anything missing preferences wise */ - public static function rebuild_preferences() { + public static function rebuild_preferences() { // First remove garbage - $sql = "DELETE FROM `user_preference` USING `user_preference` LEFT JOIN `preference` ON `preference`.`id`=`user_preference`.`preference` " . - "WHERE `preference`.`id` IS NULL"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `user_preference` USING `user_preference` LEFT JOIN `preference` ON `preference`.`id`=`user_preference`.`preference` " . + "WHERE `preference`.`id` IS NULL"; + $db_results = Dba::write($sql); // Now add anything that we are missing back in, except System - $sql = "SELECT * FROM `preference` WHERE `type`!='system'"; + $sql = "SELECT * FROM `preference` WHERE `type`!='system'"; //FIXME: Uhh WTF shouldn't there be something here?? } // rebuild_preferences /** * fix_preferences - * This takes the preferences, explodes what needs to + * This takes the preferences, explodes what needs to * become an array and boolean everythings */ public static function fix_preferences($results) { - $results['auth_methods'] = trim($results['auth_methods']) ? explode(",",$results['auth_methods']) : array(); - $results['tag_order'] = trim($results['tag_order']) ? explode(",",$results['tag_order']) : array(); - $results['album_art_order'] = trim($results['album_art_order']) ? explode(",",$results['album_art_order']) : array(); + $results['auth_methods'] = trim($results['auth_methods']) ? explode(",",$results['auth_methods']) : array(); + $results['tag_order'] = trim($results['tag_order']) ? explode(",",$results['tag_order']) : array(); + $results['album_art_order'] = trim($results['album_art_order']) ? explode(",",$results['album_art_order']) : array(); if (isset($results['amazin_base_urls'])) $results['amazon_base_urls'] = trim($results['amazin_base_urls']) ? explode(",",$results['amazon_base_urls']) : array(); - else + else $results['amazon_base_urls']= array(); - + foreach ($results as $key=>$data) { if (!is_array($data)) { if (strcasecmp($data,"true") == "0") { $results[$key] = 1; } @@ -334,15 +334,15 @@ class Preference { /** * load_from_session * This loads the preferences from the session rather then creating a connection to the database - */ - public static function load_from_session($uid=-1) { + */ + public static function load_from_session($uid=-1) { - if (is_array($_SESSION['userdata']['preferences']) AND $_SESSION['userdata']['uid'] == $uid) { - Config::set_by_array($_SESSION['userdata']['preferences'],1); - return true; - } + if (is_array($_SESSION['userdata']['preferences']) AND $_SESSION['userdata']['uid'] == $uid) { + Config::set_by_array($_SESSION['userdata']['preferences'],1); + return true; + } - return false; + return false; } // load_from_session @@ -351,9 +351,9 @@ class Preference { * This clears the users preferences, this is done whenever modifications are made to the preferences * or the admin resets something */ - public static function clear_from_session() { + public static function clear_from_session() { - unset($_SESSION['userdata']['preferences']); + unset($_SESSION['userdata']['preferences']); } // clear_from_session @@ -363,7 +363,7 @@ class Preference { * This is currently only used by the debug view, could be used other places.. wouldn't be a half * bad idea */ - public static function is_boolean($key) { + public static function is_boolean($key) { $boolean_array = array('session_cookiesecure','require_session', 'access_control','require_localnet_session', @@ -377,13 +377,13 @@ class Preference { 'allow_stream_playback','allow_democratic_playback', 'use_auth','allow_localplay_playback','debug','lock_songs', 'transcode_m4a','transcode_mp3','transcode_ogg','transcode_flac', - 'shoutcast_active','httpq_active','show_lyrics'); + 'shoutcast_active','httpq_active','show_lyrics'); - if (in_array($key,$boolean_array)) { - return true; - } + if (in_array($key,$boolean_array)) { + return true; + } - return false; + return false; } // is_boolean @@ -392,25 +392,25 @@ class Preference { * 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() { + public static function init() { - $user_id = $GLOBALS['user']->id ? Dba::escape($GLOBALS['user']->id) : '-1'; + $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; - } - + 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'"; + $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); while ($row = Dba::fetch_assoc($db_results)) { - $value = $row['system_value'] ? $row['system_value'] : $row['value']; + $value = $row['system_value'] ? $row['system_value'] : $row['value']; $name = $row['name']; - $results[$name] = $value; + $results[$name] = $value; } // end while sys prefs /* Set the Theme mojo */ @@ -425,8 +425,8 @@ class Preference { } Config::set_by_array($results,1); - $_SESSION['userdata']['preferences'] = $results; - $_SESSION['userdata']['uid'] = $user_id; + $_SESSION['userdata']['preferences'] = $results; + $_SESSION['userdata']['uid'] = $user_id; } // init diff --git a/lib/class/query.class.php b/lib/class/query.class.php index 057897e2..109cef1f 100644 --- a/lib/class/query.class.php +++ b/lib/class/query.class.php @@ -817,15 +817,15 @@ class Query { switch (self::$type) { case 'song': switch($filter) { - case 'tag': + case 'tag': self::set_join('left','`tag_map`','`tag_map`.`object_id`','`song`.`id`'); - $filter_sql = " `tag_map`.`object_type`='song' AND ("; - - foreach ($value as $tag_id) { - $filter_sql .= " `tag_map`.`tag_id`='" . Dba::escape($tag_id) . "' AND"; + $filter_sql = " `tag_map`.`object_type`='song' AND ("; + + foreach ($value as $tag_id) { + $filter_sql .= " `tag_map`.`tag_id`='" . Dba::escape($tag_id) . "' AND"; } - $filter_sql = rtrim($filter_sql,'AND') . ') AND '; - break; + $filter_sql = rtrim($filter_sql,'AND') . ') AND '; + break; case 'exact_match': $filter_sql = " `song`.`title` = '" . Dba::escape($value) . "' AND "; break; @@ -971,9 +971,9 @@ class Query { case 'exact_match': $filter_sql = " `tag`.`name` = '" . Dba::escape($value) . "' AND "; break; - case 'tag': - $filter_sql = " `tag`.`id` = '" . Dba::escape($value) . "' AND "; - break; + case 'tag': + $filter_sql = " `tag`.`id` = '" . Dba::escape($value) . "' AND "; + break; default: // Rien a faire break; diff --git a/lib/class/radio.class.php b/lib/class/radio.class.php index 65cdf1d0..7112ea5c 100644 --- a/lib/class/radio.class.php +++ b/lib/class/radio.class.php @@ -17,7 +17,7 @@ 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. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -29,26 +29,26 @@ class Radio extends database_object implements media { /* DB based variables */ - public $id; - public $name; - public $site_url; - public $url; + public $id; + public $name; + public $site_url; + public $url; public $frequency; public $call_sign; - public $catalog; + public $catalog; /** * Constructor * This takes a flagged.id and then pulls in the information for said flag entry */ - public function __construct($id) { + public function __construct($id) { $info = $this->get_info($id,'live_stream'); // Set the vars - foreach ($info as $key=>$value) { - $this->$key = $value; - } + foreach ($info as $key=>$value) { + $this->$key = $value; + } } // constructor @@ -57,111 +57,111 @@ class Radio extends database_object implements media { * This takes the normal data from the database and makes it pretty * for the users, the new variables are put in f_??? and f_???_link */ - public function format() { + public function format() { // Default link used on the rightbar - $this->f_link = "url\">$this->name"; + $this->f_link = "url\">$this->name"; - $this->f_name_link = "site_url\">$this->name"; - $this->f_callsign = scrub_out($this->call_sign); - $this->f_frequency = scrub_out($this->frequency); + $this->f_name_link = "site_url\">$this->name"; + $this->f_callsign = scrub_out($this->call_sign); + $this->f_frequency = scrub_out($this->frequency); - return true; + return true; } // format /** * update * This is a static function that takes a key'd array for input - * it depends on a ID element to determine which radio element it + * it depends on a ID element to determine which radio element it * should be updating */ - public static function update($data) { + public static function update($data) { // Verify the incoming data - if (!$data['id']) { + if (!$data['id']) { // FIXME: Untranslated - Error::add('general','Missing ID'); - } + Error::add('general','Missing ID'); + } - if (!$data['name']) { + if (!$data['name']) { // FIXME: Untranslated - Error::add('general','Name Required'); - } + Error::add('general','Name Required'); + } - $allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp'); + $allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp'); - $elements = explode(":",$data['url']); - - if (!in_array($elements['0'],$allowed_array)) { + $elements = explode(":",$data['url']); + + if (!in_array($elements['0'],$allowed_array)) { // FIXME: Untranslated - Error::add('general','Invalid URL must be mms:// , https:// or http://'); - } + Error::add('general','Invalid URL must be mms:// , https:// or http://'); + } - if (Error::occurred()) { - return false; - } + if (Error::occurred()) { + return false; + } // Setup the data - $name = Dba::escape($data['name']); - $site_url = Dba::escape($data['site_url']); - $url = Dba::escape($data['url']); - $frequency = Dba::escape($data['frequency']); - $call_sign = Dba::escape($data['call_sign']); - $id = Dba::escape($data['id']); + $name = Dba::escape($data['name']); + $site_url = Dba::escape($data['site_url']); + $url = Dba::escape($data['url']); + $frequency = Dba::escape($data['frequency']); + $call_sign = Dba::escape($data['call_sign']); + $id = Dba::escape($data['id']); - $sql = "UPDATE `live_stream` SET `name`='$name',`site_url`='$site_url',`url`='$url'" . - ",`frequency`='$frequency',`call_sign`='$call_sign' WHERE `id`='$id'"; - $db_results = Dba::write($sql); + $sql = "UPDATE `live_stream` SET `name`='$name',`site_url`='$site_url',`url`='$url'" . + ",`frequency`='$frequency',`call_sign`='$call_sign' WHERE `id`='$id'"; + $db_results = Dba::write($sql); - return $db_results; + return $db_results; } // update /** * create * This is a static function that takes a key'd array for input - * and if everything is good creates the object. + * and if everything is good creates the object. */ - public static function create($data) { + public static function create($data) { // Make sure we've got a name - if (!strlen($data['name'])) { + if (!strlen($data['name'])) { // FIXME: Untranslated - Error::add('name','Name Required'); - } + Error::add('name','Name Required'); + } - $allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp'); + $allowed_array = array('https','http','mms','mmsh','mmsu','mmst','rtsp'); - $elements = explode(":",$data['url']); - - if (!in_array($elements['0'],$allowed_array)) { - Error::add('url','Invalid URL must be http:// or https://'); - } + $elements = explode(":",$data['url']); + + if (!in_array($elements['0'],$allowed_array)) { + Error::add('url','Invalid URL must be http:// or https://'); + } // Make sure it's a real catalog - $catalog = new Catalog($data['catalog']); - if (!$catalog->name) { + $catalog = new Catalog($data['catalog']); + if (!$catalog->name) { // FIXME: Untranslated - Error::add('catalog','Invalid Catalog'); - } + Error::add('catalog','Invalid Catalog'); + } - if (Error::occurred()) { return false; } + if (Error::occurred()) { return false; } // Clean up the input - $name = Dba::escape($data['name']); - $site_url = Dba::escape($data['site_url']); - $url = Dba::escape($data['url']); - $catalog = $catalog->id; - $frequency = Dba::escape($data['frequency']); - $call_sign = Dba::escape($data['call_sign']); + $name = Dba::escape($data['name']); + $site_url = Dba::escape($data['site_url']); + $url = Dba::escape($data['url']); + $catalog = $catalog->id; + $frequency = Dba::escape($data['frequency']); + $call_sign = Dba::escape($data['call_sign']); // If we've made it this far everything must be ok... I hope - $sql = "INSERT INTO `live_stream` (`name`,`site_url`,`url`,`catalog`,`frequency`,`call_sign`) " . - "VALUES ('$name','$site_url','$url','$catalog','$frequency','$call_sign')"; - $db_results = Dba::write($sql); + $sql = "INSERT INTO `live_stream` (`name`,`site_url`,`url`,`catalog`,`frequency`,`call_sign`) " . + "VALUES ('$name','$site_url','$url','$catalog','$frequency','$call_sign')"; + $db_results = Dba::write($sql); - return $db_results; + return $db_results; } // create @@ -169,14 +169,14 @@ class Radio extends database_object implements media { * delete * This deletes the current object from the database */ - public function delete() { + public function delete() { - $id = Dba::escape($this->id); + $id = Dba::escape($this->id); - $sql = "DELETE FROM `live_stream` WHERE `id`='$id'"; - $db_results = Dba::write($sql); + $sql = "DELETE FROM `live_stream` WHERE `id`='$id'"; + $db_results = Dba::write($sql); - return true; + return true; } // delete @@ -184,29 +184,29 @@ class Radio extends database_object implements media { * native_stream * This is needed by the media interface */ - public function native_stream() { + public function native_stream() { - } // native_stream + } // native_stream /** * play_url * This is needed by the media interface */ - public static function play_url($oid,$sid='',$force_http='') { + public static function play_url($oid,$sid='',$force_http='') { - $radio = new Radio($oid); - - return $radio->url; + $radio = new Radio($oid); - } // play_url + return $radio->url; + + } // play_url /** * has_flag * This is needed by the media interface */ - public function has_flag() { + public function has_flag() { @@ -216,7 +216,7 @@ class Radio extends database_object implements media { * stream_cmd * Needed by the media interface */ - public function stream_cmd() { + public function stream_cmd() { } // stream_cmd diff --git a/lib/class/random.class.php b/lib/class/random.class.php index eab6b3f9..582d00ac 100644 --- a/lib/class/random.class.php +++ b/lib/class/random.class.php @@ -17,7 +17,7 @@ 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. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -30,17 +30,17 @@ class Random implements media { public $type; - public $id; + public $id; /** * Constructor * nothing to see here, move along */ - public function __construct($id) { + public function __construct($id) { - $this->type = Random::get_id_type($id); - $this->id = intval($id); + $this->type = Random::get_id_type($id); + $this->id = intval($id); } // constructor @@ -48,14 +48,14 @@ class Random implements media { * album * This returns the ID of a random album, nothing special */ - public static function album() { + public static function album() { - $sql = "SELECT `id` FROM `album` ORDER BY RAND() LIMIT 1"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `album` ORDER BY RAND() LIMIT 1"; + $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); - return $results['id']; + return $results['id']; } // album @@ -63,14 +63,14 @@ class Random implements media { * artist * This returns the ID of a random artist, nothing special here for now */ - public static function artist() { + public static function artist() { - $sql = "SELECT `id` FROM `artist` ORDER BY RAND() LIMIT 1"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `artist` ORDER BY RAND() LIMIT 1"; + $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); - return $results['id']; + return $results['id']; } // artist @@ -79,16 +79,16 @@ class Random implements media { * This returns a random Playlist with songs little bit of extra * logic require */ - public static function playlist() { + public static function playlist() { - $sql = "SELECT `playlist`.`id` FROM `playlist` LEFT JOIN `playlist_data` " . - " ON `playlist`.`id`=`playlist_data`.`playlist` WHERE `playlist_data`.`object_id` IS NOT NULL " . - " ORDER BY RAND()"; - $db_results = Dba::read($sql); + $sql = "SELECT `playlist`.`id` FROM `playlist` LEFT JOIN `playlist_data` " . + " ON `playlist`.`id`=`playlist_data`.`playlist` WHERE `playlist_data`.`object_id` IS NOT NULL " . + " ORDER BY RAND()"; + $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); - return $results['id']; + return $results['id']; } // playlist @@ -97,38 +97,38 @@ class Random implements media { * This generates a random play url based on the passed type * and returns it */ - public static function play_url($id,$sid='',$force_http='') { + public static function play_url($id,$sid='',$force_http='') { + + if (!$type = self::get_id_type($id)) { + return false; + } + + $uid = $GLOBALS['user']->id; - if (!$type = self::get_id_type($id)) { - return false; - } - - $uid = $GLOBALS['user']->id; - $url = Stream::get_base_url() . "random=1&type=$type&uid=$uid"; - return $url; + return $url; - } // play_url + } // play_url /** * get_single_song * This returns a single song pulled based on the passed random method */ - public static function get_single_song($type) { + public static function get_single_song($type) { - if (!$type = self::validate_type($type)) { - return false; - } + if (!$type = self::validate_type($type)) { + return false; + } - $method_name = 'get_' . $type; + $method_name = 'get_' . $type; - if (method_exists('Random',$method_name)) { - $song_ids = self::$method_name(1); - $song_id = array_pop($song_ids); - } - - return $song_id; + if (method_exists('Random',$method_name)) { + $song_ids = self::$method_name(1); + $song_id = array_pop($song_ids); + } + + return $song_id; } // get_single_song @@ -136,19 +136,19 @@ class Random implements media { * get_default * This just randomly picks a song at whim from all catalogs * nothing special here... - */ - public static function get_default($limit) { + */ + public static function get_default($limit) { - $results = array(); + $results = array(); - $sql = "SELECT `id` FROM `song` ORDER BY RAND() LIMIT $limit"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `song` ORDER BY RAND() LIMIT $limit"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['id']; - } - - return $results; + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } + + return $results; } // get_default @@ -157,24 +157,24 @@ class Random implements media { * This looks at the last object played by the current user and * then picks a song of the same genre at random... */ - public static function get_genre($limit) { + public static function get_genre($limit) { - $results = array(); + $results = array(); // Get the last genre played by us - $data = $GLOBALS['user']->get_recently_played('1','genre'); - if ($data['0']) { - $where_sql = " WHERE `genre`='" . $data['0'] . "' "; - } + $data = $GLOBALS['user']->get_recently_played('1','genre'); + if ($data['0']) { + $where_sql = " WHERE `genre`='" . $data['0'] . "' "; + } - $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['id']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } - return $results; + return $results; } // get_genre @@ -183,24 +183,24 @@ class Random implements media { * This looks at the last album played by the current user and * picks something else in the same album */ - public static function get_album($limit) { + public static function get_album($limit) { - $results = array(); + $results = array(); // Get the last album playbed by us - $data = $GLOBALS['user']->get_recently_played('1','album'); - if ($data['0']) { + $data = $GLOBALS['user']->get_recently_played('1','album'); + if ($data['0']) { $where_sql = " WHERE `album`='" . $data['0'] . "' "; - } + } - $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['id']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } - return $results; + return $results; } // get_album @@ -209,59 +209,59 @@ class Random implements media { * This looks at the last artist played and then randomly picks a song from the * same artist */ - public static function get_artist($limit) { + public static function get_artist($limit) { - $results = array(); + $results = array(); - $data = $GLOBALS['user']->get_recently_played('1','artist'); - if ($data['0']) { - $where_sql = " WHERE `artist`='" . $data['0'] . "' "; - } + $data = $GLOBALS['user']->get_recently_played('1','artist'); + if ($data['0']) { + $where_sql = " WHERE `artist`='" . $data['0'] . "' "; + } - $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit"; - $db_results = Dba::read($sql); + $sql = "SELECT `id` FROM `song` $where_sql ORDER BY RAND() LIMIT $limit"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['id']; - } - - return $results; + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } + + return $results; } // get_artist /** * advanced - * This processes the results of a post from a form and returns an - * array of song items that were returned from said randomness + * 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($data) { + public static function advanced($data) { /* Figure out our object limit */ - $limit = intval($data['random']); + $limit = intval($data['random']); // Generate our matchlist if ($data['catalog'] != '-1') { - $matchlist['catalog'] = $data['catalog']; + $matchlist['catalog'] = $data['catalog']; } - if ($data['genre'][0] != '-1') { - $matchlist['genre'] = $data['genre']; - } - + if ($data['genre'][0] != '-1') { + $matchlist['genre'] = $data['genre']; + } + /* If they've passed -1 as limit then don't get everything */ if ($data['random'] == "-1") { unset($data['random']); } else { $limit_sql = "LIMIT " . Dba::escape($limit); } $where = "1=1 "; - if (is_array($matchlist)) { + if (is_array($matchlist)) { foreach ($matchlist as $type => $value) { if (is_array($value)) { foreach ($value as $v) { - if (!strlen($v)) { continue; } + if (!strlen($v)) { continue; } $v = Dba::escape($v); if ($v != $value[0]) { $where .= " OR $type='$v' "; } else { $where .= " AND ( $type='$v'"; } } - $where .= ")"; + $where .= ")"; } elseif (strlen($value)) { $value = Dba::escape($value); @@ -269,10 +269,10 @@ class Random implements media { } } // end foreach } // end if matchlist - - switch ($data['random_type']) { - case 'full_album': - $query = "SELECT `album`.`id` FROM `song` INNER JOIN `album` ON `song`.`album`=`album`.`id` " . + + switch ($data['random_type']) { + case 'full_album': + $query = "SELECT `album`.`id` FROM `song` INNER JOIN `album` ON `song`.`album`=`album`.`id` " . "WHERE $where GROUP BY `song`.`album` ORDER BY RAND() $limit_sql"; $db_results = Dba::read($query); while ($row = Dba::fetch_assoc($db_results)) { @@ -280,9 +280,9 @@ class Random implements media { } $albums_where = ltrim($albums_where," OR"); $sql = "SELECT `song`.`id`,`song`.`size`,`song`.`time` FROM `song` WHERE $albums_where ORDER BY `song`.`album`,`song`.`track` ASC"; - break; - case 'full_artist': - $query = "SELECT `artist`.`id` FROM `song` INNER JOIN `artist` ON `song`.`artist`=`artist`.`id` " . + break; + case 'full_artist': + $query = "SELECT `artist`.`id` FROM `song` INNER JOIN `artist` ON `song`.`artist`=`artist`.`id` " . "WHERE $where GROUP BY `song`.`artist` ORDER BY RAND() $limit_sql"; $db_results = Dba::read($query); while ($row = Dba::fetch_row($db_results)) { @@ -291,114 +291,114 @@ class Random implements media { $artists_where = ltrim($artists_where," OR"); $sql = "SELECT song.id,song.size,song.time FROM song WHERE $artists_where ORDER BY RAND()"; break; - case 'unplayed': - $uid = Dba::escape($GLOBALS['user']->id); + case 'unplayed': + $uid = Dba::escape($GLOBALS['user']->id); $sql = "SELECT object_id,COUNT(`id`) AS `total` FROM `object_count` WHERE `user`='$uid' GROUP BY `object_id`"; - $db_results = Dba::read($sql); + $db_results = Dba::read($sql); $in_sql = "`id` IN ("; - while ($row = Dba::fetch_assoc($db_results)) { - $row['object_id'] = Dba::escape($row['object_id']); - $in_sql .= "'" . $row['object_id'] . "',"; - } + while ($row = Dba::fetch_assoc($db_results)) { + $row['object_id'] = Dba::escape($row['object_id']); + $in_sql .= "'" . $row['object_id'] . "',"; + } $in_sql = rtrim($in_sql,',') . ')'; $sql = "SELECT song.id,song.size,song.time FROM song " . "WHERE ($where) AND $in_sql ORDER BY RAND() $limit_sql"; - break; - case 'high_rating': - $sql = "SELECT `rating`.`object_id`,`rating`.`rating` FROM `rating` " . - "WHERE `rating`.`object_type`='song' ORDER BY `rating` DESC"; - $db_results = Dba::read($sql); + break; + case 'high_rating': + $sql = "SELECT `rating`.`object_id`,`rating`.`rating` FROM `rating` " . + "WHERE `rating`.`object_type`='song' ORDER BY `rating` DESC"; + $db_results = Dba::read($sql); // Get all of the ratings for songs - while ($row = Dba::fetch_assoc($db_results)) { - $results[$row['object_id']][] = $row['rating']; - } - // Calculate the averages - foreach ($results as $key=>$rating_array) { - $average = intval(array_sum($rating_array) / count($rating_array)); + while ($row = Dba::fetch_assoc($db_results)) { + $results[$row['object_id']][] = $row['rating']; + } + // Calculate the averages + foreach ($results as $key=>$rating_array) { + $average = intval(array_sum($rating_array) / count($rating_array)); // We have to do this because array_slice doesn't maintain indexes - $new_key = $average . $key; + $new_key = $average . $key; $ratings[$new_key] = $key; - } + } // Sort it by the value and slice at $limit * 2 so we have a little bit of randomness - krsort($ratings); - $ratings = array_slice($ratings,0,$limit*2); - - $in_sql = "`song`.`id` IN ("; - - // Build the IN query, cause if you're OUT it ain't cool - foreach ($ratings as $song_id) { - $key = Dba::escape($song_id); - $in_sql .= "'$key',"; - } + krsort($ratings); + $ratings = array_slice($ratings,0,$limit*2); - $in_sql = rtrim($in_sql,',') . ')'; + $in_sql = "`song`.`id` IN ("; + + // Build the IN query, cause if you're OUT it ain't cool + foreach ($ratings as $song_id) { + $key = Dba::escape($song_id); + $in_sql .= "'$key',"; + } + + $in_sql = rtrim($in_sql,',') . ')'; // Apply true limit and order by rand - $sql = "SELECT song.id,song.size,song.time FROM song " . - "WHERE ($where) AND $in_sql ORDER BY RAND() $limit_sql"; + $sql = "SELECT song.id,song.size,song.time FROM song " . + "WHERE ($where) AND $in_sql ORDER BY RAND() $limit_sql"; break; - default: - $sql = "SELECT `id`,`size`,`time` FROM `song` WHERE $where ORDER BY RAND() $limit_sql"; + default: + $sql = "SELECT `id`,`size`,`time` FROM `song` WHERE $where ORDER BY RAND() $limit_sql"; break; - } // end switch on type of random play + } // end switch on type of random play // Run the query generated above so we can while it - $db_results = Dba::read($sql); - $results = array(); + $db_results = Dba::read($sql); + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { - while ($row = Dba::fetch_assoc($db_results)) { - // If size limit is specified - if ($data['size_limit']) { + if ($data['size_limit']) { // Convert - $new_size = ($row['size'] / 1024) / 1024; - + $new_size = ($row['size'] / 1024) / 1024; + // Only fuzzy 10 times - if ($fuzzy_size > 10) { return $results; } + if ($fuzzy_size > 10) { return $results; } // Add and check, skip if over don't return incase theres a smaller one commin round - if (($size_total + $new_size) > $data['size_limit']) { $fuzzy_size++; continue; } - - $size_total = $size_total + $new_size; - $results[] = $row['id']; + 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) { return $results; } + if (($data['size_limit'] - floor($size_total)) < 4) { return $results; } } // if size_limit // If length really does matter - if ($data['length']) { + if ($data['length']) { // base on min, seconds are for chumps and chumpettes - $new_time = floor($row['time'] / 60); + $new_time = floor($row['time'] / 60); + + if ($fuzzy_time > 10) { return $results; } - if ($fuzzy_time > 10) { return $results; } - // If the new one would go voer skip! - if (($time_total + $new_time) > $data['length']) { $fuzzy_time++; continue; } + if (($time_total + $new_time) > $data['length']) { $fuzzy_time++; continue; } - $time_total = $time_total + $new_time; - $results[] = $row['id']; + $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 there are less then 2 min of free space return + if (($data['length'] - $time_total) < 2) { return $results; } - } // if length does matter + } // if length does matter - if (!$data['size_limit'] AND !$data['length']) { - $results[] = $row['id']; - } + if (!$data['size_limit'] AND !$data['length']) { + $results[] = $row['id']; + } } // end while results - return $results; + return $results; } // advanced @@ -406,22 +406,22 @@ class Random implements media { * get_type_name * This returns a 'purrty' name for the differnt random types */ - public static function get_type_name($type) { + public static function get_type_name($type) { - switch ($type) { + switch ($type) { case 'album': - return _('Related Album'); + return _('Related Album'); break; - case 'genre': - return _('Related Genre'); + case 'genre': + return _('Related Genre'); break; - case 'artist': - return _('Related Artist'); + case 'artist': + return _('Related Artist'); break; - default: - return _('Pure Random'); + default: + return _('Pure Random'); break; - } // end switch + } // end switch } // get_type_name @@ -431,22 +431,22 @@ class Random implements media { * MOTHER OF PEARL THIS MAKES BABY JESUS CRY * HACK HACK HACK HACK HACK HACK HACK HACK */ - public static function get_type_id($type) { + public static function get_type_id($type) { - switch ($type) { - case 'album': - return '1'; - break; - case 'artist': - return '2'; - break; - case 'tag': - return '3'; - break; - default: - return '4'; - break; - } + switch ($type) { + case 'album': + return '1'; + break; + case 'artist': + return '2'; + break; + case 'tag': + return '3'; + break; + default: + return '4'; + break; + } } // get_type_id @@ -454,24 +454,24 @@ class Random implements media { * get_id_name * This takes an ID and returns the 'name' of the random dealie * HACK HACK HACK HACK HACK HACK HACK - * Can you tell I don't like this code? + * Can you tell I don't like this code? */ - public static function get_id_type($id) { + public static function get_id_type($id) { - switch ($id) { - case '1': + switch ($id) { + case '1': return 'album'; break; - case '2': + case '2': return 'artist'; - break; - case '3': + break; + case '3': return 'tag'; - break; - default: - return 'default'; - break; - } // end switch + break; + default: + return 'default'; + break; + } // end switch } // get_id_name @@ -479,7 +479,7 @@ class Random implements media { * validiate_type * this validates the random type */ - public static function validate_type($type) { + public static function validate_type($type) { switch ($type) { case 'default': @@ -487,19 +487,19 @@ class Random implements media { case 'album': case 'artist': case 'rated': - return $type; + return $type; break; default: return 'default'; break; } // end switch - - return $type; + + return $type; } // validate_type - public function native_stream() { } - public function stream_cmd() { } + public function native_stream() { } + public function stream_cmd() { } public function has_flag() { } public function format() { } diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php index f5af5519..5c2bb3e9 100644 --- a/lib/class/rating.class.php +++ b/lib/class/rating.class.php @@ -23,7 +23,7 @@ /** * Rating class * This is an amalgamation(sp?) of code from SoundOfEmotion - * to track ratings for songs, albums and artists. + * to track ratings for songs, albums and artists. */ class Rating extends database_object { @@ -40,21 +40,21 @@ class Rating extends database_object { * This is run every time a new object is created, it requires * the id and type of object that we need to pull the raiting for */ - public function __construct($id,$type) { + public function __construct($id,$type) { $this->id = intval($id); $this->type = Dba::escape($type); // Check for the users rating - if ($rating = $this->get_user($GLOBALS['user']->id)) { + if ($rating = $this->get_user($GLOBALS['user']->id)) { $this->rating = $rating; $this->preciserating = $rating; - } - else { + } + else { $this->get_average(); } - - return true; + + return true; } // Constructor @@ -65,44 +65,44 @@ class Rating extends database_object { * //FIXME: Improve logic so that misses get cached as average */ public static function build_cache($type, $ids) { - + if (!is_array($ids) OR !count($ids)) { return false; } - $user_id = Dba::escape($GLOBALS['user']->id); + $user_id = Dba::escape($GLOBALS['user']->id); $idlist = '(' . implode(',', $ids) . ')'; - $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . + $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " . "AND `object_type`='$type'"; $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { - $user[$row['object_id']] = $row['rating']; + $user[$row['object_id']] = $row['rating']; } - - $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'"; - $db_results = Dba::read($sql); - - while ($row = Dba::fetch_assoc($db_results)) { - $rating[$row['object_id']]['rating'] += $row['rating']; - $rating[$row['object_id']]['total']++; - } - foreach ($ids as $id) { - parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id])); + $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'"; + $db_results = Dba::read($sql); + + while ($row = Dba::fetch_assoc($db_results)) { + $rating[$row['object_id']]['rating'] += $row['rating']; + $rating[$row['object_id']]['total']++; + } + + foreach ($ids as $id) { + parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id])); // Do the bit of math required to store this - if (!isset($rating[$id])) { - $entry = array('average'=>'0','percise'=>'0'); - } - else { - $average = round($rating[$id]['rating']/$rating[$id]['total'],1); - $entry = array('average'=>floor($average),'percise'=>$average); - } - - parent::add_to_cache('rating_' . $type . '_all',$id,$entry); - } + if (!isset($rating[$id])) { + $entry = array('average'=>'0','percise'=>'0'); + } + else { + $average = round($rating[$id]['rating']/$rating[$id]['total'],1); + $entry = array('average'=>floor($average),'percise'=>$average); + } - return true; + parent::add_to_cache('rating_' . $type . '_all',$id,$entry); + } + + return true; } // build_cache @@ -112,22 +112,22 @@ class Rating extends database_object { * in user. It returns the value */ public function get_user($user_id) { - - $id = intval($this->id); - - if (parent::is_cached('rating_' . $this->type . '_user',$id)) { - return parent::get_from_cache('rating_' . $this->type . '_user',$id); - } - $user_id = Dba::escape($user_id); + $id = intval($this->id); + + if (parent::is_cached('rating_' . $this->type . '_user',$id)) { + return parent::get_from_cache('rating_' . $this->type . '_user',$id); + } + + $user_id = Dba::escape($user_id); $sql = "SELECT `rating` FROM `rating` WHERE `user`='$user_id' AND `object_id`='$id' AND `object_type`='$this->type'"; $db_results = Dba::read($sql); - + $results = Dba::fetch_assoc($db_results); - parent::add_to_cache('rating_' . $this->type . '_user',$id,$results['rating']); - + parent::add_to_cache('rating_' . $this->type . '_user',$id,$results['rating']); + return $results['rating']; } // get_user @@ -136,79 +136,79 @@ class Rating extends database_object { * get_average * Get the users average rating this is based off the floor'd average * of what everyone has rated this album as. This is shown if there - * is no personal rating, and used for random play mojo. It sets + * is no personal rating, and used for random play mojo. It sets * $this->average_rating and returns the value */ - public function get_average() { + public function get_average() { - $id = intval($this->id); + $id = intval($this->id); - if (parent::is_cached('rating_' . $this->type . '_all',$id)) { - $data = parent::get_from_cache('rating_' . $this->type . '_user',$id); - $this->rating = $data['rating']; - $this->perciserating = $data['percise']; - return true; - } + if (parent::is_cached('rating_' . $this->type . '_all',$id)) { + $data = parent::get_from_cache('rating_' . $this->type . '_user',$id); + $this->rating = $data['rating']; + $this->perciserating = $data['percise']; + return true; + } $sql = "SELECT `rating` FROM `rating` WHERE `object_id`='$id' AND `object_type`='$this->type'"; $db_results = Dba::read($sql); $i = 0; - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $i++; $total += $r['rating']; } // while we're pulling results - if ($total > 0) { + if ($total > 0) { $average = round($total/$i, 1); } - elseif ($i >= '1' AND $total == '0') { + elseif ($i >= '1' AND $total == '0') { $average = -1; } - else { + else { $average = 0; } - + $this->preciserating = $average; $this->rating = floor($average); - + return $this->rating; } // get_average /** * set_rating - * This function sets a rating for the current $this object. + * This function sets a rating for the current $this object. * This uses the currently logged in user for the 'user' who is rating * the object. Returns true on success, false on failure */ - public function set_rating($score) { - + public function set_rating($score) { + $score = Dba::escape($score); // If score is -1, then remove rating if ($score == '-1') { - $sql = "DELETE FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " . + $sql = "DELETE FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " . "AND `user`='" . Dba::escape($GLOBALS['user']->id) . "'"; $db_results = Dba::read($sql); return true; } /* Check if it exists */ - $sql = "SELECT `id` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " . + $sql = "SELECT `id` FROM `rating` WHERE `object_id`='$this->id' AND `object_type`='$this->type' " . "AND `user`='" . Dba::escape($GLOBALS['user']->id) . "'"; $db_results = Dba::read($sql); - if ($existing = Dba::fetch_assoc($db_results)) { + if ($existing = Dba::fetch_assoc($db_results)) { $sql = "UPDATE `rating` SET `rating`='$score' WHERE `id`='" . $existing['id'] . "'"; $db_results = Dba::write($sql); } - else { - $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`rating`,`user`) VALUES " . + else { + $sql = "INSERT INTO `rating` (`object_id`,`object_type`,`rating`,`user`) VALUES " . " ('$this->id','$this->type','$score','" . $GLOBALS['user']->id . "')"; $db_results = Dba::write($sql); - } + } return true; @@ -216,31 +216,31 @@ class Rating extends database_object { /** * show - * This takes an id and a type and displays the rating if ratings are enabled. + * This takes an id and a type and displays the rating if ratings are enabled. */ - public static function show ($object_id,$type) { + public static function show ($object_id,$type) { // If there aren't ratings don't return anything - if (!Config::get('ratings')) { return false; } + if (!Config::get('ratings')) { return false; } - $rating = new Rating($object_id,$type); + $rating = new Rating($object_id,$type); - require Config::get('prefix') . '/templates/show_object_rating.inc.php'; + require Config::get('prefix') . '/templates/show_object_rating.inc.php'; - } // show + } // show /** * show_static - * This is a static version of the ratings created by Andy90 + * This is a static version of the ratings created by Andy90 */ - public static function show_static ($object_id,$type) { + public static function show_static ($object_id,$type) { // If there aren't ratings don't return anything - if (!Config::get('ratings')) { return false; } + if (!Config::get('ratings')) { return false; } - $rating = new Rating($object_id,$type); + $rating = new Rating($object_id,$type); - require Config::get('prefix') . '/templates/show_static_object_rating.inc.php'; + require Config::get('prefix') . '/templates/show_static_object_rating.inc.php'; } // show_static diff --git a/lib/class/registration.class.php b/lib/class/registration.class.php index 30987011..ae85670d 100644 --- a/lib/class/registration.class.php +++ b/lib/class/registration.class.php @@ -30,7 +30,7 @@ class Registration { * constructor * This is what is called when the class is loaded */ - public function __construct() { + public function __construct() { // Rien a faire @@ -40,7 +40,7 @@ class Registration { * send_confirmation * This sends the confirmation e-mail for the specified user */ - public static function send_confirmation($username,$fullname,$email,$password,$validation) { + public static function send_confirmation($username,$fullname,$email,$password,$validation) { // Multi-byte Character Mail if(function_exists('mb_language')) { @@ -76,7 +76,7 @@ Password: %s Your account is currently inactive. You cannot use it until you've visited the following link: -%s +%s Thank you for registering "), $username, $password, Config::get('web_path') . "/register.php?action=validate&username=$username&auth=$validation"); @@ -96,7 +96,7 @@ Thank you for registering } // Check to see if the admin should be notified - if (Config::get('admin_notify_reg')) { + if (Config::get('admin_notify_reg')) { $body = sprintf(_("A new user has registered The following values were entered. @@ -113,11 +113,11 @@ E-mail: %s implode("\n", $additional_header), '-f'.Config::get('mail_from')); } else { - mail(Config::get('mail_from'),$subject,$body,implode("\r\n", $additional_header),'-f'.Config::get('mail_from')); + mail(Config::get('mail_from'),$subject,$body,implode("\r\n", $additional_header),'-f'.Config::get('mail_from')); } - } - - return true; + } + + return true; } // send_confirmation @@ -125,11 +125,11 @@ E-mail: %s * show_agreement * This shows the registration agreement, /config/registration_agreement.php */ - public static function show_agreement() { + public static function show_agreement() { $filename = Config::get('prefix') . '/config/registration_agreement.php'; - if (!file_exists($filename)) { return false; } + if (!file_exists($filename)) { return false; } /* Check for existance */ $fp = fopen($filename,'r'); diff --git a/lib/class/scrobbler.class.php b/lib/class/scrobbler.class.php index ee1ae8a2..537b1490 100644 --- a/lib/class/scrobbler.class.php +++ b/lib/class/scrobbler.class.php @@ -30,7 +30,7 @@ class scrobbler { public $submit_port; public $submit_url; public $queued_tracks; - public $reset_handshake = false; + public $reset_handshake = false; public $scrobble_host = 'post.audioscrobbler.com'; /** @@ -43,11 +43,11 @@ class scrobbler { $this->username = trim($username); $this->password = trim($password); $this->challenge = $challenge; - $this->submit_host = $host; - $this->submit_port = $port; - $this->submit_url = $url; + $this->submit_host = $host; + $this->submit_port = $port; + $this->submit_url = $url; $this->queued_tracks = array(); - if ($scrobble_host) { $this->scrobble_host = $scrobble_host; } + if ($scrobble_host) { $this->scrobble_host = $scrobble_host; } } // scrobbler @@ -71,8 +71,8 @@ class scrobbler { /** * handshake - * This does a handshake with the audioscrobber server it doesn't pass the password, but - * it does pass the username and has a 10 second timeout + * This does a handshake with the audioscrobber server it doesn't pass the password, but + * it does pass the username and has a 10 second timeout */ public function handshake() { @@ -83,11 +83,11 @@ class scrobbler { } $username = rawurlencode($this->username); - $timestamp = time(); - $auth_token = rawurlencode(md5($this->password . $timestamp)); - + $timestamp = time(); + $auth_token = rawurlencode(md5($this->password . $timestamp)); + $get_string = "GET /?hs=true&p=1.2&c=apa&v=0.1&u=$username&t=$timestamp&a=$auth_token HTTP/1.1\r\n"; - + fwrite($as_socket, $get_string); fwrite($as_socket, "Host: $this->scrobble_host\r\n"); fwrite($as_socket, "Accept: */*\r\n\r\n"); @@ -111,23 +111,23 @@ class scrobbler { $this->error_msg = 'Invalid Username'; return false; } - if(substr($response[0],0,7) == 'BADTIME') { - $this->error_msg = 'Your time is too far off from the server, or your PHP timezone is incorrect'; - return false; - } + if(substr($response[0],0,7) == 'BADTIME') { + $this->error_msg = 'Your time is too far off from the server, or your PHP timezone is incorrect'; + return false; + } if(substr($response[0], 0, 6) == 'UPDATE') { $this->error_msg = 'You need to update your client: '.substr($response[0], 7); return false; } if(preg_match('/http:\/\/([^\/]+)\/(.*)$/', $response[3], $matches)) { - $host_parts = explode(":",$matches[1]); + $host_parts = explode(":",$matches[1]); $data['submit_host'] = $host_parts[0]; - $data['submit_port'] = $host_parts[1] ? $host_parts[1] : '80'; + $data['submit_port'] = $host_parts[1] ? $host_parts[1] : '80'; $data['submit_url'] = '/' . $matches[2]; } else { - $this->error_msg = "Invalid POST URL returned, unable to continue. Sent:\n$get_string\n----\nReceived:\n" . $buffer . - "\n---------\nExpeceted:" . print_r($response,1); + $this->error_msg = "Invalid POST URL returned, unable to continue. Sent:\n$get_string\n----\nReceived:\n" . $buffer . + "\n---------\nExpeceted:" . print_r($response,1); return false; } @@ -137,36 +137,36 @@ class scrobbler { } // handshake /** - * queue_track + * queue_track * This queues the LastFM track by storing it in this object, it doesn't actually * submit the track or talk to LastFM in anyway, kind of useless for our uses but its - * here, and that's how it is. + * here, and that's how it is. */ public function queue_track($artist, $album, $title, $timestamp, $length,$track) { if ($length < 30) { debug_event('Scrobbler',"Not queuing track, too short",'5'); return false; - } + } $newtrack = array(); $newtrack['artist'] = $artist; $newtrack['album'] = $album; - $newtrack['title'] = $title; + $newtrack['title'] = $title; $newtrack['track'] = $track; $newtrack['length'] = $length; $newtrack['time'] = $timestamp; $this->queued_tracks[$timestamp] = $newtrack; - return true; - + return true; + } // queue_track /** * submit_tracks * This actually talks to LastFM submiting the tracks that are queued up. It * passed the md5'd password combinted with the challenge, which is then md5'd - */ + */ public function submit_tracks() { // Check and make sure that we've got some queued tracks @@ -176,7 +176,7 @@ class scrobbler { } //sort array by timestamp - ksort($this->queued_tracks); + ksort($this->queued_tracks); // build the query string $query_str = 's='.rawurlencode($this->challenge).'&'; @@ -186,20 +186,20 @@ class scrobbler { foreach($this->queued_tracks as $track) { $query_str .= "a[$i]=".rawurlencode($track['artist'])."&t[$i]=".rawurlencode($track['title'])."&b[$i]=".rawurlencode($track['album'])."&"; $query_str .= "m[$i]=&l[$i]=".rawurlencode($track['length'])."&i[$i]=".rawurlencode($track['time'])."&"; - $query_str .= "n[$i]=" . rawurlencode($track['track']) . "&o[$i]=P&r[$i]=&"; + $query_str .= "n[$i]=" . rawurlencode($track['track']) . "&o[$i]=P&r[$i]=&"; $i++; } - if (!trim($this->submit_host) || !$this->submit_port) { - $this->reset_handshake = true; - return false; - } + if (!trim($this->submit_host) || !$this->submit_port) { + $this->reset_handshake = true; + return false; + } $as_socket = fsockopen($this->submit_host, intval($this->submit_port), $errno, $errstr, 2); if(!$as_socket) { $this->error_msg = $errstr; - $this->reset_handshake = true; + $this->reset_handshake = true; return false; } @@ -212,7 +212,7 @@ class scrobbler { fwrite($as_socket, "Content-length: ".strlen($query_str)."\r\n\r\n"); fwrite($as_socket, $query_str."\r\n\r\n"); - + $buffer = ''; while(!feof($as_socket)) { $buffer .= fread($as_socket, 8192); @@ -222,34 +222,34 @@ class scrobbler { $split_response = preg_split("/\r\n\r\n/", $buffer); if(!isset($split_response[1])) { $this->error_msg = 'Did not receive a valid response'; - $this->reset_handshake = true; + $this->reset_handshake = true; return false; } $response = explode("\n", $split_response[1]); if(!isset($response[0])) { $this->error_msg = 'Unknown error submitting tracks'. "\nDebug output:\n".$buffer; - $this->reset_handshake = true; + $this->reset_handshake = true; return false; } if(substr($response[0], 0, 6) == 'FAILED') { $this->error_msg = $response[0]; - $this->reset_handshake = true; + $this->reset_handshake = true; return false; } if(substr($response[0], 0, 7) == 'BADAUTH') { $this->error_msg = 'Invalid username/password (' . $response[0] . ')'; return false; } - if (substr($response[0],0,10) == 'BADSESSION') { - $this->error_msg = 'Invalid Session passed (' . trim($response[0]) . ')'; - $this->reset_handshake = true; - return false; - } + if (substr($response[0],0,10) == 'BADSESSION') { + $this->error_msg = 'Invalid Session passed (' . trim($response[0]) . ')'; + $this->reset_handshake = true; + return false; + } if(substr($response[0], 0, 2) != 'OK') { $this->error_msg = 'Response Not ok, unknown error'. "\nDebug output:\n".$buffer; - $this->reset_handshake = true; + $this->reset_handshake = true; return false; } diff --git a/lib/class/shoutbox.class.php b/lib/class/shoutbox.class.php index 2de151d4..6c1bf145 100644 --- a/lib/class/shoutbox.class.php +++ b/lib/class/shoutbox.class.php @@ -22,19 +22,19 @@ class shoutBox { - public $id; + public $id; /** * Constructor * This pulls the shoutbox information from the database and returns * a constructed object, uses user_shout table */ - public function __construct($shout_id) { + public function __construct($shout_id) { // Load the data from the database $this->_get_info($shout_id); - return true; + return true; } // Constructor @@ -42,48 +42,48 @@ class shoutBox { * _get_info * does the db call, reads from the user_shout table */ - private function _get_info($shout_id) { + private function _get_info($shout_id) { - $sticky_id = Dba::escape($shout_id); + $sticky_id = Dba::escape($shout_id); - $sql = "SELECT * FROM `user_shout` WHERE `id`='$shout_id'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `user_shout` WHERE `id`='$shout_id'"; + $db_results = Dba::read($sql); - $data = Dba::fetch_assoc($db_results); + $data = Dba::fetch_assoc($db_results); - foreach ($data as $key=>$value) { - $this->$key = $value; - } + foreach ($data as $key=>$value) { + $this->$key = $value; + } - return true; + return true; } // _get_info /** - * get_top + * get_top * This returns the top user_shouts, shoutbox objects are always shown regardless and count against the total * number of objects shown */ - public static function get_top($limit) { + public static function get_top($limit) { - $shouts = self::get_sticky(); + $shouts = self::get_sticky(); // If we've already got too many stop here - if (count($shouts) > $limit) { - $shouts = array_slice($shouts,0,$limit); - return $shouts; - } + if (count($shouts) > $limit) { + $shouts = array_slice($shouts,0,$limit); + return $shouts; + } // Only get as many as we need - $limit = intval($limit) - count($shouts); - $sql = "SELECT * FROM `user_shout` WHERE `sticky`='0' ORDER BY `date` DESC LIMIT $limit"; - $db_results = Dba::read($sql); + $limit = intval($limit) - count($shouts); + $sql = "SELECT * FROM `user_shout` WHERE `sticky`='0' ORDER BY `date` DESC LIMIT $limit"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - $shouts[] = $row['id']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $shouts[] = $row['id']; + } - return $shouts; + return $shouts; } // get_top @@ -91,18 +91,18 @@ class shoutBox { * get_sticky * This returns all current sticky shoutbox items */ - public static function get_sticky() { + public static function get_sticky() { - $sql = "SELECT * FROM `user_shout` WHERE `sticky`='1' ORDER BY `date` DESC"; + $sql = "SELECT * FROM `user_shout` WHERE `sticky`='1' ORDER BY `date` DESC"; $db_results = Dba::read($sql); - $results = array(); + $results = array(); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['id']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['id']; + } - return $results; + return $results; } // get_sticky @@ -110,67 +110,67 @@ class shoutBox { * get_object * This takes a type and an ID and returns a created object */ - public static function get_object($type,$object_id) { + public static function get_object($type,$object_id) { - $allowed_objects = array('song','genre','album','artist','radio'); + $allowed_objects = array('song','genre','album','artist','radio'); - if (!in_array($type,$allowed_objects)) { - return false; - } + if (!in_array($type,$allowed_objects)) { + return false; + } - $object = new $type($object_id); + $object = new $type($object_id); - return $object; + return $object; } // get_object /** * get_image - * This returns an image tag if the type of object we're currently rolling with + * This returns an image tag if the type of object we're currently rolling with * has an image assoicated with it */ - public function get_image() { + public function get_image() { - switch ($this->object_type) { - case 'album': - $image_string = ""; - break; - case 'artist': + switch ($this->object_type) { + case 'album': + $image_string = ""; + break; + case 'artist': break; - case 'song': - $song = new Song($this->object_id); - $image_string = ""; + case 'song': + $song = new Song($this->object_id); + $image_string = ""; break; - default: + default: // Rien a faire - break; + break; } // end switch - return $image_string; + return $image_string; } // get_image /** * create - * This takes a key'd array of data as input and inserts a new shoutbox entry, it returns the auto_inc id + * This takes a key'd array of data as input and inserts a new shoutbox entry, it returns the auto_inc id */ - public static function create($data) { + public static function create($data) { - $user = Dba::escape($GLOBALS['user']->id); - $text = Dba::escape(strip_tags($data['comment'])); - $date = time(); - $sticky = make_bool($data['sticky']); - $object_id = Dba::escape($data['object_id']); - $object_type = Dba::escape($data['object_type']); + $user = Dba::escape($GLOBALS['user']->id); + $text = Dba::escape(strip_tags($data['comment'])); + $date = time(); + $sticky = make_bool($data['sticky']); + $object_id = Dba::escape($data['object_id']); + $object_type = Dba::escape($data['object_type']); - $sql = "INSERT INTO `user_shout` (`user`,`date`,`text`,`sticky`,`object_id`,`object_type`) " . - "VALUES ('$user','$date','$text','$sticky','$object_id','$object_type')"; - $db_results = Dba::write($sql); + $sql = "INSERT INTO `user_shout` (`user`,`date`,`text`,`sticky`,`object_id`,`object_type`) " . + "VALUES ('$user','$date','$text','$sticky','$object_id','$object_type')"; + $db_results = Dba::write($sql); - $insert_id = Dba::insert_id(); + $insert_id = Dba::insert_id(); - return $insert_id; + return $insert_id; } // create @@ -178,16 +178,16 @@ class shoutBox { * update * This takes a key'd array of data as input and updates a shoutbox entry */ - public static function update($data) { + public static function update($data) { - $id = Dba::escape($data['shout_id']); - $text = Dba::escape(strip_tags($data['comment'])); - $sticky = make_bool($data['sticky']); + $id = Dba::escape($data['shout_id']); + $text = Dba::escape(strip_tags($data['comment'])); + $sticky = make_bool($data['sticky']); $sql = "UPDATE `user_shout` SET `text`='$text', `sticky`='$sticky' WHERE `id`='$id'"; - $db_results = Dba::write($sql); + $db_results = Dba::write($sql); - return true; + return true; } // create @@ -195,12 +195,12 @@ class shoutBox { * format * this function takes the object and reformats some values */ - + public function format() { $this->sticky = ($this->sticky == "0") ? 'No' : 'Yes'; $this->date = date("m\/d\/Y - H:i", $this->date); return true; - + } //format /** @@ -211,10 +211,10 @@ class shoutBox { public function delete($shout_id) { // Delete the shoutbox post - $shout_id = Dba::escape($shout_id); + $shout_id = Dba::escape($shout_id); $sql = "DELETE FROM `user_shout` WHERE `id`='$shout_id'"; $db_results = Dba::write($sql); - + } // delete } // shoutBox class diff --git a/lib/class/song.class.php b/lib/class/song.class.php index df37d9f7..f376c1dc 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -55,7 +55,7 @@ class Song extends database_object implements media { */ public function __construct($id='') { - if (!$id) { return false; } + if (!$id) { return false; } /* Assign id for use in get_info() */ $this->id = intval($id); @@ -63,14 +63,14 @@ class Song extends database_object implements media { /* Get the information from the db */ if ($info = $this->_get_info()) { - foreach ($info as $key=>$value) { - $this->$key = $value; - } + foreach ($info as $key=>$value) { + $this->$key = $value; + } // Format the Type of the song $this->format_type(); } - return true; + return true; } // constructor @@ -85,59 +85,59 @@ class Song extends database_object implements media { if (!is_array($song_ids) OR !count($song_ids)) { return false; } $idlist = '(' . implode(',', $song_ids) . ')'; - + // Song data cache $sql = "SELECT song.id,file,catalog,album,year,artist,". "title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,tag_map.tag_id,". "mbid,". "addition_time FROM `song` " . - "LEFT JOIN `tag_map` ON `tag_map`.`object_id`=`song`.`id` AND `tag_map`.`object_type`='song' " . + "LEFT JOIN `tag_map` ON `tag_map`.`object_id`=`song`.`id` AND `tag_map`.`object_type`='song' " . "WHERE `song`.`id` IN $idlist"; $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('song',$row['id'],$row); - $artists[$row['artist']] = $row['artist']; - $albums[$row['album']] = $row['album']; - if ($row['tag_id']) { - $tags[$row['tag_id']] = $row['tag_id']; - } + parent::add_to_cache('song',$row['id'],$row); + $artists[$row['artist']] = $row['artist']; + $albums[$row['album']] = $row['album']; + if ($row['tag_id']) { + $tags[$row['tag_id']] = $row['tag_id']; + } } Artist::build_cache($artists); - Album::build_cache($albums); - Tag::build_cache($tags); - Tag::build_map_cache('song',$song_ids); + Album::build_cache($albums); + Tag::build_cache($tags); + Tag::build_map_cache('song',$song_ids); // If we're rating this then cache them as well - if (Config::get('ratings')) { - Rating::build_cache('song',$song_ids); - } + if (Config::get('ratings')) { + Rating::build_cache('song',$song_ids); + } // Build a cache for the song's extended table - $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('song_data',$row['song_id'],$row); - } + while ($row = Dba::fetch_assoc($db_results)) { + parent::add_to_cache('song_data',$row['song_id'],$row); + } return true; - + } // build_cache /** * _get_info - * get's the vars for $this out of the database + * get's the vars for $this out of the database * Taken from the object */ private function _get_info() { - - $id = intval($this->id); - if (parent::is_cached('song',$id)) { - return parent::get_from_cache('song',$id); - } + $id = intval($this->id); + + if (parent::is_cached('song',$id)) { + return parent::get_from_cache('song',$id); + } /* Grab the basic information from the catalog and return it */ $sql = "SELECT song.id,file,catalog,album,year,artist,". @@ -148,7 +148,7 @@ class Song extends database_object implements media { $results = Dba::fetch_assoc($db_results); - parent::add_to_cache('song',$id,$results); + parent::add_to_cache('song',$id,$results); return $results; @@ -159,22 +159,22 @@ class Song extends database_object implements media { * This function gathers information from the song_ext_info table and adds it to the * current object */ - public function _get_ext_info() { + public function _get_ext_info() { - $id = intval($this->id); + $id = intval($this->id); - if (parent::is_cached('song_data',$id)) { + if (parent::is_cached('song_data',$id)) { return parent::get_from_cache('song_data',$id); - } + } $sql = "SELECT * FROM song_data WHERE `song_id`='$id'"; - $db_results = Dba::read($sql); + $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); - parent::add_to_cache('song_data',$id,$results); + parent::add_to_cache('song_data',$id,$results); - return $results; + return $results; } // _get_ext_info @@ -182,13 +182,13 @@ class Song extends database_object implements media { * fill_ext_info * This calls the _get_ext_info and then sets the correct vars */ - public function fill_ext_info() { + public function fill_ext_info() { - $info = $this->_get_ext_info(); + $info = $this->_get_ext_info(); - foreach ($info as $key=>$value) { - if ($key != 'song_id') { - $this->$key = $value; + foreach ($info as $key=>$value) { + if ($key != 'song_id') { + $this->$key = $value; } } // end foreach @@ -196,22 +196,22 @@ class Song extends database_object implements media { /** * format_type - * gets the type of song we are trying to - * play, used to set mime headers and to trick + * gets the type of song we are trying to + * play, used to set mime headers and to trick * players into playing them correctly */ - public function format_type($override='') { + public function format_type($override='') { // If we pass an override for downsampling or whatever then use it - if (!empty($override)) { - $this->type = $override; + if (!empty($override)) { + $this->type = $override; } else { - $data = pathinfo($this->file); - $this->type = strtolower($data['extension']); - } - - switch ($this->type) { + $data = pathinfo($this->file); + $this->type = strtolower($data['extension']); + } + + switch ($this->type) { case 'spx': case 'ogg': $this->mime = "application/ogg"; @@ -247,19 +247,19 @@ class Song extends database_object implements media { break; } - return true; + return true; } // format_type - + /** * get_album_name - * gets the name of $this->album, allows passing of id + * gets the name of $this->album, allows passing of id */ public function get_album_name($album_id=0) { - if (!$album_id) { $album_id = $this->album; } + if (!$album_id) { $album_id = $this->album; } $album = new Album($album_id); if ($album->prefix) - return $album->prefix . " " . $album->name; + return $album->prefix . " " . $album->name; else return $album->name; } // get_album_name @@ -270,10 +270,10 @@ class Song extends database_object implements media { */ public function get_artist_name($artist_id=0) { - if (!$artist_id) { $artist_id = $this->artist; } + if (!$artist_id) { $artist_id = $this->artist; } $artist = new Artist($artist_id); if ($artist->prefix) - return $artist->prefix . " " . $artist->name; + return $artist->prefix . " " . $artist->name; else return $artist->name; @@ -284,12 +284,12 @@ class Song extends database_object implements media { * 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 */ - public function has_flag() { + public function has_flag() { $sql = "SELECT `id` FROM `flagged` WHERE `object_type`='song' AND `object_id`='$this->id' LIMIT 1"; $db_results = Dba::read($sql); - if (Dba::fetch_assoc($db_results)) { + if (Dba::fetch_assoc($db_results)) { return true; } @@ -302,9 +302,9 @@ class Song extends database_object implements media { * this checks to see if the current object has been played * if not then it sets it to played */ - public function set_played() { + public function set_played() { - if ($this->played) { + if ($this->played) { return true; } @@ -314,12 +314,12 @@ class Song extends database_object implements media { return true; } // set_played - + /** * compare_song_information * this compares the new ID3 tags of a file against * the ones in the database to see if they have changed - * it returns false if nothing has changes, or the true + * it returns false if nothing has changes, or the true * if they have. Static because it doesn't need this */ public static function compare_song_information($song,$new_song) { @@ -327,81 +327,81 @@ class Song extends database_object implements media { // Remove some stuff we don't care about unset($song->catalog,$song->played,$song->enabled,$song->addition_time,$song->update_time,$song->type); - $string_array = array('title','comment','lyrics'); - $skip_array = array('id','tag_id','mime','mb_artistid','mbid'); + $string_array = array('title','comment','lyrics'); + $skip_array = array('id','tag_id','mime','mb_artistid','mbid'); // Pull out all the currently set vars - $fields = get_object_vars($song); + $fields = get_object_vars($song); // Foreach them - foreach ($fields as $key=>$value) { - if (in_array($key,$skip_array)) { continue; } + foreach ($fields as $key=>$value) { + if (in_array($key,$skip_array)) { continue; } // If it's a stringie thing - if (in_array($key,$string_array)) { - if (trim(stripslashes($song->$key)) != trim(stripslashes($new_song->$key))) { - $array['change'] = true; + if (in_array($key,$string_array)) { + if (trim(stripslashes($song->$key)) != trim(stripslashes($new_song->$key))) { + $array['change'] = true; $array['element'][$key] = 'OLD: ' . $song->$key . ' --> ' . $new_song->$key; } } // in array of stringies - else { - if ($song->$key != $new_song->$key) { - $array['change'] = true; + else { + if ($song->$key != $new_song->$key) { + $array['change'] = true; $array['element'][$key] = 'OLD:' . $song->$key . ' --> ' . $new_song->$key; - } + } } // end else } // end foreach - if ($array['change']) { - debug_event('song-diff',print_r($array['element'],1),'5','ampache-catalog'); - } + if ($array['change']) { + debug_event('song-diff',print_r($array['element'],1),'5','ampache-catalog'); + } return $array; } // compare_song_information - + /** * update * This takes a key'd array of data does any cleaning it needs to - * do and then calls the helper functions as needed. This will also + * do and then calls the helper functions as needed. This will also * cause the song to be flagged */ - public function update($data) { + public function update($data) { - foreach ($data as $key=>$value) { - switch ($key) { + foreach ($data as $key=>$value) { + switch ($key) { case 'artist': // Don't do anything if we've negative one'd this baby - if ($value == '-1') { - $value = Catalog::check_artist($data['artist_name'], $data['mb_artistid']); - } + if ($value == '-1') { + $value = Catalog::check_artist($data['artist_name'], $data['mb_artistid']); + } case 'album': - if ($value == '-1') { - $value = Catalog::check_album($data['album_name'], $data['year'], $data['disk'], $data['mb_albumid']); - } - case 'title': + if ($value == '-1') { + $value = Catalog::check_album($data['album_name'], $data['year'], $data['disk'], $data['mb_albumid']); + } + case 'title': case 'track': // Check to see if it needs to be updated - if ($value != $this->$key) { - $function = 'update_' . $key; - self::$function($value,$this->id); - $this->$key = $value; - $updated = 1; - } + if ($value != $this->$key) { + $function = 'update_' . $key; + self::$function($value,$this->id); + $this->$key = $value; + $updated = 1; + } break; - default: + default: // Rien a faire break; } // end whitelist } // end foreach // If a field was changed then we need to flag this mofo - if ($updated) { - Flag::add($this->id,'song','retag','Interface Update'); - } + if ($updated) { + Flag::add($this->id,'song','retag','Interface Update'); + } - return true; + return true; } // update @@ -414,36 +414,36 @@ class Song extends database_object implements media { */ public static function update_song($song_id, $new_song) { - $title = Dba::escape($new_song->title); - $bitrate = Dba::escape($new_song->bitrate); - $rate = Dba::escape($new_song->rate); - $mode = Dba::escape($new_song->mode); - $size = Dba::escape($new_song->size); - $time = Dba::escape($new_song->time); - $track = Dba::escape($new_song->track); + $title = Dba::escape($new_song->title); + $bitrate = Dba::escape($new_song->bitrate); + $rate = Dba::escape($new_song->rate); + $mode = Dba::escape($new_song->mode); + $size = Dba::escape($new_song->size); + $time = Dba::escape($new_song->time); + $track = Dba::escape($new_song->track); $mbid = Dba::escape($new_song->mbid); - $artist = Dba::escape($new_song->artist); - $album = Dba::escape($new_song->album); - $year = Dba::escape($new_song->year); - $song_id = Dba::escape($song_id); - $update_time = time(); - + $artist = Dba::escape($new_song->artist); + $album = Dba::escape($new_song->album); + $year = Dba::escape($new_song->year); + $song_id = Dba::escape($song_id); + $update_time = time(); - $sql = "UPDATE `song` SET `album`='$album', `year`='$year', `artist`='$artist', " . - "`title`='$title', `bitrate`='$bitrate', `rate`='$rate', `mode`='$mode', " . - "`size`='$size', `time`='$time', `track`='$track', " . + + $sql = "UPDATE `song` SET `album`='$album', `year`='$year', `artist`='$artist', " . + "`title`='$title', `bitrate`='$bitrate', `rate`='$rate', `mode`='$mode', " . + "`size`='$size', `time`='$time', `track`='$track', " . "`mbid`='$mbid', " . - "`update_time`='$update_time' WHERE `id`='$song_id'"; - $db_results = Dba::write($sql); - + "`update_time`='$update_time' WHERE `id`='$song_id'"; + $db_results = Dba::write($sql); - $comment = Dba::escape($new_song->comment); - $language = Dba::escape($new_song->language); - $lyrics = Dba::escape($new_song->lyrics); - - $sql = "UPDATE `song_data` SET `lyrics`='$lyrics', `language`='$language', `comment`='$comment' " . - "WHERE `song_id`='$song_id'"; - $db_results = Dba::write($sql); + + $comment = Dba::escape($new_song->comment); + $language = Dba::escape($new_song->language); + $lyrics = Dba::escape($new_song->lyrics); + + $sql = "UPDATE `song_data` SET `lyrics`='$lyrics', `language`='$language', `comment`='$comment' " . + "WHERE `song_id`='$song_id'"; + $db_results = Dba::write($sql); } // update_song @@ -452,18 +452,18 @@ class Song extends database_object implements media { * update the year tag */ public static function update_year($new_year,$song_id) { - - self::_update_item('year',$new_year,$song_id,'50'); - + + self::_update_item('year',$new_year,$song_id,'50'); + } // update_year /** * update_language * This updates the language tag of the song */ - public static function update_language($new_lang,$song_id) { + public static function update_language($new_lang,$song_id) { - self::_update_ext_item('language',$new_lang,$song_id,'50'); + self::_update_ext_item('language',$new_lang,$song_id,'50'); } // update_language @@ -471,19 +471,19 @@ class Song extends database_object implements media { * update_comment * updates the comment field */ - public static function update_comment($new_comment,$song_id) { - + public static function update_comment($new_comment,$song_id) { + self::_update_ext_item('comment',$new_comment,$song_id,'50'); - + } // update_comment /** * update_lyrics * updates the lyrics field */ - public static function update_lyrics($new_lyrics,$song_id) { - - self::_update_ext_item('lyrics',$new_lyrics,$song_id,'50'); + public static function update_lyrics($new_lyrics,$song_id) { + + self::_update_ext_item('lyrics',$new_lyrics,$song_id,'50'); } // update_lyrics @@ -492,9 +492,9 @@ class Song extends database_object implements media { * updates the title field */ public static function update_title($new_title,$song_id) { - + self::_update_item('title',$new_title,$song_id,'50'); - + } // update_title /** @@ -502,7 +502,7 @@ class Song extends database_object implements media { * updates the bitrate field */ public static function update_bitrate($new_bitrate,$song_id) { - + self::_update_item('bitrate',$new_bitrate,$song_id,'50'); } // update_bitrate @@ -512,7 +512,7 @@ class Song extends database_object implements media { * updates the rate field */ public static function update_rate($new_rate,$song_id) { - + self::_update_item('rate',$new_rate,$song_id,'50'); } // update_rate @@ -531,8 +531,8 @@ class Song extends database_object implements media { * update_size * updates the size field */ - public static function update_size($new_size,$song_id) { - + public static function update_size($new_size,$song_id) { + self::_update_item('size',$new_size,$song_id,'50'); } // update_size @@ -541,8 +541,8 @@ class Song extends database_object implements media { * update_time * updates the time field */ - public static function update_time($new_time,$song_id) { - + public static function update_time($new_time,$song_id) { + self::_update_item('time',$new_time,$song_id,'50'); } // update_time @@ -551,7 +551,7 @@ class Song extends database_object implements media { * update_track * this updates the track field */ - public static function update_track($new_track,$song_id) { + public static function update_track($new_track,$song_id) { self::_update_item('track',$new_track,$song_id,'50'); @@ -577,7 +577,7 @@ class Song extends database_object implements media { * update_album * updates the album field */ - public static function update_album($new_album,$song_id) { + public static function update_album($new_album,$song_id) { self::_update_item('album',$new_album,$song_id,'50'); @@ -599,7 +599,7 @@ class Song extends database_object implements media { * update_played * sets the played flag */ - public static function update_played($new_played,$song_id) { + public static function update_played($new_played,$song_id) { self::_update_item('played',$new_played,$song_id,'25'); @@ -610,14 +610,14 @@ class Song extends database_object implements media { * sets the enabled flag */ public static function update_enabled($new_enabled,$song_id) { - + self::_update_item('enabled',$new_enabled,$song_id,'75'); } // update_enabled /** * _update_item - * This is a private function that should only be called from within the song class. + * This is a private function that should only be called from within the song class. * It takes a field, value song id and level. first and foremost it checks the level * against $GLOBALS['user'] to make sure they are allowed to update this record * it then updates it and sets $this->{$field} to the new value @@ -628,7 +628,7 @@ class Song extends database_object implements media { if (!Access::check('interface',$level)) { return false; } /* Can't update to blank */ - if (!strlen(trim($value)) && $field != 'comment') { return false; } + if (!strlen(trim($value)) && $field != 'comment') { return false; } $value = Dba::escape($value); @@ -644,17 +644,17 @@ class Song extends database_object implements media { * This updates a song record that is housed in the song_ext_info table * These are items that aren't used normally, and often large/informational only */ - private static function _update_ext_item($field,$value,$song_id,$level) { + private static function _update_ext_item($field,$value,$song_id,$level) { /* Check them rights boy! */ - if (!Access::check('interface',$level)) { return false; } - - $value = Dba::escape($value); + if (!Access::check('interface',$level)) { return false; } + + $value = Dba::escape($value); $sql = "UPDATE `song_data` SET `$field`='$value' WHERE `song_id`='$song_id'"; - $db_results = Dba::write($sql); + $db_results = Dba::write($sql); - return true; + return true; } // _update_ext_item @@ -664,9 +664,9 @@ class Song extends database_object implements media { * and does a ton of formating on it creating f_??? variables on the current * object */ - public function format() { + public function format() { - $this->fill_ext_info(); + $this->fill_ext_info(); // Format the filename preg_match("/^.*\/(.*?)$/",$this->file, $short); @@ -683,11 +683,11 @@ class Song extends database_object implements media { // Format the title $this->f_title = truncate_with_ellipsis($this->title,Config::get('ellipse_threshold_title')); - // Create Links for the different objects + // Create Links for the different objects $this->link = Config::get('web_path') . "/song.php?action=show_song&song_id=" . $this->id; $this->f_link = "link) . "\" title=\"" . scrub_out($this->title) . "\"> " . scrub_out($this->f_title) . ""; $this->f_album_link = "album . "\" title=\"" . scrub_out($this->f_album_full) . "\"> " . scrub_out($this->f_album) . ""; - $this->f_artist_link = "artist . "\" title=\"" . scrub_out($this->f_artist_full) . "\"> " . scrub_out($this->f_artist) . ""; + $this->f_artist_link = "artist . "\" title=\"" . scrub_out($this->f_artist_full) . "\"> " . scrub_out($this->f_artist) . ""; // Format the Bitrate $this->f_bitrate = intval($this->bitrate/1000) . "-" . strtoupper($this->mode); @@ -698,13 +698,13 @@ class Song extends database_object implements media { $this->f_time = $min . ":" . $sec; // Format the track (there isn't really anything to do here) - $this->f_track = $this->track; + $this->f_track = $this->track; // Get the top tags - $tags = Tag::get_top_tags('song',$this->id); - $this->tags = $tags; - - $this->f_tags = Tag::get_display($tags,$this->id,'song'); + $tags = Tag::get_top_tags('song',$this->id); + $this->tags = $tags; + + $this->f_tags = Tag::get_display($tags,$this->id,'song'); // Format the size $this->f_size = sprintf("%.2f",($this->size/1048576)); @@ -715,21 +715,21 @@ class Song extends database_object implements media { /** * format_pattern - * This reformates the song information based on the catalog - * rename patterns + * This reformates the song information based on the catalog + * rename patterns */ - public function format_pattern() { + public function format_pattern() { $extension = ltrim(substr($this->file,strlen($this->file)-4,4),"."); - $catalog = new Catalog($this->catalog); + $catalog = new Catalog($this->catalog); // If we don't have a rename pattern then just return it - if (!trim($catalog->rename_pattern)) { + if (!trim($catalog->rename_pattern)) { $this->f_pattern = $this->title; $this->f_file = $this->title . '.' . $extension; - return; - } + return; + } /* Create the filename that this file should have */ $album = $this->f_album_full; @@ -743,10 +743,10 @@ class Song extends database_object implements media { $content_array = array($artist,$album,$title,$track,$year,'-','-'); $rename_pattern = str_replace($replace_array,$content_array,$catalog->rename_pattern); - + $rename_pattern = preg_replace("[\-\:\!]","_",$rename_pattern); - - $this->f_pattern = $rename_pattern; + + $this->f_pattern = $rename_pattern; $this->f_file = $rename_pattern . "." . $extension; } // format_pattern @@ -756,20 +756,20 @@ class Song extends database_object implements media { * This returns all of the 'data' fields for this object, we need to filter out some that we don't * want to present to a user, and add some that don't exist directly on the object but are related */ - public static function get_fields() { + public static function get_fields() { - $fields = get_class_vars('Song'); + $fields = get_class_vars('Song'); - unset($fields['id'],$fields['_transcoded'],$fields['_fake'],$fields['cache_hit'],$fields['mime'],$fields['type']); + unset($fields['id'],$fields['_transcoded'],$fields['_fake'],$fields['cache_hit'],$fields['mime'],$fields['type']); // Some additional fields - $fields['tag'] = true; - $fields['catalog'] = true; + $fields['tag'] = true; + $fields['catalog'] = true; //FIXME: These are here to keep the ideas, don't want to have to worry about them for now -// $fields['rating'] = true; -// $fields['recently Played'] = true; +// $fields['rating'] = true; +// $fields['recently Played'] = true; - return $fields; + return $fields; } // get_fields @@ -777,35 +777,35 @@ class Song extends database_object implements media { * get_from_path * This returns all of the songs that exist under the specified path */ - public static function get_from_path($path) { + public static function get_from_path($path) { - $path = Dba::escape($path); + $path = Dba::escape($path); - $sql = "SELECT * FROM `song` WHERE `file` LIKE '$path%'"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `song` WHERE `file` LIKE '$path%'"; + $db_results = Dba::read($sql); - $songs = array(); + $songs = array(); - while ($row = Dba::fetch_assoc($db_results)) { - $songs[] = $row['id']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $songs[] = $row['id']; + } - return $songs; + return $songs; } // get_from_path /** * @function get_rel_path * @discussion returns the path of the song file stripped of the catalog path - * used for mpd playback + * used for mpd playback */ public function get_rel_path($file_path=0,$catalog_id=0) { - if (!$file_path) { + if (!$file_path) { $info = $this->_get_info(); $file_path = $info->file; } - if (!$catalog_id) { + if (!$catalog_id) { $catalog_id = $info->catalog; } $catalog = new Catalog( $catalog_id ); @@ -817,29 +817,29 @@ class Song extends database_object implements media { } // get_rel_path - /*! + /*! @function fill_info @discussion this takes the $results from getid3 and attempts to fill as much information as possible from the file name using the pattern set in the current catalog */ - function fill_info($results,$pattern,$catalog_id,$key) { + function fill_info($results,$pattern,$catalog_id,$key) { $filename = $this->get_rel_path($results['file'],$catalog_id); - if (!strlen($results[$key]['title'])) { + if (!strlen($results[$key]['title'])) { $results[$key]['title'] = $this->get_info_from_filename($filename,$pattern,"%t"); } - if (!strlen($results[$key]['track'])) { + if (!strlen($results[$key]['track'])) { $results[$key]['track'] = $this->get_info_from_filename($filename,$pattern,"%T"); } - if (!strlen($results[$key]['year'])) { + if (!strlen($results[$key]['year'])) { $results[$key]['year'] = $this->get_info_from_filename($filename,$pattern,"%y"); } - if (!strlen($results[$key]['album'])) { + if (!strlen($results[$key]['album'])) { $results[$key]['album'] = $this->get_info_from_filename($filename,$pattern,"%A"); } - if (!strlen($results[$key]['artist'])) { + if (!strlen($results[$key]['artist'])) { $results[$key]['artist'] = $this->get_info_from_filename($filename,$pattern,"%a"); } @@ -847,11 +847,11 @@ class Song extends database_object implements media { } // fill_info - /*! + /*! @function get_info_from_filename @discussion get information from a filename based on pattern */ - function get_info_from_filename($file,$pattern,$tag) { + function get_info_from_filename($file,$pattern,$tag) { $preg_pattern = str_replace("$tag","(.+)",$pattern); $preg_pattern = preg_replace("/\%\w/",".+",$preg_pattern); @@ -869,20 +869,20 @@ class Song extends database_object implements media { * a stream URL taking into account the downsmapling mojo and everything * else, this is the true function */ - public static function play_url($oid) { + public static function play_url($oid) { - $song = new Song($oid); - $user_id = $GLOBALS['user']->id ? scrub_out($GLOBALS['user']->id) : '-1'; + $song = new Song($oid); + $user_id = $GLOBALS['user']->id ? scrub_out($GLOBALS['user']->id) : '-1'; $type = $song->type; - // Required for some versions of winamp that won't work if the stream doesn't end in - // .ogg This will not break any properly working player, don't report this as a bug! - if ($song->type == 'flac') { $type = 'ogg'; } + // Required for some versions of winamp that won't work if the stream doesn't end in + // .ogg This will not break any properly working player, don't report this as a bug! + if ($song->type == 'flac') { $type = 'ogg'; } $song->format(); $song_name = rawurlencode($song->f_artist_full . " - " . $song->title . "." . $type); - + $url = Stream::get_base_url() . "oid=$song->id&uid=$user_id$session_string$ds_string&name=/$song_name"; return $url; @@ -895,23 +895,23 @@ class Song extends database_object implements media { * used by the API, and used to parse out stream urls for localplay * right now just gets song id might do more later, hence the complexity */ - public static function parse_song_url($url) { + public static function parse_song_url($url) { // We only care about the question mark stuff - $query = parse_url($url,PHP_URL_QUERY); + $query = parse_url($url,PHP_URL_QUERY); - $elements = explode("&",$query); + $elements = explode("&",$query); - foreach ($elements as $items) { - list($key,$value) = explode("=",$items); - if ($key == 'oid') { - return $value; - } - } // end foreach + foreach ($elements as $items) { + list($key,$value) = explode("=",$items); + if ($key == 'oid') { + return $value; + } + } // end foreach - return false; + return false; - } // parse_song_url + } // parse_song_url /** * get_recently_played @@ -919,28 +919,28 @@ class Song extends database_object implements media { * 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='') { + public static function get_recently_played($user_id='') { - if ($user_id) { - $user_limit = " AND `object_count`.`user`='" . Dba::escape($user_id) . "'"; - } + if ($user_id) { + $user_limit = " AND `object_count`.`user`='" . Dba::escape($user_id) . "'"; + } - $sql = "SELECT `object_count`.`object_id`,`object_count`.`user`,`object_count`.`object_type`, " . - "`object_count`.`date` " . - "FROM `object_count` " . - "WHERE `object_type`='song'$user_limit " . + $sql = "SELECT `object_count`.`object_id`,`object_count`.`user`,`object_count`.`object_type`, " . + "`object_count`.`date` " . + "FROM `object_count` " . + "WHERE `object_type`='song'$user_limit " . "ORDER BY `object_count`.`date` DESC "; - $db_results = Dba::read($sql); + $db_results = Dba::read($sql); $results = array(); - - while ($row = Dba::fetch_assoc($db_results)) { - if (isset($results[$row['object_id']])) { continue; } - $results[$row['object_id']] = $row; - if (count($results) >= Config::get('popular_threshold')) { break; } - } - return $results; + while ($row = Dba::fetch_assoc($db_results)) { + if (isset($results[$row['object_id']])) { continue; } + $results[$row['object_id']] = $row; + if (count($results) >= Config::get('popular_threshold')) { break; } + } + + return $results; } // get_recently_played @@ -949,25 +949,25 @@ class Song extends database_object implements media { * This returns true/false if this can be nativly streamed */ public function native_stream() { - + if ($this->_transcode) { return false; } $conf_var = 'transcode_' . $this->type; - $conf_type = 'transcode_' . $this->type . '_target'; + $conf_type = 'transcode_' . $this->type . '_target'; + + if (Config::get($conf_var)) { + $this->_transcode = true; + debug_event('auto_transcode','Transcoding to ' . $this->type,'5'); + return false; + } - if (Config::get($conf_var)) { - $this->_transcode = true; - debug_event('auto_transcode','Transcoding to ' . $this->type,'5'); - return false; - } - return true; } // end native_stream - + /** * stream_cmd - * test if the song type streams natively and + * test if the song type streams natively and * if not returns a transcoding command from the config * we can't use this->type because its been formated for the * downsampling @@ -976,18 +976,18 @@ class Song extends database_object implements media { // Find the target for this transcode $conf_type = 'transcode_' . $this->type . '_target'; - $stream_cmd = 'transcode_cmd_' . $this->type; + $stream_cmd = 'transcode_cmd_' . $this->type; $this->format_type(Config::get($conf_type)); - if (Config::get($stream_cmd)) { + if (Config::get($stream_cmd)) { return $stream_cmd; - } - else { - debug_event('Downsample','Error: Transcode ' . $stream_cmd . ' for ' . $this->type . ' not found, using downsample','2'); } - + else { + debug_event('Downsample','Error: Transcode ' . $stream_cmd . ' for ' . $this->type . ' not found, using downsample','2'); + } + return false; - + } // end stream_cmd } // end of song class diff --git a/lib/class/stats.class.php b/lib/class/stats.class.php index 88556f7d..61b61a17 100644 --- a/lib/class/stats.class.php +++ b/lib/class/stats.class.php @@ -24,13 +24,13 @@ * Stats * this class handles the object_count * Stuff, before this was done in the user class - * but that's not good, all done through here. + * but that's not good, all done through here. */ class Stats { /* Base vars */ - var $id; - var $object_type; + var $id; + var $object_type; var $object_id; var $date; var $user; @@ -40,7 +40,7 @@ class Stats { * Constructor * This doesn't do anything currently */ - public function __construct() { + public function __construct() { return true; @@ -49,25 +49,25 @@ class Stats { /** * insert * This inserts a new record for the specified object - * with the specified information, amazing! + * with the specified information, amazing! */ - public static function insert($type,$oid,$user) { + public static function insert($type,$oid,$user) { $type = self::validate_type($type); $oid = Dba::escape($oid); - $user = Dba::escape($user); + $user = Dba::escape($user); $date = time(); - $sql = "INSERT INTO `object_count` (`object_type`,`object_id`,`date`,`user`) " . + $sql = "INSERT INTO `object_count` (`object_type`,`object_id`,`date`,`user`) " . " VALUES ('$type','$oid','$date','$user')"; $db_results = Dba::write($sql); - if (!$db_results) { + if (!$db_results) { debug_event('statistics','Unabled to insert statistics:' . $sql,'3'); - } + } } // insert - + /** * get_last_song * This returns the full data for the last song that was played, including when it @@ -75,18 +75,18 @@ class Stats { * if we should re-submit or if this is a duplicate / if it's too soon. This takes an * optional user_id because when streaming we don't have $GLOBALS() */ - public static function get_last_song($user_id='') { + public static function get_last_song($user_id='') { - $user_id = $user_id ? $user_id : $GLOBALS['user']->id; + $user_id = $user_id ? $user_id : $GLOBALS['user']->id; $user_id = Dba::escape($user_id); - $sql = "SELECT * FROM `object_count` WHERE `user`='$user_id' AND `object_type`='song' ORDER BY `date` DESC LIMIT 1"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `object_count` WHERE `user`='$user_id' AND `object_type`='song' ORDER BY `date` DESC LIMIT 1"; + $db_results = Dba::read($sql); - $results = Dba::fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); - return $results; + return $results; } // get_last_song @@ -95,25 +95,25 @@ class Stats { * This returns the objects that have happened for $user_id sometime after $time * used primarly by the democratic cooldown code */ - public static function get_object_history($user_id='',$time) { + public static function get_object_history($user_id='',$time) { $user_id = $user_id ? $user_id : $GLOBALS['user']->id; $user_id = Dba::escape($user_id); - $time = Dba::escape($time); + $time = Dba::escape($time); - $sql = "SELECT * FROM `object_count` WHERE `user`='$user_id' AND `object_type`='song' AND `date`>='$time' " . - "ORDER BY `date` DESC"; - $db_results = Dba::read($sql); + $sql = "SELECT * FROM `object_count` WHERE `user`='$user_id' AND `object_type`='song' AND `date`>='$time' " . + "ORDER BY `date` DESC"; + $db_results = Dba::read($sql); - $results = array(); + $results = array(); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['object_id']; - } + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['object_id']; + } - return $results; + return $results; } // get_object_history @@ -122,31 +122,31 @@ class Stats { * This returns the top X for type Y from the * last conf('stats_threshold') days */ - public static function get_top($type,$count='',$threshold = '') { + public static function get_top($type,$count='',$threshold = '') { /* If they don't pass one, then use the preference */ - if (!$threshold) { + if (!$threshold) { $threshold = Config::get('stats_threshold'); } - if (!$count) { - $count = Config::get('popular_threshold'); - } + if (!$count) { + $count = Config::get('popular_threshold'); + } $count = intval($count); $type = self::validate_type($type); $date = time() - (86400*$threshold); - + /* Select Top objects counting by # of rows */ - $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . + $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . " WHERE object_type='$type' AND date >= '$date'" . " GROUP BY object_id ORDER BY `count` DESC LIMIT $count"; $db_results = Dba::read($sql); $results = array(); - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = $row['object_id']; + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = $row['object_id']; } return $results; @@ -156,34 +156,34 @@ class Stats { /** * get_user * This gets all stats for atype based on user with thresholds and all - * If full is passed, doesn't limit based on date + * If full is passed, doesn't limit based on date */ - public static function get_user($count,$type,$user,$full='') { + public static function get_user($count,$type,$user,$full='') { $count = intval($count); $type = self::validate_type($type); $user = Dba::escape($user); - - /* If full then don't limit on date */ - if ($full) { + + /* If full then don't limit on date */ + if ($full) { $date = '0'; } - else { + else { $date = time() - (86400*Config::get('stats_threshold')); } /* Select Objects based on user */ - //FIXME:: Requires table scan, look at improving - $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . - " WHERE object_type='$type' AND date >= '$date' AND user = '$user'" . + //FIXME:: Requires table scan, look at improving + $sql = "SELECT object_id,COUNT(id) AS `count` FROM object_count" . + " WHERE object_type='$type' AND date >= '$date' AND user = '$user'" . " GROUP BY object_id ORDER BY `count` DESC LIMIT $count"; $db_results = Dba::read($sql); - + $results = array(); - while ($r = Dba::fetch_assoc($db_results)) { + while ($r = Dba::fetch_assoc($db_results)) { $results[] = $r; - } + } return $results; @@ -194,15 +194,15 @@ class Stats { * This function takes a type and returns only those * which are allowed, ensures good data gets put into the db */ - public static function validate_type($type) { + public static function validate_type($type) { - switch ($type) { + switch ($type) { case 'artist': case 'album': case 'genre': case 'song': - case 'video': - return $type; + case 'video': + return $type; default: return 'song'; break; @@ -215,24 +215,24 @@ class Stats { * This returns an array of the newest artists/albums/whatever * in this ampache instance */ - public static function get_newest($type,$limit='') { + public static function get_newest($type,$limit='') { if (!$limit) { $limit = Config::get('popular_threshold'); } - - $type = self::validate_type($type); - $object_name = ucfirst($type); - $sql = "SELECT DISTINCT($type) FROM `song` ORDER BY `addition_time` DESC " . - "LIMIT $limit"; - $db_results = Dba::read($sql); + $type = self::validate_type($type); + $object_name = ucfirst($type); - $items = array(); + $sql = "SELECT DISTINCT($type) FROM `song` ORDER BY `addition_time` DESC " . + "LIMIT $limit"; + $db_results = Dba::read($sql); - while ($row = Dba::fetch_row($db_results)) { - $items[] = $row['0']; + $items = array(); + + while ($row = Dba::fetch_row($db_results)) { + $items[] = $row['0']; } // end while results - return $items; + return $items; } // get_newest diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php index 3ae532e1..1b4a7225 100644 --- a/lib/class/stream.class.php +++ b/lib/class/stream.class.php @@ -3,7 +3,7 @@ /* Copyright (c) Ampache.org - All rights reserved. + 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 @@ -16,7 +16,7 @@ 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. + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ @@ -33,15 +33,15 @@ class Stream { public $type; public $web_path; public $media = array(); - public $urls = array(); + public $urls = array(); public $sess; - public $user_id; + public $user_id; // Generate once an object is constructed - public static $session; + public static $session; // Let's us tell if the session has been activated - private static $session_inserted; + private static $session_inserted; /** * Constructor for the stream class takes a type and an array @@ -52,8 +52,8 @@ class Stream { $this->type = $type; $this->media = $media_ids; $this->user_id = $GLOBALS['user']->id; - - if (!is_array($this->media)) { settype($this->media,'array'); } + + if (!is_array($this->media)) { settype($this->media,'array'); } } // Constructor @@ -64,26 +64,26 @@ class Stream { */ public function start() { - if (!count($this->media) AND !count($this->urls)) { + if (!count($this->media) AND !count($this->urls)) { debug_event('stream','Error: No Songs Passed on ' . $this->type . ' stream','2'); - return false; + return false; } // We're starting insert the session into session_stream - if (!self::get_session()) { - debug_event('stream','Session Insertion failure, aborting','3'); - return false; + if (!self::get_session()) { + debug_event('stream','Session Insertion failure, aborting','3'); + return false; } $methods = get_class_methods('Stream'); - $create_function = "create_" . $this->type; + $create_function = "create_" . $this->type; // If in the class, call it if (in_array($create_function,$methods)) { $this->{$create_function}(); } // Assume M3u incase they've pooched the type - else { + else { $this->create_m3u(); } @@ -91,14 +91,14 @@ class Stream { /** * add_urls - * Add an array of urls, it may be a single one who knows, this + * Add an array of urls, it may be a single one who knows, this * is used for things that aren't coming from media objects */ - public function add_urls($urls=array()) { + public function add_urls($urls=array()) { - if (!is_array($urls)) { return false; } - - $this->urls = array_merge($urls,$this->urls); + if (!is_array($urls)) { return false; } + + $this->urls = array_merge($urls,$this->urls); } // manual_url_add @@ -106,13 +106,13 @@ class Stream { * get_session * This returns the current stream session */ - public static function get_session() { + public static function get_session() { - if (!self::$session_inserted) { + if (!self::$session_inserted) { self::insert_session(self::$session); - } + } - return self::$session; + return self::$session; } // get_session @@ -122,10 +122,10 @@ class Stream { * an additional session into the database, should be called * with care */ - public static function set_session($sid) { + public static function set_session($sid) { - self::$session_inserted = true; - self::$session=$sid; + self::$session_inserted = true; + self::$session=$sid; } // set_session @@ -133,42 +133,42 @@ class Stream { * insert_session * This inserts a row into the session_stream table */ - public static function insert_session($sid='',$uid='') { + public static function insert_session($sid='',$uid='') { - $sid = $sid ? Dba::escape($sid) : Dba::escape(self::$session); - $uid = $uid ? Dba::escape($uid) : Dba::escape($GLOBALS['user']->id); + $sid = $sid ? Dba::escape($sid) : Dba::escape(self::$session); + $uid = $uid ? Dba::escape($uid) : Dba::escape($GLOBALS['user']->id); - $expire = time() + Config::get('stream_length'); + $expire = time() + Config::get('stream_length'); - $sql = "INSERT INTO `session_stream` (`id`,`expire`,`user`) " . - "VALUES('$sid','$expire','$uid')"; - $db_results = Dba::write($sql); + $sql = "INSERT INTO `session_stream` (`id`,`expire`,`user`) " . + "VALUES('$sid','$expire','$uid')"; + $db_results = Dba::write($sql); - if (!$db_results) { return false; } + if (!$db_results) { return false; } - self::$session_inserted = true; + self::$session_inserted = true; - return true; + return true; } // insert_session /** * session_exists - * This checks to see if the passed stream session exists and is valid + * This checks to see if the passed stream session exists and is valid */ - public static function session_exists($sid) { + public static function session_exists($sid) { - $sid = Dba::escape($sid); - $time = time(); + $sid = Dba::escape($sid); + $time = time(); - $sql = "SELECT * FROM `session_stream` WHERE `id`='$sid' AND `expire` > '$time'"; - $db_results = Dba::write($sql); + $sql = "SELECT * FROM `session_stream` WHERE `id`='$sid' AND `expire` > '$time'"; + $db_results = Dba::write($sql); - if ($row = Dba::fetch_assoc($db_results)) { - return true; - } - - return false; + if ($row = Dba::fetch_assoc($db_results)) { + return true; + } + + return false; } // session_exists @@ -177,49 +177,49 @@ class Stream { * This function performes the garbage collection stuff, run on extend and on now playing refresh * There is an array of agents that we will never GC because of their nature, MPD being the best example */ - public static function gc_session($ip='',$agent='',$uid='',$sid='') { + public static function gc_session($ip='',$agent='',$uid='',$sid='') { - $append_array = array('MPD'); + $append_array = array('MPD'); - $time = time(); - $sql = "DELETE FROM `session_stream` WHERE `expire` < '$time'"; - $db_results = Dba::write($sql); - - foreach ($append_array as $append_agent) { - if (strstr(strtoupper($agent),$append_agent)) { + $time = time(); + $sql = "DELETE FROM `session_stream` WHERE `expire` < '$time'"; + $db_results = Dba::write($sql); + + foreach ($append_array as $append_agent) { + if (strstr(strtoupper($agent),$append_agent)) { // We're done here jump ship! - return true; - } + return true; + } } // end foreach // We need all of this to run this query - if ($ip AND $agent AND $uid AND $sid) { - $sql = "DELETE FROM `session_stream` WHERE `ip`='$ip' AND `agent`='$agent' AND `user`='$uid' AND `id` != '$sid'"; - $db_results = Dba::write($sql); - } + if ($ip AND $agent AND $uid AND $sid) { + $sql = "DELETE FROM `session_stream` WHERE `ip`='$ip' AND `agent`='$agent' AND `user`='$uid' AND `id` != '$sid'"; + $db_results = Dba::write($sql); + } - } // gc_session + } // gc_session /** * extend_session * This takes the passed sid and does a replace into also setting the user * agent and IP also do a little GC in this function */ - public static function extend_session($sid,$uid) { + public static function extend_session($sid,$uid) { - $expire = time() + Config::get('stream_length'); - $sid = Dba::escape($sid); - $agent = Dba::escape($_SERVER['HTTP_USER_AGENT']); - $ip = Dba::escape(inet_pton($_SERVER['REMOTE_ADDR'])); - $uid = Dba::escape($uid); + $expire = time() + Config::get('stream_length'); + $sid = Dba::escape($sid); + $agent = Dba::escape($_SERVER['HTTP_USER_AGENT']); + $ip = Dba::escape(inet_pton($_SERVER['REMOTE_ADDR'])); + $uid = Dba::escape($uid); - $sql = "UPDATE `session_stream` SET `expire`='$expire', `agent`='$agent', `ip`='$ip' " . - "WHERE `id`='$sid'"; - $db_results = Dba::write($sql); + $sql = "UPDATE `session_stream` SET `expire`='$expire', `agent`='$agent', `ip`='$ip' " . + "WHERE `id`='$sid'"; + $db_results = Dba::write($sql); - self::gc_session($ip,$agent,$uid,$sid); + self::gc_session($ip,$agent,$uid,$sid); - return true; + return true; } // extend_session @@ -234,16 +234,16 @@ class Stream { header("Content-Type: audio/x-mpegurl;"); // Flip for the poping! - asort($this->urls); + asort($this->urls); /* Foreach songs */ - foreach ($this->media as $element) { + foreach ($this->media as $element) { $type = array_shift($element); - echo call_user_func(array($type,'play_url'),array_shift($element)) . "\n"; + echo call_user_func(array($type,'play_url'),array_shift($element)) . "\n"; } // end foreach /* Foreach the additional URLs */ - foreach ($this->urls as $url) { + foreach ($this->urls as $url) { echo "$url\n"; } @@ -254,7 +254,7 @@ class Stream { * creates an m3u file, this includes the EXTINFO and as such can be * large with very long playlsits */ - public function create_m3u() { + public function create_m3u() { // Send the client an m3u playlist header("Cache-control: public"); @@ -264,31 +264,31 @@ class Stream { // Foreach the songs in this stream object foreach ($this->media as $element) { - $type = array_shift($element); - $media = new $type(array_shift($element)); - $media->format(); - switch ($type) { - case 'song': + $type = array_shift($element); + $media = new $type(array_shift($element)); + $media->format(); + switch ($type) { + case 'song': echo "#EXTINF:$media->time," . $media->f_artist_full . " - " . $media->title . "\n"; break; - case 'video': + case 'video': echo "#EXTINF: Video - $media->title\n"; break; - case 'radio': - echo "#EXTINF: Radio - $media->name [$media->frequency] ($media->site_url)\n"; - break; - case 'random': - echo "#EXTINF:Random URL\n"; - break; - default: + case 'radio': + echo "#EXTINF: Radio - $media->name [$media->frequency] ($media->site_url)\n"; + break; + case 'random': + echo "#EXTINF:Random URL\n"; + break; + default: echo "#EXTINF:URL-Add\n"; break; - } - echo call_user_func(array($type,'play_url'),$media->id) . "\n"; + } + echo call_user_func(array($type,'play_url'),$media->id) . "\n"; } // end foreach /* Foreach URLS */ - foreach ($this->urls as $url) { + foreach ($this->urls as $url) { echo "#EXTINF: URL-Add\n"; echo $url . "\n"; } @@ -300,10 +300,10 @@ class Stream { * This creates a new pls file from an array of songs and * urls, exciting I know */ - public function create_pls() { + public function create_pls() { /* Count entries */ - $total_entries = count($this->media) + count($this->urls); + $total_entries = count($this->media) + count($this->urls); // Send the client a pls playlist header("Cache-control: public"); @@ -311,30 +311,30 @@ class Stream { header("Content-Type: audio/x-scpls;"); echo "[Playlist]\n"; echo "NumberOfEntries=$total_entries\n"; - foreach ($this->media as $element) { + foreach ($this->media as $element) { $i++; - $type = array_shift($element); - $media = new $type(array_shift($element)); - $media->format(); - switch ($type) { - case 'song': + $type = array_shift($element); + $media = new $type(array_shift($element)); + $media->format(); + switch ($type) { + case 'song': $name = $media->f_artist_full . " - " . $media->title . "." . $media->type; - $length = $media->time; - break; - default: - $name = 'URL-Add'; - $length='-1'; - break; - } + $length = $media->time; + break; + default: + $name = 'URL-Add'; + $length='-1'; + break; + } $url = call_user_func(array($type,'play_url'),$media->id); echo "File" . $i . "=$url\n"; echo "Title" . $i . "=$name\n"; echo "Length" . $i . "=$length\n"; - } // end foreach songs + } // end foreach songs /* Foreach Additional URLs */ - foreach ($this->urls as $url) { + foreach ($this->urls as $url) { $i++; echo "File" . $i ."=$url\n"; echo "Title". $i . "=AddedURL\n"; @@ -348,32 +348,32 @@ class Stream { /** * create_asx * creates an ASX playlist (Thx Samir Kuthiala) This should really only be used - * if all of the content is ASF files. + * if all of the content is ASF files. */ - public function create_asx() { + public function create_asx() { header("Cache-control: public"); header("Content-Disposition: filename=ampache_playlist.asx"); header("Content-Type: video/x-ms-wmv;"); - + echo "\n"; echo "Ampache ASX Playlist"; - + foreach ($this->media as $element) { - $type = array_shift($element); - $media = new $type(array_shift($element)); - $media->format(); - switch ($type) { - case 'song': + $type = array_shift($element); + $media = new $type(array_shift($element)); + $media->format(); + switch ($type) { + case 'song': $name = $media->f_album_full . " - " . $media->title . "." . $media->type; - $author = $media->f_artist_full; - break; + $author = $media->f_artist_full; + break; default: - $author = 'Ampache'; + $author = 'Ampache'; $name = 'URL-Add'; - break; - } // end switch - $url = call_user_func(array($type,'play_url'),$media->id); + break; + } // end switch + $url = call_user_func(array($type,'play_url'),$media->id); echo "\n"; echo "$name\n"; @@ -386,17 +386,17 @@ class Stream { echo "\t\t\n"; echo "\n"; echo "\n"; - + } // end foreach /* Foreach urls */ - foreach ($this->urls as $url) { + foreach ($this->urls as $url) { echo "\n"; echo "AddURL\n"; echo "AddURL\n"; echo "\n"; echo "\n"; - } // end foreach + } // end foreach echo "\n"; @@ -406,26 +406,26 @@ class Stream { * create_xspf * creates an XSPF playlist (Thx PB1DFT) */ - public function create_xspf() { + public function create_xspf() { // Itterate through the songs foreach ($this->media as $element) { - $type = array_shift($element); - $media = new $type(array_shift($element)); - $media->format(); + $type = array_shift($element); + $media = new $type(array_shift($element)); + $media->format(); $xml = array(); - switch ($type) { + switch ($type) { default: - case 'song': + case 'song': $xml['track']['title'] = $media->title; $xml['track']['creator'] = $media->f_artist_full; $xml['track']['info'] = Config::get('web_path') . "/albums.php?action=show&album=" . $media->album; $xml['track']['image'] = Config::get('web_path') . "/image.php?id=" . $media->album . "&thumb=3"; $xml['track']['album'] = $media->f_album_full; - $length = $media->time; - break; + $length = $media->time; + break; } // type $xml['track']['location'] = call_user_func(array($type,'play_url'),$media->id); @@ -435,15 +435,15 @@ class Stream { $result .= xmlData::keyed_array($xml,1); } // end foreach - - xmlData::set_type('xspf'); + + xmlData::set_type('xspf'); header("Cache-control: public"); header("Content-Disposition: filename=ampache_playlist.xspf"); header("Content-Type: application/xspf+xml; charset=utf-8"); - echo xmlData::header(); + echo xmlData::header(); echo $result; - echo xmlData::footer(); + echo xmlData::footer(); } // create_xspf @@ -453,7 +453,7 @@ class Stream { * have to do a little 'cheating' to make this work, we are going to take * advantage of tmp_playlists to do all of this hotness */ - public function create_xspf_player() { + public function create_xspf_player() { /* Build the extra info we need to have it pass */ $play_info = "?action=show&tmpplaylist_id=" . $GLOBALS['user']->playlist->id; @@ -462,7 +462,7 @@ class Stream { //FIXME: This needs to go in a template, here for now though //FIXME: This preference doesn't even exists, we'll eventually //FIXME: just make it the default - if (Config::get('embed_xspf') == 1 ){ + if (Config::get('embed_xspf') == 1 ){ header("Location: ".Config::get('web_path')."/index.php?xspf&play_info=".$GLOBALS['user']->playlist->id); } else { @@ -474,13 +474,13 @@ class Stream { // We do a little check here to see if it's a Wii! if (false !== stristr($_SERVER['HTTP_USER_AGENT'], 'Nintendo Wii')) { echo "window.location=URL;\n"; - } + } // Else go ahead and do the normal stuff else { echo "window.open(URL, 'XSPF_player', 'width=400,height=170,scrollbars=0,toolbar=0,location=0,directories=0,status=0,resizable=0');\n"; echo "window.location = '" . return_referer() . "';\n"; echo "return false;\n"; - } + } echo "}\n"; echo "// end -->\n"; echo "\n"; @@ -491,41 +491,41 @@ class Stream { echo "\n"; } } // create_xspf_player - + /** * create_localplay - * This calls the Localplay API and attempts to + * This calls the Localplay API and attempts to * add, and then start playback */ - public function create_localplay() { + public function create_localplay() { // First figure out what their current one is and create the object - $localplay = new Localplay(Config::get('localplay_controller')); - $localplay->connect(); - foreach ($this->media as $element) { + $localplay = new Localplay(Config::get('localplay_controller')); + $localplay->connect(); + foreach ($this->media as $element) { $type = array_shift($element); - switch ($type) { - case 'video': + switch ($type) { + case 'video': // Add check for video support - case 'song': - case 'radio': - case 'random': - $media = new $type(array_shift($element)); - break; - default: - $media = array_shift($element); - break; - } // switch on types - $localplay->add($media); + case 'song': + case 'radio': + case 'random': + $media = new $type(array_shift($element)); + break; + default: + $media = array_shift($element); + break; + } // switch on types + $localplay->add($media); } // foreach object /** * Add urls after the fact */ - foreach ($this->urls as $url) { - $localplay->add($url); - } - + foreach ($this->urls as $url) { + $localplay->add($url); + } + $localplay->play(); } // create_localplay @@ -535,10 +535,10 @@ class Stream { * This 'votes' on the songs it inserts them into * a tmp_playlist with user of -1 (System) */ - public function create_democratic() { + public function create_democratic() { $democratic = Democratic::get_current_playlist(); - $democratic->set_parent(); + $democratic->set_parent(); $democratic->vote($this->media); } // create_democratic @@ -548,21 +548,21 @@ class Stream { * This prompts for a download of the song, only a single * element can by in song_ids */ - private function create_download() { + private function create_download() { - // There should only be one here... - foreach ($this->media as $element) { + // There should only be one here... + foreach ($this->media as $element) { $type = array_shift($element); $media = new $type(array_shift($element)); - $url = call_user_func(array($type,'play_url'),$media->id); - + $url = call_user_func(array($type,'play_url'),$media->id); + // Append the fact we are downloading - $url .= '&action=download'; + $url .= '&action=download'; // Header redirect baby! - header("Location: $url"); - exit; - } + header("Location: $url"); + exit; + } } //create_download @@ -570,26 +570,26 @@ class Stream { * create_ram *this functions creates a RAM file for use by Real Player */ - public function create_ram() { + public function create_ram() { header("Cache-control: public"); header("Content-Disposition: filename=ampache_playlist.ram"); header("Content-Type: audio/x-pn-realaudio ram;"); foreach ($this->media as $element) { $type = array_shift($element); - echo $url = call_user_func(array($type,'play_url'),array_shift($element)) . "\n"; + echo $url = call_user_func(array($type,'play_url'),array_shift($element)) . "\n"; } // foreach songs } // create_ram /** * start_downsample - * This is a rather complext function that starts the downsampling of a song and returns the + * This is a rather complext function that starts the downsampling of a song and returns the * opened file handled a reference to the song object is passed so that the changes we make - * in here affect the external object, References++ + * in here affect the external object, References++ */ public static function start_downsample(&$song,$now_playing_id=0,$song_name=0,$start=0) { - + /* Check to see if bitrates are set if so let's go ahead and optomize! */ $max_bitrate = Config::get('max_bit_rate'); $min_bitrate = Config::get('min_bit_rate'); @@ -611,8 +611,8 @@ class Stream { $results = Dba::fetch_row($db_results); // Current number of active streams (current is already in now playing, worst case make it 1) - $active_streams = intval($results[0]); - if (!$active_streams) { $active_streams = '1'; } + $active_streams = intval($results[0]); + if (!$active_streams) { $active_streams = '1'; } /* If only one user, they'll get all available. Otherwise split up equally. */ $sample_rate = floor($max_bitrate/$active_streams); @@ -630,7 +630,7 @@ class Stream { $sample_rate = floor($max_bitrate/$active_streams); } // end else - // Never go over the users sample rate + // Never go over the users sample rate if ($sample_rate > $user_sample_rate) { $sample_rate = $user_sample_rate; } debug_event('downsample',"Downsampled: $active_streams current active streams, downsampling to $sample_rate",'2'); @@ -653,7 +653,7 @@ class Stream { /* Set the Sample Ratio */ $sample_ratio = $sample_rate/($song->bitrate/1000); } - + // Set the new size for the song $song->size = floor($sample_ratio*$song->size); @@ -677,9 +677,9 @@ class Stream { $downsample_command = str_replace("%EOF%",$eof,$downsample_command,$eof_exists); $downsample_command = str_replace("%SAMPLE%",$sample_rate,$downsample_command,$sample_exists); - if (!$file_exists || !$offset_exists || !$eof_exists || !$sample_exists) { - debug_event('downsample','Error: Downsample command missing a varaible values are File:' . $file_exists . ' Offset:' . $offset_exists . ' Eof:' . $eof_exists . ' Sample:' . $sample_exists,'1'); - } + if (!$file_exists || !$offset_exists || !$eof_exists || !$sample_exists) { + debug_event('downsample','Error: Downsample command missing a varaible values are File:' . $file_exists . ' Offset:' . $offset_exists . ' Eof:' . $eof_exists . ' Sample:' . $sample_exists,'1'); + } // If we are debugging log this event $message = "Start Downsample: $downsample_command"; @@ -692,7 +692,7 @@ class Stream { } // start_downsample - /** + /** * validate_bitrate * this function takes a bitrate and returns a valid one */ @@ -701,17 +701,17 @@ class Stream { /* Round to standard bitrates */ $sample_rate = 16*(floor($bitrate/16)); - return $sample_rate; + return $sample_rate; } // validate_bitrate /** * gc_now_playing - * This will garbage collect the now playing data, + * This will garbage collect the now playing data, * this is done on every play start */ - public static function gc_now_playing() { + public static function gc_now_playing() { // Remove any now playing entries for session_streams that have been GC'd $sql = "DELETE FROM `now_playing` USING `now_playing` " . @@ -731,7 +731,7 @@ class Stream { $time = intval(time()+$length); $session_id = Dba::escape($sid); - $object_type = Dba::escape(strtolower($type)); + $object_type = Dba::escape(strtolower($type)); // Do a replace into ensuring that this client always only has a single row $sql = "REPLACE INTO `now_playing` (`id`,`object_id`,`object_type`, `user`, `expire`)" . @@ -758,7 +758,7 @@ class Stream { * get_now_playing * This returns the now playing information */ - public static function get_now_playing($filter=NULL) { + public static function get_now_playing($filter=NULL) { $sql = "SELECT `session_stream`.`agent`,`now_playing`.* " . "FROM `now_playing` " . @@ -766,17 +766,17 @@ class Stream { "ORDER BY `now_playing`.`expire` DESC"; $db_results = Dba::read($sql); - $results = array(); + $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']); + 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; + return $results; } // get_now_playing @@ -785,20 +785,20 @@ class Stream { * 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) { + public static function check_lock_media($media_id,$type) { - $media_id = Dba::escape($media_id); - $type = Dba::escape($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); + $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'); + if (Dba::num_rows($db_results)) { + debug_event('Stream','Unable to play media currently locked by another user','3'); return false; - } + } - return true; + return true; } // check_lock_media @@ -806,7 +806,7 @@ class Stream { * auto_init * This is called on class load it sets the session */ - public static function _auto_init() { + public static function _auto_init() { // Generate the session ID self::$session = md5(uniqid(rand(), true)); @@ -817,31 +817,31 @@ class Stream { * run_playlist_method * This takes care of the different types of 'playlist methods' the reason this is here * is because it deals with streaming rather then playlist mojo. If something needs to happen - * this will echo the javascript required to cause a reload of the iframe. + * this will echo the javascript required to cause a reload of the iframe. */ - public static function run_playlist_method() { + public static function run_playlist_method() { - // If this wasn't ajax included run away - if (AJAX_INCLUDE != '1') { return false; } + // If this wasn't ajax included run away + if (AJAX_INCLUDE != '1') { return false; } // If we're doin the flash magic then run away as well - if (Config::get('play_type') == 'xspf_player') { return false; } + if (Config::get('play_type') == 'xspf_player') { return false; } - switch (Config::get('playlist_method')) { - default: - case 'clear': - case 'default': - return true; + switch (Config::get('playlist_method')) { + default: + case 'clear': + case 'default': + return true; break; - case 'send': + case 'send': $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket'; break; - case 'send_clear': - $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket&playlist_method=clear'; - break; - } // end switch on method + case 'send_clear': + $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket&playlist_method=clear'; + break; + } // end switch on method - // Load our javascript + // Load our javascript echo "'si", // strip out javascript "'<[\/\!]*?[^<>]*?>'si", // strip out html tags "'([\r\n])[\s]+'", // strip out white space @@ -722,9 +722,9 @@ class Snoopy "Ü", "ß", ); - + $text = preg_replace($search,$replace,$document); - + return $text; } @@ -738,7 +738,7 @@ class Snoopy function _expandlinks($links,$URI) { - + preg_match("/^[^\?]+/",$URI,$match); $match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]); @@ -746,21 +746,21 @@ class Snoopy $match_part = parse_url($match); $match_root = $match_part["scheme"]."://".$match_part["host"]; - + $search = array( "|^http://".preg_quote($this->host)."|i", "|^(\/)|i", "|^(?!http://)(?!mailto:)|i", "|/\./|", "|/[^\/]+/\.\./|" ); - + $replace = array( "", $match_root."/", $match."/", "/", "/" - ); - + ); + $expandedLinks = preg_replace($search,$replace,$links); return $expandedLinks; @@ -773,19 +773,19 @@ class Snoopy $fp the current open file pointer $URI the full URI $body body contents to send if any (POST) - Output: + Output: \*======================================================================*/ - + function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") { $cookie_headers = ''; if($this->passcookies && $this->_redirectaddr) $this->setcookies(); - + $URI_PARTS = parse_url($URI); if(empty($url)) $url = "/"; - $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; + $headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; if(!empty($this->agent)) $headers .= "User-Agent: ".$this->agent."\r\n"; if(!empty($this->host) && !isset($this->rawheaders['Host'])) { @@ -799,10 +799,10 @@ class Snoopy if(!empty($this->referer)) $headers .= "Referer: ".$this->referer."\r\n"; if(!empty($this->cookies)) - { + { if(!is_array($this->cookies)) $this->cookies = (array)$this->cookies; - + reset($this->cookies); if ( count($this->cookies) > 0 ) { $cookie_headers .= 'Cookie: '; @@ -810,7 +810,7 @@ class Snoopy $cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; } $headers .= substr($cookie_headers,0,-2) . "\r\n"; - } + } } if(!empty($this->rawheaders)) { @@ -825,28 +825,28 @@ class Snoopy $headers .= "; boundary=".$this->_mime_boundary; $headers .= "\r\n"; } - if(!empty($body)) + if(!empty($body)) $headers .= "Content-length: ".strlen($body)."\r\n"; - if(!empty($this->user) || !empty($this->pass)) + if(!empty($this->user) || !empty($this->pass)) $headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; - + //add proxy auth headers - if(!empty($this->proxy_user)) + if(!empty($this->proxy_user)) $headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n"; $headers .= "\r\n"; - + // set the read timeout if needed if ($this->read_timeout > 0) socket_set_timeout($fp, $this->read_timeout); $this->timed_out = false; - + fwrite($fp,$headers.$body,strlen($headers.$body)); - + $this->_redirectaddr = false; unset($this->headers); - + while($currentHeader = fgets($fp,$this->_maxlinelen)) { if ($this->read_timeout > 0 && $this->_check_timeout($fp)) @@ -854,10 +854,10 @@ class Snoopy $this->status=-100; return false; } - + if($currentHeader == "\r\n") break; - + // if a header begins with Location: or URI:, set the redirect if(preg_match("/^(Location:|URI:)/i",$currentHeader)) { @@ -877,16 +877,16 @@ class Snoopy else $this->_redirectaddr = $matches[2]; } - + if(preg_match("|^HTTP/|",$currentHeader)) { if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) { $this->status= $status[1]; - } + } $this->response_code = $currentHeader; } - + $this->headers[] = $currentHeader; } @@ -904,13 +904,13 @@ class Snoopy $this->status=-100; return false; } - + // check if there is a a redirect meta tag - + if(preg_match("']*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) { - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); + $this->_redirectaddr = $this->_expandlinks($match[1],$URI); } // have we hit our frame depth and is there frame src to fetch? @@ -926,7 +926,7 @@ class Snoopy // no framed content else $this->results = $results; - + return true; } @@ -936,21 +936,21 @@ class Snoopy Input: $url the url to fetch $URI the full URI $body body contents to send if any (POST) - Output: + Output: \*======================================================================*/ - + function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") - { + { if($this->passcookies && $this->_redirectaddr) $this->setcookies(); - $headers = array(); - + $headers = array(); + $URI_PARTS = parse_url($URI); if(empty($url)) $url = "/"; // GET ... header not needed for curl - //$headers[] = $http_method." ".$url." ".$this->_httpversion; + //$headers[] = $http_method." ".$url." ".$this->_httpversion; if(!empty($this->agent)) $headers[] = "User-Agent: ".$this->agent; if(!empty($this->host)) @@ -963,10 +963,10 @@ class Snoopy if(!empty($this->referer)) $headers[] = "Referer: ".$this->referer; if(!empty($this->cookies)) - { + { if(!is_array($this->cookies)) $this->cookies = (array)$this->cookies; - + reset($this->cookies); if ( count($this->cookies) > 0 ) { $cookie_str = 'Cookie: '; @@ -989,43 +989,43 @@ class Snoopy else $headers[] = "Content-type: $content_type"; } - if(!empty($body)) + if(!empty($body)) $headers[] = "Content-length: ".strlen($body); - if(!empty($this->user) || !empty($this->pass)) + if(!empty($this->user) || !empty($this->pass)) $headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); - + for($curr_header = 0; $curr_header < count($headers); $curr_header++) { $safer_header = strtr( $headers[$curr_header], "\"", " " ); $cmdline_params .= " -H \"".$safer_header."\""; } - + if(!empty($body)) $cmdline_params .= " -d \"$body\""; - + if($this->read_timeout > 0) $cmdline_params .= " -m ".$this->read_timeout; - + $headerfile = tempnam($temp_dir, "sno"); exec($this->curl_path." -k -D \"$headerfile\"".$cmdline_params." \"".escapeshellcmd($URI)."\"",$results,$return); - + if($return) { $this->error = "Error: cURL could not retrieve the document, error $return."; return false; } - - + + $results = implode("\r\n",$results); - + $result_headers = file("$headerfile"); - + $this->_redirectaddr = false; unset($this->headers); - + for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) { - + // if a header begins with Location: or URI:, set the redirect if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader])) { @@ -1045,7 +1045,7 @@ class Snoopy else $this->_redirectaddr = $matches[2]; } - + if(preg_match("|^HTTP/|",$result_headers[$currentHeader])) $this->response_code = $result_headers[$currentHeader]; @@ -1053,10 +1053,10 @@ class Snoopy } // check if there is a a redirect meta tag - + if(preg_match("']*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) { - $this->_redirectaddr = $this->_expandlinks($match[1],$URI); + $this->_redirectaddr = $this->_expandlinks($match[1],$URI); } // have we hit our frame depth and is there frame src to fetch? @@ -1074,7 +1074,7 @@ class Snoopy $this->results = $results; unlink("$headerfile"); - + return true; } @@ -1082,7 +1082,7 @@ class Snoopy Function: setcookies() Purpose: set cookies for a redirection \*======================================================================*/ - + function setcookies() { for($x=0; $xheaders); $x++) @@ -1092,7 +1092,7 @@ class Snoopy } } - + /*======================================================================*\ Function: _check_timeout Purpose: checks whether timeout has occurred @@ -1116,13 +1116,13 @@ class Snoopy Purpose: make a socket connection Input: $fp file pointer \*======================================================================*/ - + function _connect(&$fp) { if(!empty($this->proxy_host) && !empty($this->proxy_port)) { $this->_isproxy = true; - + $host = $this->proxy_host; $port = $this->proxy_port; } @@ -1131,9 +1131,9 @@ class Snoopy $host = $this->host; $port = $this->port; } - + $this->status = 0; - + if($fp = fsockopen( $host, $port, @@ -1169,13 +1169,13 @@ class Snoopy Purpose: disconnect a socket connection Input: $fp file pointer \*======================================================================*/ - + function _disconnect($fp) { return(fclose($fp)); } - + /*======================================================================*\ Function: _prepare_post_body Purpose: Prepare post body according to encoding type @@ -1183,7 +1183,7 @@ class Snoopy $formfiles - form upload files Output: post body \*======================================================================*/ - + function _prepare_post_body($formvars, $formfiles) { settype($formvars, "array"); @@ -1192,7 +1192,7 @@ class Snoopy if (count($formvars) == 0 && count($formfiles) == 0) return; - + switch ($this->_submit_type) { case "application/x-www-form-urlencoded": reset($formvars); @@ -1208,7 +1208,7 @@ class Snoopy case "multipart/form-data": $this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); - + reset($formvars); while(list($key,$val) = each($formvars)) { if (is_array($val) || is_object($val)) { @@ -1223,7 +1223,7 @@ class Snoopy $postdata .= "$val\r\n"; } } - + reset($formfiles); while (list($field_name, $file_names) = each($formfiles)) { settype($file_names, "array"); diff --git a/modules/infotools/jamendoSearch.class.php b/modules/infotools/jamendoSearch.class.php index 57d3c948..d234ae85 100644 --- a/modules/infotools/jamendoSearch.class.php +++ b/modules/infotools/jamendoSearch.class.php @@ -21,11 +21,11 @@ */ /** - * jamendoSearch - * This class does XML lookups against the jamendo website + * jamendoSearch + * This class does XML lookups against the jamendo website * and returns information */ -class jamendoSearch { +class jamendoSearch { @@ -36,29 +36,29 @@ class jamendoSearch { * Constructor * This function inits the searcher */ - function jamendoSearch() { + function jamendoSearch() { /* Load the XMLRPC client */ - $this->_client = new XML_RPC_Client('/xmlrpc/','www.jamendo.com',80); + $this->_client = new XML_RPC_Client('/xmlrpc/','www.jamendo.com',80); } // jamendoSearch /** * query - * This runs a XMLRPC query and returns decoded data + * This runs a XMLRPC query and returns decoded data */ - function query($command,$options) { - + function query($command,$options) { + $encoded_command = new XML_RPC_Value($command); $encoded_options = new XML_RPC_Value($options,'struct'); - $message = new XML_RPC_Message('jamendo.get',array($encoded_command,$encoded_options)); - $response = $this->_client->send($message,15); - $value = $response->value(); + $message = new XML_RPC_Message('jamendo.get',array($encoded_command,$encoded_options)); + $response = $this->_client->send($message,15); + $value = $response->value(); - return XML_RPC_Decode($value); + return XML_RPC_Decode($value); } // query -} // jamendoSearch +} // jamendoSearch ?> diff --git a/modules/mpd/mpd.class.php b/modules/mpd/mpd.class.php index b0c9c76c..588f0604 100644 --- a/modules/mpd/mpd.class.php +++ b/modules/mpd/mpd.class.php @@ -21,7 +21,7 @@ * 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 - */ + */ // Create common command definitions for MPD to use define("MPD_CMD_STATUS", "status"); @@ -98,14 +98,14 @@ class mpd { var $db_last_refreshed; var $num_songs_played; var $playlist_count; - + var $num_artists; var $num_albums; var $num_songs; - + var $playlist = array(); - // Misc Other Vars + // Misc Other Vars var $mpd_class_version = "1.2"; var $errStr = ""; // Used for maintaining information about the last error message @@ -115,19 +115,19 @@ class mpd { // =================== BEGIN OBJECT METHODS ================ /* mpd() : Constructor - * + * * Builds the MPD object, connects to the server, and refreshes all local object properties. */ public function __construct($srv,$port,$pwd = NULL) { $this->host = $srv; $this->port = $port; $this->password = $pwd; - + $resp = $this->Connect(); if ( is_null($resp) ) { $this->errStr = "Could not connect"; return; - } + } list ( $this->mpd_version ) = sscanf($resp, OK . " MPD %s\n"); @@ -137,7 +137,7 @@ class mpd { $this->errStr = "Password supplied is incorrect or Invalid Command"; return; // bad password or command } - + if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected! $this->connected = FALSE; $this->errStr = "Password supplied does not have read access"; @@ -148,32 +148,32 @@ class mpd { if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected! $this->connected = FALSE; $this->errStr = "Password required to access server"; - return; + return; } } - return true; + return true; } // constructor /* Connect() - * - * Connects to the MPD server. - * + * + * Connects to the MPD server. + * * NOTE: This is called automatically upon object instantiation; you should not need to call this directly. */ public function Connect() { debug_event('MPD',"mpd->Connect() / host: ".$this->host.", port: ".$this->port,'5'); $this->mpd_sock = fsockopen($this->host,$this->port,$errNo,$errStr,6); - /* Vollmerize this bizatch, if we've got php4.3+ we should + /* Vollmerize this bizatch, if we've got php4.3+ we should * have these functions and we need them */ - if (function_exists('stream_set_timeout')) { - + if (function_exists('stream_set_timeout')) { + /* Set the timeout on the connection */ stream_set_timeout($this->mpd_sock,6); - + /* We want blocking, cause otherwise it doesn't - * timeout, and feof just keeps on spinning + * timeout, and feof just keeps on spinning */ stream_set_blocking($this->mpd_sock,TRUE); $status = socket_get_status($this->mpd_sock); @@ -181,14 +181,14 @@ class mpd { if (!$this->mpd_sock) { $this->errStr = "Socket Error: $errStr ($errNo)"; return NULL; - } + } else { while(!feof($this->mpd_sock) && !$status['timed_out']) { $response = fgets($this->mpd_sock,1024); - if (function_exists('socket_get_status')) { + if (function_exists('socket_get_status')) { $status = socket_get_status($this->mpd_sock); } - if (strstr($response,"OK")) { + if (strstr($response,"OK")) { $this->connected = TRUE; return $response; break; @@ -198,7 +198,7 @@ class mpd { return NULL; } - + } // end while // Generic response $this->errStr = "Connection not available"; @@ -208,9 +208,9 @@ class mpd { } // connect /* SendCommand() - * - * Sends a generic command to the MPD server. Several command constants are pre-defined for - * use (see MPD_CMD_* constant definitions above). + * + * Sends a generic command to the MPD server. Several command constants are pre-defined for + * use (see MPD_CMD_* constant definitions above). */ function SendCommand($cmdStr,$arg1 = "",$arg2 = "") { debug_event('MPD',"mpd->SendCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2,'5'); @@ -255,11 +255,11 @@ class mpd { return $respStr; } - /* QueueCommand() + /* QueueCommand() * - * Queues a generic command for later sending to the MPD server. The CommandQueue can hold - * as many commands as needed, and are sent all at once, in the order they are queued, using - * the SendCommandQueue() method. The syntax for queueing commands is identical to SendCommand(). + * Queues a generic command for later sending to the MPD server. The CommandQueue can hold + * as many commands as needed, and are sent all at once, in the order they are queued, using + * the SendCommandQueue() method. The syntax for queueing commands is identical to SendCommand(). */ function QueueCommand($cmdStr,$arg1 = "",$arg2 = "") { if ( $this->debugging ) echo "mpd->QueueCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2."\n"; @@ -280,7 +280,7 @@ class mpd { return TRUE; } - /* SendCommandQueue() + /* SendCommandQueue() * * Sends all commands in the Command Queue to the MPD server. See also QueueCommand(). */ @@ -301,10 +301,10 @@ class mpd { return $respStr; } - /* AdjustVolume() + /* AdjustVolume() * * Adjusts the mixer volume on the MPD by , which can be a positive (volume increase), - * or negative (volume decrease) value. + * or negative (volume decrease) value. */ function AdjustVolume($modifier) { if ( $this->debugging ) echo "mpd->AdjustVolume()\n"; @@ -321,7 +321,7 @@ class mpd { return $ret; } - /* SetVolume() + /* SetVolume() * * Sets the mixer volume to , which should be between 1 - 100. */ @@ -353,11 +353,11 @@ class mpd { return $ret; } - /* GetDir() - * + /* GetDir() + * * Retrieves a database directory listing of the directory and places the results into - * a multidimensional array. If no directory is specified, the directory listing is at the - * base of the MPD music path. + * a multidimensional array. If no directory is specified, the directory listing is at the + * base of the MPD music path. */ function GetDir($dir = "") { if ( $this->debugging ) echo "mpd->GetDir()\n"; @@ -367,10 +367,10 @@ class mpd { return $dirlist; } - /* PLAdd() - * - * Adds each track listed in a single-dimensional , which contains filenames - * of tracks to add, to the end of the playlist. This is used to add many, many tracks to + /* PLAdd() + * + * Adds each track listed in a single-dimensional , which contains filenames + * of tracks to add, to the end of the playlist. This is used to add many, many tracks to * the playlist in one swoop. */ function PLAddBulk($trackArray) { @@ -385,9 +385,9 @@ class mpd { return $resp; } - /* PLAdd() - * - * Adds the file to the end of the playlist. must be a track in the MPD database. + /* PLAdd() + * + * Adds the file to the end of the playlist. must be a track in the MPD database. */ function PLAdd($fileName) { if ( $this->debugging ) echo "mpd->PLAdd()\n"; @@ -396,9 +396,9 @@ class mpd { return $resp; } - /* PLMoveTrack() - * - * Moves track number to position in the playlist. This is used to reorder + /* PLMoveTrack() + * + * Moves track number to position in the playlist. This is used to reorder * the songs in the playlist. */ function PLMoveTrack($origPos, $newPos) { @@ -406,21 +406,21 @@ class mpd { if ( ! is_numeric($origPos) ) { $this->errStr = "PLMoveTrack(): argument 1 must be numeric"; return NULL; - } + } if ( $origPos < 0 or $origPos > $this->playlist_count ) { $this->errStr = "PLMoveTrack(): argument 1 out of range"; return NULL; } if ( $newPos < 0 ) $newPos = 0; if ( $newPos > $this->playlist_count ) $newPos = $this->playlist_count; - + if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLMOVETRACK,$origPos,$newPos))) $this->RefreshInfo(); if ( $this->debugging ) echo "mpd->PLMoveTrack() / return\n"; return $resp; } - /* PLShuffle() - * + /* PLShuffle() + * * Randomly reorders the songs in the playlist. */ function PLShuffle() { @@ -430,9 +430,9 @@ class mpd { return $resp; } - /* PLLoad() - * - * Retrieves the playlist from .m3u and loads it into the current playlist. + /* PLLoad() + * + * Retrieves the playlist from .m3u and loads it into the current playlist. */ function PLLoad($file) { if ( $this->debugging ) echo "mpd->PLLoad()\n"; @@ -441,8 +441,8 @@ class mpd { return $resp; } - /* PLSave() - * + /* PLSave() + * * Saves the playlist to .m3u for later retrieval. The file is saved in the MPD playlist * directory. */ @@ -453,8 +453,8 @@ class mpd { return $resp; } - /* PLClear() - * + /* PLClear() + * * Empties the playlist. */ function PLClear() { @@ -464,8 +464,8 @@ class mpd { return $resp; } - /* PLRemove() - * + /* PLRemove() + * * Removes track from the playlist. */ public function PLRemove($id) { @@ -474,13 +474,13 @@ class mpd { return NULL; } if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLREMOVE,$id))) $this->RefreshInfo(); - debug_event('MPD',"mpd->PLRemove() / return",'5'); + debug_event('MPD',"mpd->PLRemove() / return",'5'); return $resp; } // PLRemove - /* SetRepeat() - * - * Enables 'loop' mode -- tells MPD continually loop the playlist. The parameter + /* SetRepeat() + * + * Enables 'loop' mode -- tells MPD continually loop the playlist. The parameter * is either 1 (on) or 0 (off). */ function SetRepeat($repVal) { @@ -491,8 +491,8 @@ class mpd { return $rpt; } - /* SetRandom() - * + /* SetRandom() + * * Enables 'randomize' mode -- tells MPD to play songs in the playlist in random order. The * parameter is either 1 (on) or 0 (off). */ @@ -504,10 +504,10 @@ class mpd { return $resp; } - /* Shutdown() - * - * Shuts down the MPD server (aka sends the KILL command). This closes the current connection, - * and prevents future communication with the server. + /* Shutdown() + * + * Shuts down the MPD server (aka sends the KILL command). This closes the current connection, + * and prevents future communication with the server. */ function Shutdown() { if ( $this->debugging ) echo "mpd->Shutdown()\n"; @@ -522,15 +522,15 @@ class mpd { return $resp; } - /* DBRefresh() - * - * Tells MPD to rescan the music directory for new tracks, and to refresh the Database. Tracks + /* DBRefresh() + * + * Tells MPD to rescan the music directory for new tracks, and to refresh the Database. Tracks * cannot be played unless they are in the MPD database. */ function DBRefresh() { if ( $this->debugging ) echo "mpd->DBRefresh()\n"; $resp = $this->SendCommand(MPD_CMD_REFRESH); - + // Update local variables $this->RefreshInfo(); @@ -538,9 +538,9 @@ class mpd { return $resp; } - /* Play() - * - * Begins playing the songs in the MPD playlist. + /* Play() + * + * Begins playing the songs in the MPD playlist. */ function Play() { if ( $this->debugging ) echo "mpd->Play()\n"; @@ -549,9 +549,9 @@ class mpd { return $rpt; } - /* Stop() - * - * Stops playing the MPD. + /* Stop() + * + * Stops playing the MPD. */ function Stop() { if ( $this->debugging ) echo "mpd->Stop()\n"; @@ -560,10 +560,10 @@ class mpd { return $rpt; } - /* Pause() - * + /* Pause() + * * Toggles pausing on the MPD. Calling it once will pause the player, calling it again - * will unpause. + * will unpause. */ function Pause() { if ( $this->debugging ) echo "mpd->Pause()\n"; @@ -571,12 +571,12 @@ class mpd { if ( $this->debugging ) echo "mpd->Pause() / return\n"; return $rpt; } - - /* SeekTo() - * - * Skips directly to the song in the MPD playlist. + + /* SeekTo() + * + * Skips directly to the song in the MPD playlist. */ - function SkipTo($idx) { + function SkipTo($idx) { if ( $this->debugging ) echo "mpd->SkipTo()\n"; if ( ! is_numeric($idx) ) { $this->errStr = "SkipTo() : argument 1 must be a numeric value"; @@ -587,13 +587,13 @@ class mpd { return $idx; } - /* SeekTo() - * + /* SeekTo() + * * Skips directly to a given position within a track in the MPD playlist. The argument, * given in seconds, is the track position to locate. The argument, if supplied is * the track number in the playlist. If is not specified, the current track is assumed. */ - function SeekTo($pos, $track = -1) { + function SeekTo($pos, $track = -1) { if ( $this->debugging ) echo "mpd->SeekTo()\n"; if ( ! is_numeric($pos) ) { $this->errStr = "SeekTo() : argument 1 must be a numeric value"; @@ -603,18 +603,18 @@ class mpd { $this->errStr = "SeekTo() : argument 2 must be a numeric value"; return NULL; } - if ( $track == -1 ) { + if ( $track == -1 ) { $track = $this->current_track_id; - } - + } + if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_SEEK,$track,$pos))) $this->RefreshInfo(); if ( $this->debugging ) echo "mpd->SeekTo() / return\n"; return $pos; } - /* Next() - * - * Skips to the next song in the MPD playlist. If not playing, returns an error. + /* Next() + * + * Skips to the next song in the MPD playlist. If not playing, returns an error. */ function Next() { if ( $this->debugging ) echo "mpd->Next()\n"; @@ -623,9 +623,9 @@ class mpd { return $rpt; } - /* Previous() - * - * Skips to the previous song in the MPD playlist. If not playing, returns an error. + /* Previous() + * + * Skips to the previous song in the MPD playlist. If not playing, returns an error. */ function Previous() { if ( $this->debugging ) echo "mpd->Previous()\n"; @@ -633,13 +633,13 @@ class mpd { if ( $this->debugging ) echo "mpd->Previous() / return\n"; return $rpt; } - - /* Search() - * - * Searches the MPD database. The search should be one of the following: + + /* Search() + * + * Searches the MPD database. The search should be one of the following: * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM - * The search is a case-insensitive locator string. Anything that contains - * will be returned in the results. + * The search is a case-insensitive locator string. Anything that contains + * will be returned in the results. */ function Search($type,$string) { if ( $this->debugging ) echo "mpd->Search()\n"; @@ -656,13 +656,13 @@ class mpd { return $searchlist; } - /* Find() - * - * Find() looks for exact matches in the MPD database. The find should be one of - * the following: + /* Find() + * + * Find() looks for exact matches in the MPD database. The find should be one of + * the following: * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM - * The find is a case-insensitive locator string. Anything that exactly matches - * will be returned in the results. + * The find is a case-insensitive locator string. Anything that exactly matches + * will be returned in the results. */ function Find($type,$string) { if ( $this->debugging ) echo "mpd->Find()\n"; @@ -679,8 +679,8 @@ class mpd { return $searchlist; } - /* Disconnect() - * + /* Disconnect() + * * Closes the connection to the MPD server. */ function Disconnect() { @@ -693,15 +693,15 @@ class mpd { unset($this->mpd_sock); } - /* GetArtists() - * + /* GetArtists() + * * Returns the list of artists in the database in an associative array. */ function GetArtists() { if ( $this->debugging ) echo "mpd->GetArtists()\n"; if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ARTIST))) return NULL; $arArray = array(); - + $arLine = strtok($resp,"\n"); $arName = ""; $arCounter = -1; @@ -719,8 +719,8 @@ class mpd { return $arArray; } - /* GetAlbums() - * + /* GetAlbums() + * * Returns the list of albums in the database in an associative array. Optional parameter * is an artist Name which will list all albums by a particular artist. */ @@ -760,9 +760,9 @@ class mpd { return ( 100 * $ver_maj ) + ( 10 * $ver_min ) + ( $ver_rel ); } - /* _checkCompatibility() - * - * Check MPD command compatibility against our internal table. If there is no version + /* _checkCompatibility() + * + * Check MPD command compatibility against our internal table. If there is no version * listed in the table, allow it by default. */ function _checkCompatibility($cmd) { @@ -794,8 +794,8 @@ class mpd { return TRUE; } - /* _parseFileListResponse() - * + /* _parseFileListResponse() + * * Builds a multidimensional array with MPD response lists. * * NOTE: This function is used internally within the class. It should not be used. @@ -819,13 +819,13 @@ class mpd { } $plistLine = strtok("\n"); - } + } } return $plistArray; } - /* RefreshInfo() - * + /* RefreshInfo() + * * Updates all class properties with the values from the MPD server. * * NOTE: This function is automatically called upon Connect() as of v1.1. @@ -842,7 +842,7 @@ class mpd { list ( $element, $value ) = explode(": ",$statLine); $stats[$element] = $value; $statLine = strtok("\n"); - } + } } // Get the Server Status @@ -894,8 +894,8 @@ class mpd { } /* ------------------ DEPRECATED METHODS -------------------*/ - /* GetStatistics() - * + /* GetStatistics() + * * Retrieves the 'statistics' variables from the server and tosses them into an array. * * NOTE: This function really should not be used. Instead, use $this->[variable]. The function @@ -913,14 +913,14 @@ class mpd { list ( $element, $value ) = explode(": ",$statsLine); $statsArray[$element] = $value; $statsLine = strtok("\n"); - } + } } if ( $this->debugging ) echo "mpd->GetStatistics() / return: " . print_r($statsArray) ."\n"; return $statsArray; } - /* GetStatus() - * + /* GetStatus() + * * Retrieves the 'status' variables from the server and tosses them into an array. * * NOTE: This function really should not be used. Instead, use $this->[variable]. The function @@ -944,8 +944,8 @@ class mpd { return $statusArray; } - /* GetVolume() - * + /* GetVolume() + * * Retrieves the mixer volume from the server. * * NOTE: This function really should not be used. Instead, use $this->volume. The function @@ -963,8 +963,8 @@ class mpd { return $vol; } - /* GetPlaylist() - * + /* GetPlaylist() + * * Retrieves the playlist from the server and tosses it into a multidimensional array. * * NOTE: This function really should not be used. Instead, use $this->playlist. The function @@ -989,7 +989,7 @@ class mpd { $this->RefreshInfo(); if ($resp = ($this->state == MPD_STATE_STOPPED)) { $this->PLClear(); - return true; + return true; } return false; diff --git a/modules/php_musicbrainz/mbArtist.php b/modules/php_musicbrainz/mbArtist.php index 7ba126b0..972ca311 100644 --- a/modules/php_musicbrainz/mbArtist.php +++ b/modules/php_musicbrainz/mbArtist.php @@ -14,7 +14,7 @@ private $releasesCount = 0; private $releasesOffset = 0; private $aliases = array(); - + function mbArtist( $id = '', $type = '', $name = '', $sortName = '' ) { parent::MusicBrainzEntity($id); $this->type = $type; @@ -102,7 +102,7 @@ if ( empty( $rresults ) ) return ""; - + $keys = array(); foreach ( $rresults as $key => $rr ) { $rr = $rr->getRelease(); diff --git a/modules/php_musicbrainz/mbArtistAlias.php b/modules/php_musicbrainz/mbArtistAlias.php index c7e7e95d..3b65fcb6 100644 --- a/modules/php_musicbrainz/mbArtistAlias.php +++ b/modules/php_musicbrainz/mbArtistAlias.php @@ -4,7 +4,7 @@ private $value; private $type; private $script; - + function mbAristAlias( $value='', $type='', $script='' ) { $this->value = $value; $this->type = $type; diff --git a/modules/php_musicbrainz/mbDisc.php b/modules/php_musicbrainz/mbDisc.php index 63087016..90dacc06 100644 --- a/modules/php_musicbrainz/mbDisc.php +++ b/modules/php_musicbrainz/mbDisc.php @@ -1,7 +1,7 @@ lastTrackNum; } function setFirstTrackNum( $track ) { $this->firstTrackNum = $track; } function getFirstTrackNum( ) { return $this->firstTrackNum; } - + function &getTracks() { return $this->tracks; } @@ -46,7 +46,7 @@ foreach ( $disc->getTracks() as $track ) $toc .= '+' . $track[0]; - return "http://" . $netloc . "/bare/cdlookup.html?id=" . $disc->getId() . "&toc=" . $toc . + return "http://" . $netloc . "/bare/cdlookup.html?id=" . $disc->getId() . "&toc=" . $toc . "&tracks=" . $disc->getLastTrackNum(); } } diff --git a/modules/php_musicbrainz/mbEntity.php b/modules/php_musicbrainz/mbEntity.php index 47089279..86cfdc07 100644 --- a/modules/php_musicbrainz/mbEntity.php +++ b/modules/php_musicbrainz/mbEntity.php @@ -21,7 +21,7 @@ function &getRelations( $target_type='', $relation_type='' ) { if ( $target_type == '' && $relation_type == '' ) return $this->relations; - + $result = array(); if ( empty($target_type) ) { diff --git a/modules/php_musicbrainz/mbFilter.php b/modules/php_musicbrainz/mbFilter.php index 02ee41f7..a759fffa 100644 --- a/modules/php_musicbrainz/mbFilter.php +++ b/modules/php_musicbrainz/mbFilter.php @@ -6,11 +6,11 @@ class mbArtistFilter implements MusicBrainzFilter { private $parameterList = array(); - + function createParameters() { return $this->parameterList; } - + function name( $name ) { $this->parameterList['name'] = $name; return $this; @@ -46,14 +46,14 @@ function releaseType( $rtype ) { $type = extractFragment($rtype); - + if ( isset( $this->parameters['releasetypes'] ) ) { $this->parameters['releasetypes'] .= ' ' . $type; } else { $this->parameters['releasetypes'] = $type; } - + return $this; } @@ -71,12 +71,12 @@ $this->parameters['asin'] = $asin; return $this; } - + function limit( $limit ) { $this->parameters['limit'] = $limit; return $this; } - + function offset( $offset ) { $this->parameterList['offset'] = $offset; return $this; @@ -135,14 +135,14 @@ return $this; } } - + class mbUserFilter implements MusicBrainzFilter { private $parameters = array(); - + function createParameters() { return $this->parameters; } - + function name( $value ) { $this->parameters['name'] = $value; } diff --git a/modules/php_musicbrainz/mbLabel.php b/modules/php_musicbrainz/mbLabel.php index a94443f7..67e069ef 100644 --- a/modules/php_musicbrainz/mbLabel.php +++ b/modules/php_musicbrainz/mbLabel.php @@ -34,7 +34,7 @@ function getBeginDate() { return $this->beginDate; } function setEndDate( $endDate ) { $this->endDate = $endDate; } function getEndDate() { return $this->endDate; } - + function getUniqueName() { return empty($this->disambiguation) ? $this->name : $this->name . ' (' . $this->disambiguation . ')'; diff --git a/modules/php_musicbrainz/mbMetadata.php b/modules/php_musicbrainz/mbMetadata.php index 076bf6be..45453d6e 100644 --- a/modules/php_musicbrainz/mbMetadata.php +++ b/modules/php_musicbrainz/mbMetadata.php @@ -54,13 +54,13 @@ function &getArtistResults () { return $this->artistList; } function &getTrackResults () { return $this->trackList; } function &getReleaseResults() { return $this->releaseList; } - + function getUserList2( $remove ) { $ul = $this->userList; $this->userList = array(); return $ul; } - + function getArtistResults2( $remove ) { $al = $this->artistList; $this->artistList = array(); diff --git a/modules/php_musicbrainz/mbQuery.php b/modules/php_musicbrainz/mbQuery.php index 07afd771..df8aa4aa 100644 --- a/modules/php_musicbrainz/mbQuery.php +++ b/modules/php_musicbrainz/mbQuery.php @@ -1,9 +1,9 @@ ws = new mbWebService(); $this->ownWs = true; } - + $this->clientId = $clientId; } function getUserByName( $name ) { $metadata = $this->getFromWebService( "user", "", null, mbUserFilter().name($name) ); $list = $metadata->getUserList(true); - + if ( count($list) > 0 ) { return $list[0]; } - + throw mbResponseError("response didn't contain user data"); } - + function getArtists( mbArtistFilter $artist_filters ) { $metadata = $this->getFromWebService( "artist", "", null, $artist_filters ); return $metadata->getArtistResults2(true); @@ -63,12 +63,12 @@ $metadata = $this->getFromWebService( "release", "", null, $release_filters ); return $metadata->getReleaseResults2(true); } - + function getTracks( mbTrackFilter $track_filters ) { $metadata = $this->getFromWebService( "track", "", null, $track_filters ); return $metadata->getTrackResults2(true); } - + function getArtistById( $aID, mbArtistIncludes $artist_includes ) { try { $id = extractUuid($aID); @@ -106,7 +106,7 @@ $includeList = $includes ? $includes->createIncludeTags() : null; $filterList = $filters ? $filters->createParameters() : null; $content = $this->ws->get( $entity, $id, $includeList, $filterList ); - + try { $parser = new mbXmlParser(); $parsed_content = $parser->parse($content); diff --git a/modules/php_musicbrainz/mbRelation.php b/modules/php_musicbrainz/mbRelation.php index a03efe18..398c950f 100644 --- a/modules/php_musicbrainz/mbRelation.php +++ b/modules/php_musicbrainz/mbRelation.php @@ -4,7 +4,7 @@ const DIR_BOTH = 0; const DIR_FORWARD = 1; const DIR_BACKWARD = 2; - + const TO_ARTIST = "http://musicbrainz.org/ns/mmd-1.0#Artist"; const TO_TRACK = "http://musicbrainz.org/ns/mmd-1.0#Track"; const TO_RELEASE = "http://musicbrainz.org/ns/mmd-1.0#Release"; @@ -76,7 +76,7 @@ function getEndDate() { return $this->endDate; } - + function getDirection() { return $this->direction; } diff --git a/modules/php_musicbrainz/mbRelease.php b/modules/php_musicbrainz/mbRelease.php index 9bcf4321..27afa4db 100644 --- a/modules/php_musicbrainz/mbRelease.php +++ b/modules/php_musicbrainz/mbRelease.php @@ -3,7 +3,7 @@ class mbRelease extends MusicBrainzEntity { // Types const TYPE_NONE = "http://musicbrainz.org/ns/mmd-1.0#None"; - + const TYPE_ALBUM = "http://musicbrainz.org/ns/mmd-1.0#Album"; const TYPE_SINGLE = "http://musicbrainz.org/ns/mmd-1.0#Single"; const TYPE_EP = "http://musicbrainz.org/ns/mmd-1.0#EP"; @@ -21,7 +21,7 @@ const TYPE_PROMOTION = "http://musicbrainz.org/ns/mmd-1.0#Promotion"; const TYPE_BOOTLEG = "http://musicbrainz.org/ns/mmd-1.0#Bootleg"; const TYPE_PSEUDO_RELEASE = "http://musicbrainz.org/ns/mmd-1.0#Pseudo-Release"; - + private $title; private $textLanguage; private $textScript; diff --git a/modules/php_musicbrainz/mbReleaseEvent.php b/modules/php_musicbrainz/mbReleaseEvent.php index a41fa95b..3131ea55 100644 --- a/modules/php_musicbrainz/mbReleaseEvent.php +++ b/modules/php_musicbrainz/mbReleaseEvent.php @@ -11,7 +11,7 @@ $this->country = $country; $this->dateStr = $dateStr; } - + function setCountry ( $country ) { $this->country = $country; } function getCountry ( ) { return $this->country; } function setCatalogNumber( $c_number ) { $this->catalogNumber = $c_number; } diff --git a/modules/php_musicbrainz/mbUser.php b/modules/php_musicbrainz/mbUser.php index 86e384f7..8317bebb 100644 --- a/modules/php_musicbrainz/mbUser.php +++ b/modules/php_musicbrainz/mbUser.php @@ -4,29 +4,29 @@ private $name; private $showNag = false; private $types = array(); - + function mbUser() { } - + function setName( $name ) { $this->name = $name; } function getName() { return $this->name; } - + function getShowNag() { return $this->showNag; } - + function setShowNag( $value ) { $this->setShowNag = $value; } - + function addType( $type ) { $this->types[] = $type; } - + function getNumTypes() { return count($this->types); } - + function getType( $i ) { return $this->types[$i]; } diff --git a/modules/php_musicbrainz/mbUtil.php b/modules/php_musicbrainz/mbUtil.php index eff5f34c..4ebdb33a 100644 --- a/modules/php_musicbrainz/mbUtil.php +++ b/modules/php_musicbrainz/mbUtil.php @@ -1,7 +1,7 @@ "Bangladesh", "BE" => "Belgium", "BF" => "Burkina Faso", diff --git a/modules/php_musicbrainz/mbUtil_languagenames.php b/modules/php_musicbrainz/mbUtil_languagenames.php index 5006198d..3e56bf82 100644 --- a/modules/php_musicbrainz/mbUtil_languagenames.php +++ b/modules/php_musicbrainz/mbUtil_languagenames.php @@ -1,6 +1,6 @@ "Artificial (Other)", "ROH" => "Raeto-Romance", "SCO" => "Scots", diff --git a/modules/php_musicbrainz/mbUtil_releasetypenames.php b/modules/php_musicbrainz/mbUtil_releasetypenames.php index ad4f2bf0..a655dcdc 100644 --- a/modules/php_musicbrainz/mbUtil_releasetypenames.php +++ b/modules/php_musicbrainz/mbUtil_releasetypenames.php @@ -1,6 +1,6 @@ "None", "http://musicbrainz.org/ns/mmd-1.0#Album" => "Album", "http://musicbrainz.org/ns/mmd-1.0#Single" => "Single", diff --git a/modules/php_musicbrainz/mbWebService.php b/modules/php_musicbrainz/mbWebService.php index 0b59da34..76aa0939 100644 --- a/modules/php_musicbrainz/mbWebService.php +++ b/modules/php_musicbrainz/mbWebService.php @@ -4,7 +4,7 @@ function get ( $entity, $id, $include, $filter, $version = '1' ); function post( $entity, $id, $data, $version = '1' ); } - + class mbWebService implements IWebService { private $host; private $port; @@ -31,7 +31,7 @@ return true; } - + function close() { if ( $this->fSock != -1 ) { fclose($this->fSock); @@ -47,7 +47,7 @@ function parseHeaders( $string ) { $lines = explode( "\n", $string ); $this->lastHeaders = array(); - + foreach ( $lines as $key => $line ) { // Status line if ( $key == 0 ) { @@ -81,7 +81,7 @@ $this->lastHeaders = array(); return false; } - + function getHeaders() { return $this->lastHeaders; } @@ -91,7 +91,7 @@ $this->lastError = "Trying to write to closed socket."; return false; } - + fwrite( $this->fSock, $string . "\r\n" ); fwrite( $this->fSock, "Host: " . $this->host . "\r\n" ); fwrite( $this->fSock, "Accept: */*\r\n" ); @@ -109,7 +109,7 @@ $this->lastError = "Trying to read from closed socket."; return false; } - + $buffer = ""; while ( !feof($this->fSock) ) @@ -120,7 +120,7 @@ return $this->parseHeaders($buffer); } - + function get( $entity, $uid, $includes, $filters, $version="1" ) { $params = array(); $params['type'] = "xml"; @@ -142,17 +142,17 @@ } $URI = $this->pathPrefix . "/" . $version . "/" . $entity . "/" . $uid . "?" . $this->build_query( $params ); - + if ( $this->fSock == -1 && !$this->connect() ) return false; - + $this->sendRequest( "GET $URI HTTP/1.1" ); $this->lastResponse = $this->getResponse(); $this->close(); if ( isset($this->lastHeaders['HTTP_status']) && $this->lastHeaders['HTTP_status'] != 200 ) return false; - + return $this->lastResponse; } @@ -170,11 +170,11 @@ return $this->lastResponse; } - + function build_query( $array ) { $first = true; $query_string = ""; - + if ( !is_array($array) || sizeof($array) == 0 ) return ""; diff --git a/modules/php_musicbrainz/mbXmlParser.php b/modules/php_musicbrainz/mbXmlParser.php index aaad0126..46d39e7c 100644 --- a/modules/php_musicbrainz/mbXmlParser.php +++ b/modules/php_musicbrainz/mbXmlParser.php @@ -5,19 +5,19 @@ class mbXmlParser { private $xml_parser; private $factory; - + function mbXmlParser() { $this->xml_parser = new xmlParser(); $this->factory = new mbDefaultFactory(); } - + private function parseList( XMLNode $node, array &$list, $func ) { for ( $i = 0; $i < $node->nChildNodes(); $i++ ) { $cnode = $node->getChildNode($i); $list[] = call_user_func( array( &$this, $func ), $cnode ); } } - + private function parseResults( XMLNode $node, array &$list, $func, $type ) { for ( $i = 0; $i < $node->nChildNodes(); $i++ ) { $cnode = $node->getChildNode($i); @@ -29,7 +29,7 @@ $list[] = $to_add; } } - + private function parseRelations( XMLNode $node, MusicBrainzEntity $entity ) { $targetType = $node->getAttribute("target-type"); if ( $targetType == '' ) @@ -44,14 +44,14 @@ } } } - + private function parseUserResults( XMLNode $node, array &$userList ) { for ( $i = 0; $i < $node->nChildNodes(); $i++ ) { $cnode = $node->getChildNode($i); $userList[] = $this->createUser( $cnode ); } } - + private function createUser( XMLNode $node ) { $user = $this->factory->newUser(); for ( $i = 0; $i < $node->nChildNodes(); $i++ ) { @@ -68,7 +68,7 @@ } return $user; } - + private function createArtistAlias( XMLNode $node ) { $aa = $this->factory->newArtistAlias(); $aa->setType($node->getAttribute("type")); @@ -77,14 +77,14 @@ return $aa; } - + private function createTag( XMLNode $node ) { $tag = $this->factory->newTag(); $tag->setCount($node->getAttribute("count")); $tag->setName($node->getText()); return $tag; } - + private function createLabelAlias( XML $node ) { $la = $this->factory->newLabelAlias(); $la->setType($node->getAttribute("type")); @@ -92,13 +92,13 @@ $la->setValue($node->getText()); return $la; } - + private function createDisc( XMLNode $node ) { $disc = $this->factory->newDisc(); $disc->setId($node->getAttribute("id")); return $disc; } - + private function createReleaseEvent( XMLNode $node ) { $relEvent = $this->factory->newReleaseEvent(); $relEvent->setCountry($node->getAttribute("country")); @@ -115,7 +115,7 @@ } return $relEvent; } - + private function createLabel( XMLNode $node ) { $label = $this->factory->newLabel(); $label->setId($node->getAttribute("id")); @@ -160,7 +160,7 @@ return $label; } - + private function createArtist( XMLNode $node ) { $artist = $this->factory->newArtist(); $artist->setId($node->getAttribute("id")); @@ -207,7 +207,7 @@ return $artist; } - + private function createTrack( XMLNode $node ) { $track = $this->factory->newTrack(); $track->setId($node->getAttribute("id")); @@ -238,10 +238,10 @@ break; } } - + return $track; } - + private function createRelease( XMLNode $node ) { $release = $this->factory->newRelease(); $release->setId($node->getAttribute("id")); @@ -294,13 +294,13 @@ return $release; } - + private function createRelation( XMLNode $node, $type ) { $relation = $this->factory->newRelation(); $relation->setType(extractFragment($node->getAttribute("type"))); // TODO: fixme $relation->setTargetType($type); $relation->setTargetId($node->getAttribute("target")); - + $dir = mbRelation::DIR_BOTH; switch( strtolower($node->getAttribute("direction")) ) { case "forward": @@ -340,7 +340,7 @@ return $relation; } - + function parse( $data ) { $nodes = $this->xml_parser->parse( $data ); @@ -349,7 +349,7 @@ $md = new mbMetadata(); - + for ( $i = 0; $i < $nodes->nChildNodes(); $i++ ) { $node = $nodes->getChildNode($i); $name = strtolower($node->getName()); diff --git a/modules/php_musicbrainz/xml/xmlParser.php b/modules/php_musicbrainz/xml/xmlParser.php index 1d0058da..7e3311cf 100644 --- a/modules/php_musicbrainz/xml/xmlParser.php +++ b/modules/php_musicbrainz/xml/xmlParser.php @@ -15,7 +15,7 @@ function getParentNode() { return $this->parentNode; } - + function nChildNodes() { return sizeof($this->childNodes); } @@ -46,7 +46,7 @@ return $this->attributes['TEXT']; } } - + class xmlParser { private $_parser; private $_root_node = null; @@ -69,7 +69,7 @@ public function lastError() { return $this->_last_error; } - + public function parse( $data ) { if ( !xml_parse( $this->_parser, $data ) ) { $this->_last_error = xml_get_current_line_number($this->_parser) . ": ". xml_error_string($this->_parser); @@ -77,7 +77,7 @@ } return $this->_root_node; } - + private function start_element_handler( $parser, $name, $attribs ) { if ( !$this->_root_node ) { $new_node = new XMLNode( $name, $attribs ); @@ -90,14 +90,14 @@ $old_node->setChildNode( $new_node ); $this->_curr_node = $new_node; } - + } private function text_handler( $parser, $text ) { if ( $this->_curr_node ) $this->_curr_node->setText( $text ); } - + private function end_element_handler( $parser, $name ) { if ( $this->_root_node ) { $this->_curr_node = $this->_curr_node->getParentNode(); diff --git a/modules/plugins/Lastfm.plugin.php b/modules/plugins/Lastfm.plugin.php index 99ac5fd7..24f9862f 100644 --- a/modules/plugins/Lastfm.plugin.php +++ b/modules/plugins/Lastfm.plugin.php @@ -20,31 +20,31 @@ */ -class AmpacheLastfm { +class AmpacheLastfm { - public $name ='Last.FM'; - public $description ='Records your played songs to your Last.FM Account'; + public $name ='Last.FM'; + public $description ='Records your played songs to your Last.FM Account'; public $url =''; public $version ='000003'; public $min_ampache ='340007'; public $max_ampache ='340008'; - // These are internal settings used by this class, run this->load to + // These are internal settings used by this class, run this->load to // fill em out - private $username; - private $password; + private $username; + private $password; private $hostname; - private $port; - private $path; + private $port; + private $path; private $challenge; /** * Constructor * This function does nothing... */ - public function __construct() { + public function __construct() { - return true; + return true; } // PluginLastfm @@ -53,19 +53,19 @@ class AmpacheLastfm { * This is a required plugin function it inserts the required preferences * into Ampache */ - public function install() { + public function install() { // Check and see if it's already installed (they've just hit refresh, those dorks) - if (Preference::exists('lastfm_user')) { return false; } + if (Preference::exists('lastfm_user')) { return false; } - Preference::insert('lastfm_user','Last.FM Username','','25','string','plugins'); - Preference::insert('lastfm_pass','Last.FM Password','','25','string','plugins'); - Preference::insert('lastfm_port','Last.FM Submit Port','','25','string','internal'); - Preference::insert('lastfm_host','Last.FM Submit Host','','25','string','internal'); - Preference::insert('lastfm_url','Last.FM Submit URL','','25','string','internal'); - Preference::insert('lastfm_challenge','Last.FM Submit Challenge','','25','string','internal'); + Preference::insert('lastfm_user','Last.FM Username','','25','string','plugins'); + Preference::insert('lastfm_pass','Last.FM Password','','25','string','plugins'); + Preference::insert('lastfm_port','Last.FM Submit Port','','25','string','internal'); + Preference::insert('lastfm_host','Last.FM Submit Host','','25','string','internal'); + Preference::insert('lastfm_url','Last.FM Submit URL','','25','string','internal'); + Preference::insert('lastfm_challenge','Last.FM Submit Challenge','','25','string','internal'); - return true; + return true; } // install @@ -74,14 +74,14 @@ class AmpacheLastfm { * This is a required plugin function it removes the required preferences from * the database returning it to its origional form */ - public function uninstall() { + public function uninstall() { - Preference::delete('lastfm_pass'); - Preference::delete('lastfm_user'); - Preference::delete('lastfm_url'); - Preference::delete('lastfm_host'); - Preference::delete('lastfm_port'); - Preference::delete('lastfm_challenge'); + Preference::delete('lastfm_pass'); + Preference::delete('lastfm_user'); + Preference::delete('lastfm_url'); + Preference::delete('lastfm_host'); + Preference::delete('lastfm_port'); + Preference::delete('lastfm_challenge'); } // uninstall @@ -90,76 +90,76 @@ class AmpacheLastfm { * This takes care of queueing and then submiting the tracks eventually this will make sure * that you've haven't */ - public function submit($song,$user_id) { + public function submit($song,$user_id) { // Before we start let's pull the last song submited by this user - $previous = Stats::get_last_song($user_id); + $previous = Stats::get_last_song($user_id); + + $diff = time() - $previous['date']; - $diff = time() - $previous['date']; - // Make sure it wasn't within the last min - if ($diff < 60) { - debug_event('LastFM','Last song played within ' . $diff . ' seconds, not recording stats','3'); - return false; - } - - if ($song->time < 30) { - debug_event('LastFM','Song less then 30 seconds not queueing','3'); - return false; - } - - // Make sure there's actually a username and password before we keep going - if (!$this->username || !$this->password) { return false; } - - // Create our scrobbler with everything this time and then queue it - $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge); - - // Check to see if the scrobbling works - if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { - // Depending on the error we might need to do soemthing here - return false; - } - - // Go ahead and submit it now - if (!$scrobbler->submit_tracks()) { - debug_event('LastFM','Error Submit Failed: ' . $scrobbler->error_msg,'3'); - if ($scrobbler->reset_handshake) { - debug_event('LastFM','Re-running Handshake due to error','3'); - $this->set_handshake($user_id); - // Try try again - if ($scrobbler->submit_tracks()) { - return true; - } - } - return false; + if ($diff < 60) { + debug_event('LastFM','Last song played within ' . $diff . ' seconds, not recording stats','3'); + return false; } - debug_event('LastFM','Submission Successful','5'); - - return true; + if ($song->time < 30) { + debug_event('LastFM','Song less then 30 seconds not queueing','3'); + return false; + } + + // Make sure there's actually a username and password before we keep going + if (!$this->username || !$this->password) { return false; } + + // Create our scrobbler with everything this time and then queue it + $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge); + + // Check to see if the scrobbling works + if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { + // Depending on the error we might need to do soemthing here + return false; + } + + // Go ahead and submit it now + if (!$scrobbler->submit_tracks()) { + debug_event('LastFM','Error Submit Failed: ' . $scrobbler->error_msg,'3'); + if ($scrobbler->reset_handshake) { + debug_event('LastFM','Re-running Handshake due to error','3'); + $this->set_handshake($user_id); + // Try try again + if ($scrobbler->submit_tracks()) { + return true; + } + } + return false; + } + + debug_event('LastFM','Submission Successful','5'); + + return true; } // submit - /** + /** * set_handshake * This runs a handshake and properly updates the preferences as needed, it returns the data - * as an array so we don't have to requery the db. This requires a userid so it knows who's + * as an array so we don't have to requery the db. This requires a userid so it knows who's * crap to update */ - public function set_handshake($user_id) { - - $scrobbler = new scrobbler($this->username,$this->password); - $data = $scrobbler->handshake(); + public function set_handshake($user_id) { - if (!$data) { - debug_event('LastFM','Handshake Failed: ' . $scrobbler->error_msg,'3'); - return false; - } + $scrobbler = new scrobbler($this->username,$this->password); + $data = $scrobbler->handshake(); - $this->hostname = $data['submit_host']; - $this->port = $data['submit_port']; - $this->path = $data['submit_url']; - $this->challenge = $data['challenge']; + if (!$data) { + debug_event('LastFM','Handshake Failed: ' . $scrobbler->error_msg,'3'); + return false; + } + + $this->hostname = $data['submit_host']; + $this->port = $data['submit_port']; + $this->path = $data['submit_url']; + $this->challenge = $data['challenge']; // Update the preferences Preference::update('lastfm_port',$user_id,$data['submit_port']); @@ -167,7 +167,7 @@ class AmpacheLastfm { Preference::update('lastfm_url',$user_id,$data['submit_url']); Preference::update('lastfm_challenge',$user_id,$data['challenge']); - return true; + return true; } // set_handshake @@ -176,40 +176,40 @@ class AmpacheLastfm { * This loads up the data we need into this object, this stuff comes from the preferences * it's passed as a key'd array */ - public function load($data,$user_id) { + public function load($data,$user_id) { - if (strlen(trim($data['lastfm_user']))) { - $this->username = trim($data['lastfm_user']); - } - else { - debug_event('LastFM','No Username, not scrobbling','3'); - return false; - } - if (strlen(trim($data['lastfm_pass']))) { - $this->password = trim($data['lastfm_pass']); - } - else { - debug_event('LastFM','No Password, not scrobbling','3'); - return false; - } + if (strlen(trim($data['lastfm_user']))) { + $this->username = trim($data['lastfm_user']); + } + else { + debug_event('LastFM','No Username, not scrobbling','3'); + return false; + } + if (strlen(trim($data['lastfm_pass']))) { + $this->password = trim($data['lastfm_pass']); + } + else { + debug_event('LastFM','No Password, not scrobbling','3'); + return false; + } // If we don't have the other stuff try to get it before giving up - if (!$data['lastfm_host'] || !$data['lastfm_port'] || !$data['lastfm_url'] || !$data['lastfm_challenge']) { - debug_event('LastFM','Running Handshake, missing information','3'); - if (!$this->set_handshake($user_id)) { + if (!$data['lastfm_host'] || !$data['lastfm_port'] || !$data['lastfm_url'] || !$data['lastfm_challenge']) { + debug_event('LastFM','Running Handshake, missing information','3'); + if (!$this->set_handshake($user_id)) { debug_event('LastFM','Handshake failed, you lose','3'); - return false; - } - } - else { + return false; + } + } + else { $this->hostname = $data['lastfm_host']; $this->port = $data['lastfm_port']; $this->path = $data['lastfm_url']; $this->challenge = $data['lastfm_challenge']; - } - + } - return true; + + return true; } // load diff --git a/modules/plugins/Librefm.plugin.php b/modules/plugins/Librefm.plugin.php index 9b22b183..36d72603 100644 --- a/modules/plugins/Librefm.plugin.php +++ b/modules/plugins/Librefm.plugin.php @@ -20,31 +20,31 @@ */ -class Ampachelibrefm { +class Ampachelibrefm { - public $name ='Libre.FM'; - public $description ='Records your played songs to your Libre.FM Account'; + public $name ='Libre.FM'; + public $description ='Records your played songs to your Libre.FM Account'; public $url =''; public $version ='000001'; public $min_ampache ='350001'; public $max_ampache ='360008'; - // These are internal settings used by this class, run this->load to + // These are internal settings used by this class, run this->load to // fill em out - private $username; - private $password; + private $username; + private $password; private $hostname; - private $port; - private $path; + private $port; + private $path; private $challenge; /** * Constructor * This function does nothing... */ - public function __construct() { + public function __construct() { - return true; + return true; } // Pluginlibrefm @@ -53,19 +53,19 @@ class Ampachelibrefm { * This is a required plugin function it inserts the required preferences * into Ampache */ - public function install() { + public function install() { // Check and see if it's already installed (they've just hit refresh, those dorks) - if (Preference::exists('librefm_user')) { return false; } + if (Preference::exists('librefm_user')) { return false; } - Preference::insert('librefm_user','Libre.FM Username','','25','string','plugins'); - Preference::insert('librefm_pass','Libre.FM Password','','25','string','plugins'); - Preference::insert('librefm_port','Libre.FM Submit Port','','25','string','internal'); - Preference::insert('librefm_host','Libre.FM Submit Host','','25','string','internal'); - Preference::insert('librefm_url','Libre.FM Submit URL','','25','string','internal'); - Preference::insert('librefm_challenge','Libre.FM Submit Challenge','','25','string','internal'); + Preference::insert('librefm_user','Libre.FM Username','','25','string','plugins'); + Preference::insert('librefm_pass','Libre.FM Password','','25','string','plugins'); + Preference::insert('librefm_port','Libre.FM Submit Port','','25','string','internal'); + Preference::insert('librefm_host','Libre.FM Submit Host','','25','string','internal'); + Preference::insert('librefm_url','Libre.FM Submit URL','','25','string','internal'); + Preference::insert('librefm_challenge','Libre.FM Submit Challenge','','25','string','internal'); - return true; + return true; } // install @@ -74,14 +74,14 @@ class Ampachelibrefm { * This is a required plugin function it removes the required preferences from * the database returning it to its origional form */ - public function uninstall() { + public function uninstall() { - Preference::delete('librefm_pass'); - Preference::delete('librefm_user'); - Preference::delete('librefm_url'); - Preference::delete('librefm_host'); - Preference::delete('librefm_port'); - Preference::delete('librefm_challenge'); + Preference::delete('librefm_pass'); + Preference::delete('librefm_user'); + Preference::delete('librefm_url'); + Preference::delete('librefm_host'); + Preference::delete('librefm_port'); + Preference::delete('librefm_challenge'); } // uninstall @@ -90,76 +90,76 @@ class Ampachelibrefm { * This takes care of queueing and then submiting the tracks eventually this will make sure * that you've haven't */ - public function submit($song,$user_id) { + public function submit($song,$user_id) { // Before we start let's pull the last song submited by this user - $previous = Stats::get_last_song($user_id); + $previous = Stats::get_last_song($user_id); + + $diff = time() - $previous['date']; - $diff = time() - $previous['date']; - // Make sure it wasn't within the last min - if ($diff < 60) { - debug_event('librefm','Last song played within ' . $diff . ' seconds, not recording stats','3'); - return false; - } - - if ($song->time < 30) { - debug_event('librefm','Song less then 30 seconds not queueing','3'); - return false; - } - - // Make sure there's actually a username and password before we keep going - if (!$this->username || !$this->password) { return false; } - - // Create our scrobbler with everything this time and then queue it - $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge,'turtle.libre.fm'); - - // Check to see if the scrobbling works - if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { - // Depending on the error we might need to do soemthing here - return false; - } - - // Go ahead and submit it now - if (!$scrobbler->submit_tracks()) { - debug_event('librefm','Error Submit Failed: ' . $scrobbler->error_msg,'3'); - if ($scrobbler->reset_handshake) { - debug_event('librefm','Re-running Handshake due to error','3'); - $this->set_handshake($user_id); - // Try try again - if ($scrobbler->submit_tracks()) { - return true; - } - } - return false; + if ($diff < 60) { + debug_event('librefm','Last song played within ' . $diff . ' seconds, not recording stats','3'); + return false; } - debug_event('librefm','Submission Successful','5'); - - return true; + if ($song->time < 30) { + debug_event('librefm','Song less then 30 seconds not queueing','3'); + return false; + } + + // Make sure there's actually a username and password before we keep going + if (!$this->username || !$this->password) { return false; } + + // Create our scrobbler with everything this time and then queue it + $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge,'turtle.libre.fm'); + + // Check to see if the scrobbling works + if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) { + // Depending on the error we might need to do soemthing here + return false; + } + + // Go ahead and submit it now + if (!$scrobbler->submit_tracks()) { + debug_event('librefm','Error Submit Failed: ' . $scrobbler->error_msg,'3'); + if ($scrobbler->reset_handshake) { + debug_event('librefm','Re-running Handshake due to error','3'); + $this->set_handshake($user_id); + // Try try again + if ($scrobbler->submit_tracks()) { + return true; + } + } + return false; + } + + debug_event('librefm','Submission Successful','5'); + + return true; } // submit - /** + /** * set_handshake * This runs a handshake and properly updates the preferences as needed, it returns the data - * as an array so we don't have to requery the db. This requires a userid so it knows who's + * as an array so we don't have to requery the db. This requires a userid so it knows who's * crap to update */ - public function set_handshake($user_id) { - - $scrobbler = new scrobbler($this->username,$this->password,'','','','','turtle.libre.fm'); - $data = $scrobbler->handshake(); + public function set_handshake($user_id) { - if (!$data) { - debug_event('librefm','Handshake Failed: ' . $scrobbler->error_msg,'3'); - return false; - } + $scrobbler = new scrobbler($this->username,$this->password,'','','','','turtle.libre.fm'); + $data = $scrobbler->handshake(); - $this->hostname = $data['submit_host']; - $this->port = $data['submit_port']; - $this->path = $data['submit_url']; - $this->challenge = $data['challenge']; + if (!$data) { + debug_event('librefm','Handshake Failed: ' . $scrobbler->error_msg,'3'); + return false; + } + + $this->hostname = $data['submit_host']; + $this->port = $data['submit_port']; + $this->path = $data['submit_url']; + $this->challenge = $data['challenge']; // Update the preferences Preference::update('librefm_port',$user_id,$data['submit_port']); @@ -167,7 +167,7 @@ class Ampachelibrefm { Preference::update('librefm_url',$user_id,$data['submit_url']); Preference::update('librefm_challenge',$user_id,$data['challenge']); - return true; + return true; } // set_handshake @@ -176,40 +176,40 @@ class Ampachelibrefm { * This loads up the data we need into this object, this stuff comes from the preferences * it's passed as a key'd array */ - public function load($data,$user_id) { - - if (strlen(trim($data['librefm_user']))) { - $this->username = trim($data['librefm_user']); - } - else { - debug_event('librefm','No Username, not scrobbling','3'); - return false; - } - if (strlen(trim($data['librefm_pass']))) { - $this->password = trim($data['librefm_pass']); - } - else { - debug_event('librefm','No Password, not scrobbling','3'); - return false; - } + public function load($data,$user_id) { + + if (strlen(trim($data['librefm_user']))) { + $this->username = trim($data['librefm_user']); + } + else { + debug_event('librefm','No Username, not scrobbling','3'); + return false; + } + if (strlen(trim($data['librefm_pass']))) { + $this->password = trim($data['librefm_pass']); + } + else { + debug_event('librefm','No Password, not scrobbling','3'); + return false; + } // If we don't have the other stuff try to get it before giving up - if (!$data['librefm_host'] || !$data['librefm_port'] || !$data['librefm_url'] || !$data['librefm_challenge']) { - debug_event('librefm','Running Handshake, missing information','3'); - if (!$this->set_handshake($user_id)) { + if (!$data['librefm_host'] || !$data['librefm_port'] || !$data['librefm_url'] || !$data['librefm_challenge']) { + debug_event('librefm','Running Handshake, missing information','3'); + if (!$this->set_handshake($user_id)) { debug_event('librefm','Handshake failed, you lose','3'); - return false; - } - } - else { + return false; + } + } + else { $this->hostname = $data['librefm_host']; $this->port = $data['librefm_port']; $this->path = $data['librefm_url']; $this->challenge = $data['librefm_challenge']; - } - + } - return true; + + return true; } // load diff --git a/modules/validatemail/validateEmail.php b/modules/validatemail/validateEmail.php index 3fc83026..78bbf5f6 100644 --- a/modules/validatemail/validateEmail.php +++ b/modules/validatemail/validateEmail.php @@ -26,7 +26,7 @@ Organization: webdev.berber.co.il Date: April 10th, 1999 Changes: - The script now handles all kinds of domains (not only @xxx.yyy) as before. - Added a debugging mode which also works as a verbose mode. - + By: Frank Vogel vogel@simec.com Organization: Simec Corp. (http://www.simec.com) Date: June 13th, 2000 @@ -65,10 +65,10 @@ Organization: KillerSoft < http://www.killersoft.com/ > with EHLO. - Added routines to listen for multi-line output from servers. - Fixed all commands ending in "\n" to end in "\r\n" as specified by accurate SMTP - communication. THIS FIXES THE "HANG" PROBLEM EXPERIENCED WITH MANY MAIL SERVERS, + communication. THIS FIXES THE "HANG" PROBLEM EXPERIENCED WITH MANY MAIL SERVERS, INCLUDING AOL.COM. (See Disclaimers about AOL.com connections, though ...) - Added support for Jeffrey E.F. Friedl's definitive email format regex, translated - from perl into PHP. Will reject email addresses with invalid formatting before + from perl into PHP. Will reject email addresses with invalid formatting before opening any server connections. - Changed initial "listening" routine to listen for one of two SMTP greeting responses (220 or 421) instead of just listening for anything. validateEmail is now well-behaved @@ -80,7 +80,7 @@ Organization: KillerSoft < http://www.killersoft.com/ > - Modified comments where Shane Gibson's were no longer needed or accurate (due to changes). Added the comments for features that didn't exist in Shane's version. - Incremented version number. - + Disclaimers: - All additions and modifications Copyright 2002 KillerSoft.com. - Program is free for any use as long as these notes & credits remain intact. - Yes, I know there is no foolproof way to validate an e-mail address. But this is better than @@ -100,7 +100,7 @@ Organization: KillerSoft < http://www.killersoft.com/ > through alternate means. So -- this script won't help you in validating AOL.com (and affiliated) e-mail addresses. BUT ... at least it won't choke/hang on them either, as previous versions of this script would. - + - Please send bugs, comments or suggestions to info@killersoft.com! */ @@ -144,7 +144,7 @@ function validateEmail ( $email, $verbose=0 ) { global $SERVER_NAME; // DEFINE PREFERENCES - + // Passed along with the HELO/EHLO statement. // Leave blank to use $SERVER_NAME. // Note that most modern MTAs will ignore (but require) whatever you say here ... @@ -161,30 +161,30 @@ function validateEmail ( $email, $verbose=0 ) { if (Config::get('mail_domain')) { $serverName = Config::get('mail_domain'); - } + } else { $serverName = "domain.tld"; } // MAIL FROM -- who's asking? // Good values: nobody, postmaster, info, buckwheat, gumby $from = "info"; - + // fsockopen() timeout - in seconds $socketTimeout = 15; - + // waitTimeout - how long we'll wait for a server to respond after // a successful connection. In seconds. // Recommended to keep this above 35 seconds - some servers are really slow. $waitTimeout = 50; - + // MX Server cutoff // Some hosts (like hotmail.com) have MANY MX hosts -- 12 or more. // Set this to a number where you'd like to say "I get the picture" // ... so you don't wind up having to hit EVERY MX host. $mxcutoff = 15; - + // END OF PREFERENCES - + /////////////////////////////////////////////////////////////////////////////// // DO NOT EDIT BELOW THIS LINE /////////////////////////////////////////////////////////////////////////////// @@ -195,16 +195,16 @@ function validateEmail ( $email, $verbose=0 ) { // Let's give good commands $CRLF = "\r\n"; - + // Make a few adjustments for verbose mode if ( $verbose ) { // Version $version = "validateEmail 2.0 - http://killersoft.com/contrib/"; - + // Start stopwatch list ( $msecStart, $secStart ) = explode ( " ", microtime() ); - + // Adjust verbose output format // for php.cgi or webserver interface $sapi_type = php_sapi_name(); @@ -231,29 +231,29 @@ function validateEmail ( $email, $verbose=0 ) { eval("echo \"Internal: $version - running as ".AddSlashes($sapi_type)."\"; $vNL"); } } - + // How we'll identify ourselves in SMTP HELO/EHLO argument if ( $serverName == "" ) $serverName = "$SERVER_NAME"; if ( $serverName == "" ) $serverName = "localhost"; - + // Initialize return values with default $return[0] = false; $return[1] = "Invalid email address (bad domain name)"; $return[2] = false; $return[3] = ""; - + // make sure that we're dealing with a valid email address format $isValid = true; // just in case validateEmailFormat is not available if ( function_exists('validateEmailFormat') ) $isValid = validateEmailFormat ( $email ); - + // abort if necessary if ( !$isValid ) { if ( $verbose ) eval("echo \"Internal: $email format is invalid! Quitting ...\"; $vNL"); return $return; - + } else { if ( $verbose ) eval("echo \"Internal: $email is a valid RFC 822 formatted address\"; $vNL"); - + // assign our user part and domain parts respectively to seperate // variables list ( $user, $domain ) = explode ( "@", $email ); @@ -261,20 +261,20 @@ function validateEmail ( $email, $verbose=0 ) { eval("echo \"Internal: user ..... $user\"; $vNL"); eval("echo \"Internal: domain ... $domain\"; $vNL"); } - + // split up the domain into sub-parts $arr = explode ( ".", $domain ); - + // figure out how many parts there are in the host/domain name portion $count = count ( $arr ); - + // flag to indicate success $bSuccess = false; - + // we try this for each qualification step of domain name // (from full qualified to TopLevel) for ( $i = 0; $i < $count - 1 && !$bSuccess; $i = $i + 1 ) { - + // create the domain name $domain = ""; for ( $j = $i; $j < $count; $j = $j + 1 ) { @@ -284,20 +284,20 @@ function validateEmail ( $email, $verbose=0 ) { $domain = $domain . "."; } if ( $verbose ) eval("echo \"Internal: checking DNS for $domain ... \"; $vNL"); - + // Strict Mail Check if($mail_check == "strict") { // check that an MX record exists for Top-Level domain // If it exists, start our email address checking - if (function_exists('checkdnsrr')) { + if (function_exists('checkdnsrr')) { if ( checkdnsrr ( $domain, "MX" ) ) { - + // Okay -- we've got a valid DNS reverse record. if ( $verbose ) eval("echo \"Internal: ... Check DNS RR OK!\"; $vNL"); // Test that MX record for host exists, // then fill 'mxhosts' and 'weight' arrays with correct info if ( getmxrr ( $domain, $mxhosts, $weight ) ) { - + // Now we've got MX records if ( $verbose ) { eval("echo \"Internal: MX LOOKUP RESULTS:\"; $vNL"); @@ -311,18 +311,18 @@ function validateEmail ( $email, $verbose=0 ) { // determine our MX host cutoff $mxstop = ($mxcount > $mxcutoff) ? $mxcutoff : $mxcount; for ( $i = 0; $i < $mxstop ; $i++ ) { - + // open socket on port 25 to mxhost, setting // returned socket pointer to $sp if( $verbose ) eval("echo \"Internal: attempting to open $mxhosts[$i] ...\"; $vNL"); $sp = fsockopen ( $mxhosts[$i], 25, $errno, $errstr, $socketTimeout); - + // Greeting Code default // Sets default greeting code to 421, just in case we // don't ever hear ANYTHING from this host. // If we hear nothing, we'll want to skip it. $greetCode = "421"; - + // if $sp connection is good, let's rock on if ( $sp ) { if ( $verbose ) { @@ -334,17 +334,17 @@ function validateEmail ( $email, $verbose=0 ) { $msec = 0; // milisec count $tsec = 0; // tensec count $out = ""; - + // set our created socket for $sp to // non-blocking mode so that our fgets() // calls will return with a quickness set_socket_blocking ( $sp, false ); - + // as long as our 'out' variable does not begin // with a valid SMTP greeting (220 or 421), // keep looping (do) until we get something do { - + // prepare for clean debug output if necessary // (puts a line break after the waitMarkers) if ( $verbose && $msec > 0 ) { @@ -354,7 +354,7 @@ function validateEmail ( $email, $verbose=0 ) { // output of the stream assigned to // 'out' variable $out = fgets ( $sp, 2500 ); - + // Check for multi-line output (###-) if ( preg_match ( "/^2..-/", $out ) ) { $end = false; @@ -369,9 +369,9 @@ function validateEmail ( $email, $verbose=0 ) { } } } - + if ( $verbose && $out != "" ) eval("$clean echo \"Server: ".AddSlashes($out)."\"; $vNL"); - + // if we get a "220" code (service ready), // we're ready to rock on if ( substr ( $out, 0, 3 ) == "220" ) { @@ -384,25 +384,25 @@ function validateEmail ( $email, $verbose=0 ) { } else { $send = "HELO"; } - + // Set Greeting Code $greetCode = "220"; - + } - + // else if ... // Perhaps we've gotten a 421 Temporarily Refused error else if ( substr ( $out, 0, 3 ) == "421" ) { - + //if ( $verbose ) echo " ... moving on\n"; if ( $verbose ) eval("echo \"Internal: $mxhosts[$i] temporarily rejected connection. (421 response)\"; $vNL"); $return[2] = false; // Set Greeting Code $greetCode = "421"; break; // get out of this loop - + } - + // increase our waitTimeout counters // if we still haven't heard anything ... // Note that the time looping isn't an exact science @@ -426,34 +426,34 @@ function validateEmail ( $email, $verbose=0 ) { } $msec = $msec + 0.25; usleep(250000); - + } elseif ( $msec == $waitTimeout ) { - + // let's get out of here. Toooo sloooooww ... if ( $verbose ) eval("$clean echo \"Internal: !! we've waited $waitTimeout seconds !!\nbreaking ...\"; $vNL"); break; } - - + + // end of 'do' loop } while ( substr ( $out, 0, 3 ) != "220" ); - + // Make sure we got a "220" greetCode // before we start shoveling requests // at this server. if ( $greetCode == "220" ) { - + // reset our file pointer to blocking mode, // so we can wait for communication to finish // before moving on ... set_socket_blocking ( $sp, true ); - + // talk to the MX mail server, attempt to validate // ourself. Use "HELO" or "EHLO", as determined above fputs ( $sp, "$send $serverName"."$CRLF" ); if ( $verbose ) eval("echo \"Client: $send $serverName\"; $vNL"); - + // get the mail server's reply, check it // $originalOutput = fgets ( $sp, 2500 ); @@ -472,12 +472,12 @@ function validateEmail ( $email, $verbose=0 ) { } } if ( $verbose ) eval("echo \"Server: ".AddSlashes($originalOutput)."\"; $vNL"); - - + + // if there's a HELP option, let's see it if ( $verbose ) { if( preg_match( "/250.HELP/m", $originalOutput ) && $verbose == true ) { - + eval("echo \"Internal: VERBOSE-MODE ONLY: Getting the HELP output\"; $vNL"); // Get the output of the HELP command fputs ( $sp, "HELP"."$CRLF" ); @@ -499,14 +499,14 @@ function validateEmail ( $email, $verbose=0 ) { } } if ( $verbose ) eval("echo \"Server: ".AddSlashes($output)."\"; $vNL"); - + } } - + // Give the MAIL FROM: header to the server fputs ( $sp, "MAIL FROM: <$from" . "@" . "$serverName" . ">"."$CRLF"); if ( $verbose ) eval("echo \"Client: MAIL FROM: $leftCarrot"."$from" . "@" . "$serverName" . "$rightCarrot\"; $vNL"); - + // Get output again $output = fgets ( $sp, 2500 ); // Check for multi-line positive output @@ -524,11 +524,11 @@ function validateEmail ( $email, $verbose=0 ) { } } if ( $verbose ) eval("echo \"Server: ".AddSlashes($output)."\"; $vNL"); - + // Give the RCPT TO: header for the email address we're testing fputs ( $sp, "RCPT TO: <$email>"."$CRLF" ); if ( $verbose ) eval("echo \"Client: RCPT TO: $leftCarrot"."$email"."$rightCarrot\"; $vNL"); - + // Get output again // This will be the one we check for validity $output = fgets ( $sp, 2500 ); @@ -547,19 +547,19 @@ function validateEmail ( $email, $verbose=0 ) { } } if ( $verbose ) eval("echo \"Server: ".AddSlashes($output)."\"; $vNL"); - + // test the last reply code from the mail server // for the 250 (okay) response if ( substr ( $output, 0, 3 ) == "250" ) { - + // set our true/false(ness) // array item for testing $return[0] = true; $return[1] = $output; if ( $verbose ) eval("echo \"Internal: Check for 250 ... Recipient OK\"; $vNL"); - + } else { - + // we didn't get a 250 // may be a bogus address if ( $verbose ) eval("echo \"Internal: Check for 250 ... Response did not begin with 250!\"; $vNL"); @@ -567,19 +567,19 @@ function validateEmail ( $email, $verbose=0 ) { // reply for user to test if they want $return[0] = false; $return[1] = $output; - + } - + // tell the mail server we're done fputs ( $sp, "QUIT"."$CRLF" ); if ( $verbose ) { eval("echo \"Client: QUIT\"; $vNL"); - eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL $vNL"); + eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL $vNL"); } - + // close the socket/file pointer fclose ( $sp ); - + // If we got a good response back on RCPT TO, // break here // Otherwise, keep trying MX servers until we @@ -588,36 +588,36 @@ function validateEmail ( $email, $verbose=0 ) { if ( $return[0] == true ) { if ( $verbose ) { eval("echo \"Internal: Recipient is OK - thanks, $mxhosts[$i]!\"; $vNL"); - eval("echo \"Internal: Stop checking MX hosts ...\"; $vNL"); + eval("echo \"Internal: Stop checking MX hosts ...\"; $vNL"); } $bSuccess = true; break; } - + } else { - + // greetCode wasn't "220" // we better skip this one and move on if ( $verbose ) eval("echo \"Internal: SKIPPING $mxhosts[$i] -- never got 220 welcome\"; $vNL"); // close out this connection fclose ( $sp ); - + } // end of greetCode check - + } else { // $sp socket pointer was false -- couldn't open it if ( $verbose ) { - eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL"); + eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL"); eval("echo \"Internal: could not open socket to $mxhosts[$i]!\"; $vNL"); eval("echo \"fsockopen error $errno: $errstr\"; $vNL"); - eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL $vNL"); + eval("echo \"* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\"; $vNL $vNL"); } $return[0] = false; $return[1] = "fsockopen error $errno: $errstr"; } // end of $sp check - + } // end for $mxhosts - + } // getmxrr test else { // getmxrr failed @@ -625,7 +625,7 @@ function validateEmail ( $email, $verbose=0 ) { $return[0] = false; $return[1] = "554 No MX records found for $domain"; } // end getmxrr test - + } // continue checkdnsrr test else { if ( $verbose ) eval("echo \"Internal: No DNS Reverse Record available!\"; $vNL"); @@ -649,9 +649,9 @@ function validateEmail ( $email, $verbose=0 ) { } } // end walking through each domain possibility - + } // end isValid - + // output elapsed time if Verbose if ( $verbose ) { list ( $msecStop, $secStop ) = explode ( " ", microtime() ); @@ -660,7 +660,7 @@ function validateEmail ( $email, $verbose=0 ) { eval("echo \"Internal: VERBOSE-MODE execution time: $elapsedTime seconds (silent mode somewhat faster)\"; $vNL"); if ( $sapi_type != "cgi" ) echo ""; } - + // return the array for the user to test against return $return; diff --git a/modules/validatemail/validateEmailFormat.php b/modules/validatemail/validateEmailFormat.php index 94fde197..14ff9cff 100644 --- a/modules/validatemail/validateEmailFormat.php +++ b/modules/validatemail/validateEmailFormat.php @@ -87,7 +87,7 @@ function validateEmailFormat ( $email ) { // Impossible to do properly with a regex, I make do by allowing at most // one level of nesting. $ctext = " [^$esc$NonASCII$CRlist()] "; - + // $Cnested matches one non-nested comment. // It is unrolled, with normal of $ctext, special of $quoted_pair. $Cnested = ""; @@ -95,7 +95,7 @@ function validateEmailFormat ( $email ) { $Cnested .= "$ctext*"; // normal* $Cnested .= "(?: $quoted_pair $ctext* )*"; // (special normal*)* $Cnested .= "$CloseParen"; // ) - + // $comment allows one level of nested parentheses // It is unrolled, with normal of $ctext, special of ($quoted_pair|$Cnested) $comment = ""; @@ -106,29 +106,29 @@ function validateEmailFormat ( $email ) { $comment .= "$ctext*"; // normal* $comment .= ")*"; // )* $comment .= "$CloseParen"; // ) - + // ********************************************* // $X is optional whitespace/comments $X = ""; $X .= "[$space$tab]*"; // Nab whitespace $X .= "(?: $comment [$space$tab]* )*"; // If comment found, allow more spaces - - + + // Item 10: atom $atom_char = "[^($space)<>\@,;:\".$esc$OpenBR$CloseBR$ctrl$NonASCII]"; $atom = ""; $atom .= "$atom_char+"; // some number of atom characters ... $atom .= "(?!$atom_char)"; // ... not followed by something that // could be part of an atom - + // Item 11: doublequoted string, unrolled. $quoted_str = ""; $quoted_str .= "\""; // " $quoted_str .= "$qtext *"; // normal $quoted_str .= "(?: $quoted_pair $qtext * )*"; // ( special normal* )* $quoted_str .= "\""; // " - - + + // Item 7: word is an atom or quoted string $word = ""; $word .= "(?:"; @@ -136,10 +136,10 @@ function validateEmailFormat ( $email ) { $word .= "|"; // or $word .= "$quoted_str"; // Quoted string $word .= ")"; - + // Item 12: domain-ref is just an atom $domain_ref = $atom; - + // Item 13: domain-literal is like a quoted string, but [...] instead of "..." $domain_lit = ""; $domain_lit .= "$OpenBR"; // [ @@ -154,28 +154,28 @@ function validateEmailFormat ( $email ) { $sub_domain .= "$domain_lit"; $sub_domain .= ")"; $sub_domain .= "$X"; // optional trailing comments - + // Item 6: domain is a list of subdomains separated by dots $domain = ""; $domain .= "$sub_domain"; $domain .= "(?:"; $domain .= "$Period $X $sub_domain"; $domain .= ")*"; - + // Item 8: a route. A bunch of "@ $domain" separated by commas, followed by a colon. $route = ""; $route .= "\@ $X $domain"; $route .= "(?: , $X \@ $X $domain )*"; // additional domains $route .= ":"; $route .= "$X"; // optional trailing comments - + // Item 5: local-part is a bunch of $word separated by periods $local_part = ""; $local_part .= "$word $X"; $local_part .= "(?:"; $local_part .= "$Period $X $word $X"; // additional words $local_part .= ")*"; - + // Item 2: addr-spec is local@domain $addr_spec = "$local_part \@ $X $domain"; @@ -185,10 +185,10 @@ function validateEmailFormat ( $email ) { $route_addr .= "(?: $route )?"; // optional route $route_addr .= "$addr_spec"; // address spec $route_addr .= ">"; - + // Item 3: phrase........ $phrase_ctrl = '\000-\010\012-\037'; // like ctrl, but without tab - + // Like atom-char, but without listing space, and uses phrase_ctrl. // Since the class is negated, this matches the same as atom-char plus space and tab $phrase_char = "[^()<>\@,;:\".$esc$OpenBR$CloseBR$NonASCII$phrase_ctrl]"; @@ -214,7 +214,7 @@ function validateEmailFormat ( $email ) { // test it and return results $isValid = preg_match("/^$mailbox$/xS",$email); - + return($isValid); } // END validateEmailFormat ?> diff --git a/play/index.php b/play/index.php index 3bc77b96..88e02b84 100644 --- a/play/index.php +++ b/play/index.php @@ -3,7 +3,7 @@ /* Copyright (c) Ampache.org - All rights reserved. + 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 @@ -24,63 +24,63 @@ This is the wrapper for opening music streams from this server. This script will play the local version or redirect to the remote server if that be the case. Also this will update local statistics for songs as well. - This is also where it decides if you need to be downsampled. + This is also where it decides if you need to be downsampled. */ define('NO_SESSION','1'); require_once '../lib/init.php'; require_once Config::get('prefix') . '/modules/horde/Browser.php'; -ob_end_clean(); +ob_end_clean(); /* These parameters had better come in on the url. */ $uid = scrub_in($_REQUEST['uid']); -$oid = $_REQUEST['song'] ? scrub_in($_REQUEST['song']) : scrub_in($_REQUEST['oid']); +$oid = $_REQUEST['song'] ? scrub_in($_REQUEST['song']) : scrub_in($_REQUEST['oid']); $sid = scrub_in($_REQUEST['ssid']); -$xml_rpc = scrub_in($_REQUEST['xml_rpc']); -$video = make_bool($_REQUEST['video']); +$xml_rpc = scrub_in($_REQUEST['xml_rpc']); +$video = make_bool($_REQUEST['video']); /* This is specifically for tmp playlist requests */ $demo_id = scrub_in($_REQUEST['demo_id']); -$random = scrub_in($_REQUEST['random']); +$random = scrub_in($_REQUEST['random']); // Parse byte range request $n = sscanf($_SERVER['HTTP_RANGE'], "bytes=%d-%d",$start,$end); /* First things first, if we don't have a uid/oid stop here */ -if (empty($oid) && empty($demo_id) && empty($random)) { +if (empty($oid) && empty($demo_id) && empty($random)) { debug_event('Play',"Error: No Object UID Specified, nothing to play",'2'); echo "Error: No Object UID Specified, nothing to play"; - exit; + exit; } // If we're XML-RPC and it's enabled, use system user -if (isset($xml_rpc) AND Config::get('xml_rpc') AND !isset($uid)) { - $uid = '-1'; -} +if (isset($xml_rpc) AND Config::get('xml_rpc') AND !isset($uid)) { + $uid = '-1'; +} -if (!isset($uid)) { - debug_event('Play','Error: No User specified','2'); - echo "Error: No User Specified"; +if (!isset($uid)) { + debug_event('Play','Error: No User specified','2'); + echo "Error: No User Specified"; exit; } /* Misc Housework */ $GLOBALS['user'] = new User($uid); -Preference::init(); +Preference::init(); /* If the user has been disabled (true value) */ if (make_bool($GLOBALS['user']->disabled)) { debug_event('user_disabled',"Error $user->username is currently disabled, stream access denied",'3'); - echo "Error: User Disabled"; - exit; + echo "Error: User Disabled"; + exit; } // If require session is set then we need to make sure we're legit -if (Config::get('require_session')) { - if (!Config::get('require_localnet_session') AND Access::check_network('network',$GLOBALS['user']->id,'5')) { +if (Config::get('require_session')) { + if (!Config::get('require_localnet_session') AND Access::check_network('network',$GLOBALS['user']->id,'5')) { // Localnet defined IP and require localnot session has been turned off we let this one through - debug_event('LocalNet','Streaming Access Granted to Localnet defined IP ' . $_SERVER['REMOTE_ADDR'],'5'); + debug_event('LocalNet','Streaming Access Granted to Localnet defined IP ' . $_SERVER['REMOTE_ADDR'],'5'); } - elseif(!Stream::session_exists($sid)) { + elseif(!Stream::session_exists($sid)) { debug_event('session_expired',"Streaming Access Denied: " . $GLOBALS['user']->username . "'s session has expired",'3'); die(_("Session Expired: please log in again at") . " " . Config::get('web_path') . "/login.php"); } @@ -98,103 +98,103 @@ $GLOBALS['user']->update_last_seen(); if (Config::get('demo_mode') || (!Access::check('interface','25') AND !isset($xml_rpc))) { debug_event('access_denied',"Streaming Access Denied:" .Config::get('demo_mode') . "is the value of demo_mode. Current user level is " . $GLOBALS['user']->access,'3'); access_denied(); - exit; + exit; } -/* - If they are using access lists let's make sure +/* + If they are using access lists let's make sure that they have enough access to play this mojo */ -if (Config::get('access_control')) { +if (Config::get('access_control')) { if (!Access::check_network('stream',$GLOBALS['user']->id,'25') AND - !Access::check_network('network',$GLOBALS['user']->id,'25')) { + !Access::check_network('network',$GLOBALS['user']->id,'25')) { debug_event('access_denied', "Streaming Access Denied: " . $_SERVER['REMOTE_ADDR'] . " does not have stream level access",'3'); access_denied(); - exit; + exit; } } // access_control is enabled -/** +/** * If we've got a tmp playlist then get the * current song, and do any other crazyness - * we need to + * we need to */ -if ($demo_id) { +if ($demo_id) { $democratic = new Democratic($demo_id); - $democratic->set_parent(); + $democratic->set_parent(); // If there is a cooldown we need to make sure this song isn't a repeat - if (!$democratic->cooldown) { + if (!$democratic->cooldown) { /* This takes into account votes etc and removes the */ $oid = $democratic->get_next_object(); - } - else { + } + else { // Pull history $oid = $democratic->get_next_object($song_cool_check); - $oids = $democratic->get_cool_songs(); - while (in_array($oid,$oids)) { - $song_cool_check++; + $oids = $democratic->get_cool_songs(); + while (in_array($oid,$oids)) { + $song_cool_check++; $oid = $democratic->get_next_object($song_cool_check); - if ($song_cool_check >= '5') { break; } + if ($song_cool_check >= '5') { break; } } // while we've got the 'new' song in old the array - - } // end if we've got a cooldown + + } // end if we've got a cooldown } // if democratic ID passed /** * if we are doing random let's pull the random object */ -if ($random) { - if ($start < 1) { - $oid = Random::get_single_song($_REQUEST['type']); +if ($random) { + if ($start < 1) { + $oid = Random::get_single_song($_REQUEST['type']); // Save this one incase we do a seek - $_SESSION['random']['last'] = $oid; - } - else { - $oid = $_SESSION['random']['last']; - } -} // if random + $_SESSION['random']['last'] = $oid; + } + else { + $oid = $_SESSION['random']['last']; + } +} // if random -if (!$video) { +if (!$video) { /* Base Checks passed create the song object */ $media = new Song($oid); $media->format(); } -else { - $media = new Video($oid); - $media->format(); -} +else { + $media = new Video($oid); + $media->format(); +} // Build up the catalog for our current object $catalog = new Catalog($media->catalog); /* If the song is disabled */ -if (!make_bool($media->enabled)) { +if (!make_bool($media->enabled)) { debug_event('Play',"Error: $media->file is currently disabled, song skipped",'5'); exit; } // If we are running in Legalize mode, don't play songs already playing if (Config::get('lock_songs')) { - if (!Stream::check_lock_media($media->id,get_class($media))) { - exit; + if (!Stream::check_lock_media($media->id,get_class($media))) { + exit; } } /* Check to see if this is a 'remote' catalog */ if ($catalog->catalog_type == 'remote') { - preg_match("/(.+)\/play\/index.+/",$media->file,$match); + preg_match("/(.+)\/play\/index.+/",$media->file,$match); - $token = xmlRpcClient::ampache_handshake($match['1'],$catalog->key); + $token = xmlRpcClient::ampache_handshake($match['1'],$catalog->key); // If we don't get anything back we failed and should bail now - if (!$token) { - debug_event('xmlrpc-stream','Error Unable to get Token from ' . $match['1'] . ' check target servers logs','1'); - exit; - } + if (!$token) { + debug_event('xmlrpc-stream','Error Unable to get Token from ' . $match['1'] . ' check target servers logs','1'); + exit; + } - $sid = xmlRpcClient::ampache_create_stream_session($match['1'],$token); + $sid = xmlRpcClient::ampache_create_stream_session($match['1'],$token); $extra_info = "&xml_rpc=1&sid=$sid"; header("Location: " . $media->file . $extra_info); @@ -213,17 +213,17 @@ if ($catalog->catalog_type == 'remote') { } // end if remote catalog /* If we don't have a file, or the file is not readable */ -if (!$media->file OR !is_readable($media->file)) { +if (!$media->file OR !is_readable($media->file)) { // We need to make sure this isn't democratic play, if it is then remove the song // from the vote list - if (is_object($tmp_playlist)) { - $tmp_playlist->delete_track($oid); + if (is_object($tmp_playlist)) { + $tmp_playlist->delete_track($oid); } debug_event('Play',"Error song $media->file ($media->title) does not have a valid filename specified",'2'); - echo "Error: Invalid Song Specified, file not found or file unreadable"; - exit; + echo "Error: Invalid Song Specified, file not found or file unreadable"; + exit; } // make fread binary safe @@ -238,48 +238,48 @@ ignore_user_abort(TRUE); // Format the song name $media_name = $media->f_artist_full . " - " . $media->title . "." . $media->type; -/* If they are just trying to download make sure they have rights +/* If they are just trying to download make sure they have rights * and then present them with the download file */ -if ($_GET['action'] == 'download' AND Config::get('download')) { - +if ($_GET['action'] == 'download' AND Config::get('download')) { + // STUPID IE - $media->format_pattern(); + $media->format_pattern(); $media_name = str_replace(array('?','/','\\'),"_",$media->f_file); // Use Horde's Browser class to send the headers - header("Content-Length: " . $media->size); - $browser = new Browser(); - $browser->downloadHeaders($media_name,$media->mime,false,$media->size); - $fp = fopen($media->file,'rb'); - $bytesStreamed = 0; + header("Content-Length: " . $media->size); + $browser = new Browser(); + $browser->downloadHeaders($media_name,$media->mime,false,$media->size); + $fp = fopen($media->file,'rb'); + $bytesStreamed = 0; - if (!is_resource($fp)) { + if (!is_resource($fp)) { debug_event('Play',"Error: Unable to open $media->file for downloading",'2'); - exit(); + exit(); } - + // Check to see if we should be throttling because we can get away with it - if (Config::get('rate_limit') > 0) { - while (!feof($fp)) { - echo fread($fp,round(Config::get('rate_limit')*1024)); - $bytesStreamed += round(Config::get('rate_limit')*1024); - flush(); - sleep(1); - } - } - else { - fpassthru($fp); - } + if (Config::get('rate_limit') > 0) { + while (!feof($fp)) { + echo fread($fp,round(Config::get('rate_limit')*1024)); + $bytesStreamed += round(Config::get('rate_limit')*1024); + flush(); + sleep(1); + } + } + else { + fpassthru($fp); + } // Make sure that a good chunk of the song has been played if ($bytesStreamed >= $media->size) { debug_event('Play','Downloaded, Registering stats for ' . $media->title,'5'); $GLOBALS['user']->update_stats($media->id); } // if enough bytes are streamed - - fclose($fp); - exit(); + + fclose($fp); + exit(); } // if they are trying to download and they can @@ -288,41 +288,41 @@ $browser = new Browser(); header("Accept-Ranges: bytes" ); // Prevent the script from timing out -set_time_limit(0); +set_time_limit(0); /* We're about to start record this persons IP */ -if (Config::get('track_user_ip')) { +if (Config::get('track_user_ip')) { $GLOBALS['user']->insert_ip_history(); } // If we've got downsample remote enabled -if (Config::get('downsample_remote')) { - if (!Access::check_network('network',$GLOBALS['user']->id,'0')) { - debug_event('Downsample','Network Downsample ' . $_SERVER['REMOTE_ADDR'] . ' is not in Local definition','5'); +if (Config::get('downsample_remote')) { + if (!Access::check_network('network',$GLOBALS['user']->id,'0')) { + debug_event('Downsample','Network Downsample ' . $_SERVER['REMOTE_ADDR'] . ' is not in Local definition','5'); $not_local = true; } } // if downsample remote is enabled // If they are downsampling, or if the song is not a native stream or it's non-local -if ((Config::get('transcode') == 'always' || !$media->native_stream() || $not_local) && Config::get('transcode') != 'never') { +if ((Config::get('transcode') == 'always' || !$media->native_stream() || $not_local) && Config::get('transcode') != 'never') { debug_event('Downsample','Starting Downsample {Transcode:' . Config::get('transcode') . '} {Native Stream:' . $media->native_stream() .'} {Not Local:' . $not_local . '}','5'); $fp = Stream::start_downsample($media,$lastid,$media_name,$start); $media_name = $media->f_artist_full . " - " . $media->title . "." . $media->type; // Note that this is downsampling - $downsampled_song = true; + $downsampled_song = true; } // end if downsampling -else { +else { // Send file, possible at a byte offset $fp = fopen($media->file, 'rb'); - - if (!is_resource($fp)) { + + if (!is_resource($fp)) { debug_event('Play',"Error: Unable to open $media->file for reading",'2'); cleanup_and_exit($lastid); } } // else not downsampling -// Put this song in the now_playing table only if it's a song for now... -if (get_class($media) == 'Song') { +// Put this song in the now_playing table only if it's a song for now... +if (get_class($media) == 'Song') { Stream::insert_now_playing($media->id,$uid,$media->time,$sid,get_class($media)); } @@ -332,16 +332,16 @@ if ($start > 0) { if(isset($end)) { $end = min($end,$media->size-1); $stream_size = ($end-$start)+1; - } + } else { $stream_size = $media->size - $start; } - + debug_event('Play','Content-Range header recieved, skipping ahead ' . $start . ' bytes out of ' . $media->size,'5'); $browser->downloadHeaders($media_name, $media->mime, false, $media->size); - if (!$downsampled_song) { + if (!$downsampled_song) { fseek( $fp, $start ); - } + } $range = $start ."-". $end . "/" . $media->size; header("HTTP/1.1 206 Partial Content"); header("Content-Range: bytes $range"); @@ -350,22 +350,22 @@ if ($start > 0) { /* Last but not least pump em out */ else { - debug_event('Play','Starting stream of ' . $media->file . ' with size ' . $media->size,'5'); + debug_event('Play','Starting stream of ' . $media->file . ' with size ' . $media->size,'5'); header("Content-Length: $media->size"); $browser->downloadHeaders($media_name, $media->mime, false, $media->size); - $stream_size = $media->size; + $stream_size = $media->size; } - -/* Let's force them to actually play a portion of the song before + +/* Let's force them to actually play a portion of the song before * we count it in the statistics */ $bytes_streamed = 0; $min_bytes_streamed = $media->size / 2; -// Actually do the streaming +// Actually do the streaming do { - $read_size = min(2048,$stream_size-$bytes_streamed); - if ($read_size < 1) { break; } + $read_size = min(2048,$stream_size-$bytes_streamed); + if ($read_size < 1) { break; } $buf = fread($fp, $read_size); print($buf); $bytes_streamed += strlen($buf); @@ -378,16 +378,16 @@ if($bytes_streamed < $stream_size AND (connection_status() == 0)) { // Make sure that a good chunk of the song has been played if ($bytes_streamed > $min_bytes_streamed AND get_class($media) == 'Song') { - debug_event('Play','Registering stats for ' . $media->title,'5'); - + debug_event('Play','Registering stats for ' . $media->title,'5'); + $GLOBALS['user']->update_stats($media->id); /* Set the Song as Played if it isn't already */ $media->set_played(); } // if enough bytes are streamed -else { - debug_event('Play',$bytes_streamed .' of ' . $media->size . ' streamed, less than ' . $min_bytes_streamed . ' not collecting stats','5'); -} +else { + debug_event('Play',$bytes_streamed .' of ' . $media->size . ' streamed, less than ' . $min_bytes_streamed . ' not collecting stats','5'); +} /* If this is a voting tmp playlist remove the entry, we do this regardless of play amount */ @@ -400,14 +400,14 @@ if ($demo_id) { } // if tmp_playlist /* Clean up any open ends */ -if (Config::get('play_type') == 'downsample' || !$media->native_stream()) { +if (Config::get('play_type') == 'downsample' || !$media->native_stream()) { @pclose($fp); -} -else { +} +else { @fclose($fp); } // Note that the stream has ended -debug_event('Play','Stream Ended at ' . $bytes_streamed . ' bytes out of ' . $media->size,'5'); +debug_event('Play','Stream Ended at ' . $bytes_streamed . ' bytes out of ' . $media->size,'5'); ?> diff --git a/playlist.php b/playlist.php index bb1ac99e..226c0e35 100644 --- a/playlist.php +++ b/playlist.php @@ -27,39 +27,39 @@ require_once 'lib/init.php'; -show_header(); +show_header(); /* Switch on the action passed in */ -switch ($_REQUEST['action']) { +switch ($_REQUEST['action']) { case 'add_dyn_song': /* Check Rights */ - if (!$playlist->has_access()) { + if (!$playlist->has_access()) { access_denied(); break; } - + $playlist->add_dyn_song(); $_SESSION['data']['playlist_id'] = $playlist->id; show_playlist($playlist); break; case 'create_playlist': /* Check rights */ - if (!Access::check('interface','25')) { + if (!Access::check('interface','25')) { access_denied(); break; - } - + } + $playlist_name = scrub_in($_REQUEST['playlist_name']); $playlist_type = scrub_in($_REQUEST['type']); - $playlist->create($playlist_name,$playlist_type); + $playlist->create($playlist_name,$playlist_type); $_SESSION['data']['playlist_id'] = $playlist->id; show_confirmation(_('Playlist Created'),$playlist_name . ' (' . $playlist_type . ') ' . _(' has been created'),'playlist.php'); break; case 'remove_song': /* Check em for rights */ - if (!$playlist->has_access()) { + if (!$playlist->has_access()) { access_denied(); break; } @@ -67,10 +67,10 @@ switch ($_REQUEST['action']) { show_playlist($playlist); break; case 'show_playlist': - $playlist = new Playlist($_REQUEST['playlist_id']); - $playlist->format(); - $object_ids = $playlist->get_items(); - require_once Config::get('prefix') . '/templates/show_playlist.inc.php'; + $playlist = new Playlist($_REQUEST['playlist_id']); + $playlist->format(); + $object_ids = $playlist->get_items(); + require_once Config::get('prefix') . '/templates/show_playlist.inc.php'; break; case 'show_import_playlist': require_once Config::get('prefix') . '/templates/show_import_playlist.inc.php'; @@ -100,7 +100,7 @@ switch ($_REQUEST['action']) { break; case 'set_track_numbers': /* Make sure they have permission */ - if (!$playlist->has_access()) { + if (!$playlist->has_access()) { access_denied(); break; } @@ -116,33 +116,33 @@ switch ($_REQUEST['action']) { break; case 'prune_empty': /* Make sure they have permission */ - if (!$GLOBALS['user']->has_access(100)) { - access_denied(); + if (!$GLOBALS['user']->has_access(100)) { + access_denied(); break; } - prune_empty_playlists(); + prune_empty_playlists(); $url = Config::get('web_path') . '/playlist.php'; - $title = _('Empty Playlists Deleted'); + $title = _('Empty Playlists Deleted'); $body = ''; show_confirmation($title,$body,$url); break; case 'normalize_tracks': - $playlist = new Playlist($_REQUEST['playlist_id']); + $playlist = new Playlist($_REQUEST['playlist_id']); /* Make sure they have permission */ - if (!$playlist->has_access()) { + if (!$playlist->has_access()) { access_denied(); break; } - + /* Normalize the tracks */ $playlist->normalize_tracks(); - $object_ids = $playlist->get_items(); + $object_ids = $playlist->get_items(); default: - require_once Config::get('prefix') . '/templates/show_playlist.inc.php'; + require_once Config::get('prefix') . '/templates/show_playlist.inc.php'; break; } // switch on the action -show_footer(); +show_footer(); ?> diff --git a/preferences.php b/preferences.php index f8e7c4d9..330bd66b 100644 --- a/preferences.php +++ b/preferences.php @@ -22,75 +22,75 @@ require 'lib/init.php'; -// Switch on the action -switch($_REQUEST['action']) { +// Switch on the action +switch($_REQUEST['action']) { case 'update_preferences': - if ($_POST['method'] == 'admin' && !Access::check('interface','100')) { - access_denied(); - exit; - } - - if (!Core::form_verify('update_preference','post')) { - access_denied(); - exit; - } - - /* Reset the Theme */ - if ($_POST['method'] == 'admin') { - $user_id = '-1'; - $fullname = _('Server'); - $_REQUEST['action'] = 'admin'; + if ($_POST['method'] == 'admin' && !Access::check('interface','100')) { + access_denied(); + exit; + } + + if (!Core::form_verify('update_preference','post')) { + access_denied(); + exit; + } + + /* Reset the Theme */ + if ($_POST['method'] == 'admin') { + $user_id = '-1'; + $fullname = _('Server'); + $_REQUEST['action'] = 'admin'; + } + else { + $user_id = $GLOBALS['user']->id; + $fullname = $GLOBALS['user']->fullname; } - else { - $user_id = $GLOBALS['user']->id; - $fullname = $GLOBALS['user']->fullname; - } /* Update and reset preferences */ - update_preferences($user_id); + update_preferences($user_id); Preference::init(); - $preferences = $GLOBALS['user']->get_preferences($user_id,$_REQUEST['tab']); + $preferences = $GLOBALS['user']->get_preferences($user_id,$_REQUEST['tab']); break; - case 'admin_update_preferences': + case 'admin_update_preferences': // Make sure only admins here - if (!Access::check('interface','100')) { - access_denied(); - exit; - } + if (!Access::check('interface','100')) { + access_denied(); + exit; + } if (!Core::form_verify('update_preference','post')) { access_denied(); exit; } - update_preferences($_POST['user_id']); - header("Location: " . Config::get('web_path') . "/admin/users.php?action=show_preferences&user_id=" . scrub_out($_POST['user_id'])); + update_preferences($_POST['user_id']); + header("Location: " . Config::get('web_path') . "/admin/users.php?action=show_preferences&user_id=" . scrub_out($_POST['user_id'])); break; - case 'admin': + case 'admin': // Make sure only admins here - if (!Access::check('interface','100')) { - access_denied(); + if (!Access::check('interface','100')) { + access_denied(); exit; - } + } $fullname= _('Server'); - $preferences = $GLOBALS['user']->get_preferences(-1,$_REQUEST['tab']); + $preferences = $GLOBALS['user']->get_preferences(-1,$_REQUEST['tab']); break; case 'user': - if (!Access::check('interface','100')) { - access_denied(); - exit; - } - $client = new User($_REQUEST['user_id']); - $fullname = $client->fullname; - $preferences = $client->get_preferences(0,$_REQUEST['tab']); - break; - case 'update_user': + if (!Access::check('interface','100')) { + access_denied(); + exit; + } + $client = new User($_REQUEST['user_id']); + $fullname = $client->fullname; + $preferences = $client->get_preferences(0,$_REQUEST['tab']); + break; + case 'update_user': // Make sure we're a user and they came from the form - if (!Access::check('interface','25') OR !Config::get('use_auth')) { - access_denied(); - exit; - } + if (!Access::check('interface','25') OR !Config::get('use_auth')) { + access_denied(); + exit; + } if (!Core::form_verify('update_user','post')) { access_denied(); @@ -98,38 +98,38 @@ switch($_REQUEST['action']) { } // Remove the value - unset($_SESSION['forms']['account']); + unset($_SESSION['forms']['account']); // Don't let them change access, or username here - unset($_POST['access']); - $_POST['username'] = $GLOBALS['user']->username; + unset($_POST['access']); + $_POST['username'] = $GLOBALS['user']->username; - if (!$GLOBALS['user']->update($_POST)) { - Error::add('general',_('Error Update Failed')); - } - else { - $_REQUEST['action'] = 'confirm'; - $title = _('Updated'); - $text = _('Your Account has been updated'); - $next_url = Config::get('web_path') . '/preferences.php?tab=account'; - } + if (!$GLOBALS['user']->update($_POST)) { + Error::add('general',_('Error Update Failed')); + } + else { + $_REQUEST['action'] = 'confirm'; + $title = _('Updated'); + $text = _('Your Account has been updated'); + $next_url = Config::get('web_path') . '/preferences.php?tab=account'; + } break; - default: - $fullname = $GLOBALS['user']->fullname; - $preferences = $GLOBALS['user']->get_preferences(0,$_REQUEST['tab']); + default: + $fullname = $GLOBALS['user']->fullname; + $preferences = $GLOBALS['user']->get_preferences(0,$_REQUEST['tab']); break; } // End Switch Action -show_header(); +show_header(); /** * switch on the view */ -switch ($_REQUEST['action']) { - case 'confirm': - show_confirmation($title,$text,$next_url,$cancel); +switch ($_REQUEST['action']) { + case 'confirm': + show_confirmation($title,$text,$next_url,$cancel); break; - default: + default: // Show the default preferences page require Config::get('prefix') . '/templates/show_preferences.inc.php'; break; diff --git a/radio.php b/radio.php index d51ea21a..41192078 100644 --- a/radio.php +++ b/radio.php @@ -22,44 +22,44 @@ require 'lib/init.php'; -show_header(); +show_header(); // Switch on Action -switch ($_REQUEST['action']) { - case 'show_create': - if (!Access::check('interface','25')) { - access_denied(); - exit; - } +switch ($_REQUEST['action']) { + case 'show_create': + if (!Access::check('interface','25')) { + access_denied(); + exit; + } - require_once Config::get('prefix') . '/templates/show_add_live_stream.inc.php'; + require_once Config::get('prefix') . '/templates/show_add_live_stream.inc.php'; break; - case 'create': - if (!Access::check('interface','25') || Config::get('demo_mode')) { - access_denied(); - exit; - } + case 'create': + if (!Access::check('interface','25') || Config::get('demo_mode')) { + access_denied(); + exit; + } - if (!Core::form_verify('add_radio','post')) { - access_denied(); - exit; - } + if (!Core::form_verify('add_radio','post')) { + access_denied(); + exit; + } // Try to create the sucker - $results = Radio::create($_POST); + $results = Radio::create($_POST); - if (!$results) { - require_once Config::get('prefix') . '/templates/show_add_live_stream.inc.php'; - } - else { - $body = _('Radio Station Added'); - $title = ''; - show_confirmation($title,$body,Config::get('web_path') . '/index.php'); - } + if (!$results) { + require_once Config::get('prefix') . '/templates/show_add_live_stream.inc.php'; + } + else { + $body = _('Radio Station Added'); + $title = ''; + show_confirmation($title,$body,Config::get('web_path') . '/index.php'); + } break; -} // end data collection +} // end data collection -show_footer(); +show_footer(); ?> diff --git a/random.php b/random.php index 83922d17..5c2a89d8 100644 --- a/random.php +++ b/random.php @@ -23,24 +23,24 @@ require_once 'lib/init.php'; -show_header(); +show_header(); -switch ($_REQUEST['action']) { - case 'get_advanced': - $object_ids = Random::advanced($_POST); +switch ($_REQUEST['action']) { + case 'get_advanced': + $object_ids = Random::advanced($_POST); // We need to add them to the active playlist - foreach ($object_ids as $object_id) { - $GLOBALS['user']->playlist->add_object($object_id,'song'); - } + foreach ($object_ids as $object_id) { + $GLOBALS['user']->playlist->add_object($object_id,'song'); + } case 'advanced': - default: - require_once Config::get('prefix') . '/templates/show_random.inc.php'; + default: + require_once Config::get('prefix') . '/templates/show_random.inc.php'; /* require_once Config::get('prefix') . '/templates/show_random_rules.inc.php';*/ break; -} // end switch +} // end switch -show_footer(); +show_footer(); ?> diff --git a/register.php b/register.php index d2a1463d..80bfed64 100644 --- a/register.php +++ b/register.php @@ -27,18 +27,18 @@ require_once 'lib/init.php'; if (!Config::get('allow_public_registration') || Config::get('demo_mode')) { debug_event('DENIED','Error Attempted registration','1'); access_denied(); - exit(); + exit(); } /** - * These are only needed for this page so they aren't included in init.php + * These are only needed for this page so they aren't included in init.php * this is for email validation and the cool little graphic */ require_once Config::get('prefix') . '/modules/validatemail/validateEmailFormat.php'; require_once Config::get('prefix') . '/modules/validatemail/validateEmail.php'; /* Don't even include it if we aren't going to use it */ -if (Config::get('captcha_public_reg')) { +if (Config::get('captcha_public_reg')) { define ("CAPTCHA_INVERSE", 1); include Config::get('prefix') . '/modules/captcha/captcha.php'; } @@ -46,13 +46,13 @@ if (Config::get('captcha_public_reg')) { /* Start switch based on action passed */ switch ($_REQUEST['action']) { - case 'validate': - $username = scrub_in($_GET['username']); - $validation = scrub_in($_GET['auth']); - require_once Config::get('prefix') . '/templates/show_user_activate.inc.php'; - break; + case 'validate': + $username = scrub_in($_GET['username']); + $validation = scrub_in($_GET['auth']); + require_once Config::get('prefix') . '/templates/show_user_activate.inc.php'; + break; case 'add_user': - /** + /** * User information has been entered * we need to check the database for possible existing username first * if username exists, error and say "Please choose a different name." @@ -68,11 +68,11 @@ switch ($_REQUEST['action']) { $pass2 = scrub_in($_POST['password_2']); /* If we're using the captcha stuff */ - if (Config::get('captcha_public_reg')) { - $captcha = captcha::solved(); + if (Config::get('captcha_public_reg')) { + $captcha = captcha::solved(); if(!isset ($captcha)) { Error::add('captcha',_('Error Captcha Required')); - } + } if (isset ($captcha)) { if ($captcha) { $msg="SUCCESS"; @@ -86,7 +86,7 @@ switch ($_REQUEST['action']) { if (Config::get('user_agreement')) { if (!$_POST['accept_agreement']) { Error::add('user_agreement',_("You must accept the user agreement")); - } + } } // if they have to agree to something if (!$_POST['username']) { @@ -115,11 +115,11 @@ switch ($_REQUEST['action']) { $mmsg = "MAILOK"; } else { - Error::add('email',_("Error Email address not confirmed") + Error::add('email',_("Error Email address not confirmed") . "
$validate_results[1]"); } /* End of mailcheck */ - + if (!$pass1) { Error::add('password',_("You must enter a password")); } @@ -128,7 +128,7 @@ switch ($_REQUEST['action']) { Error::add('password',_("Your passwords do not match")); } - if (!User::check_username($username)) { + if (!User::check_username($username)) { Error::add('duplicate_user',_("Error Username already exists")); } @@ -140,20 +140,20 @@ switch ($_REQUEST['action']) { /* Attempt to create the new user */ $access = '5'; - switch (Config::get('auto_user')) { - case 'admin': - $access = '100'; + switch (Config::get('auto_user')) { + case 'admin': + $access = '100'; break; - case 'user': - $access = '25'; + case 'user': + $access = '25'; break; - default: - case 'guest': - $access = '5'; + default: + case 'guest': + $access = '5'; break; } // auto-user level - + $new_user = User::create($username,$fullname,$email,$pass1,$access); if (!$new_user) { @@ -167,11 +167,11 @@ switch ($_REQUEST['action']) { $client->update_validation($validation); Registration::send_confirmation($username, $fullname, $email, $pass1, $validation); - require_once Config::get('prefix') . '/templates/show_registration_confirmation.inc.php'; + require_once Config::get('prefix') . '/templates/show_registration_confirmation.inc.php'; break; case 'show_add_user': default: - require_once Config::get('prefix') . '/templates/show_user_registration.inc.php'; + require_once Config::get('prefix') . '/templates/show_user_registration.inc.php'; break; } // end switch on action ?> diff --git a/rss.php b/rss.php index e5320905..c480c0ec 100644 --- a/rss.php +++ b/rss.php @@ -30,9 +30,9 @@ if (!Config::get('use_rss') || Config::get('demo_mode')) { } // Add in our base hearder defining the content type -header("Content-Type: application/xml; charset=" . Config::get('site_charset')); +header("Content-Type: application/xml; charset=" . Config::get('site_charset')); -$rss = new AmpacheRSS($_REQUEST['type']); -echo $rss->get_xml(); +$rss = new AmpacheRSS($_REQUEST['type']); +echo $rss->get_xml(); ?> diff --git a/search.php b/search.php index cae80205..4aedf327 100644 --- a/search.php +++ b/search.php @@ -22,31 +22,31 @@ require_once 'lib/init.php'; -show_header(); +show_header(); /** - * action switch + * action switch */ -switch ($_REQUEST['action']) { +switch ($_REQUEST['action']) { case 'quick_search': /* This needs to be done because we don't know what thing * they used the quick search to search on until after they've - * submited it + * submited it */ $_REQUEST['s_all'] = $_REQUEST['search_string']; - - if (strlen($_REQUEST['search_string']) < 1) { + + if (strlen($_REQUEST['search_string']) < 1) { Error::add('keyword',_('Error: No Keyword Entered')); - require_once Config::get('prefix') . '/templates/show_search.inc.php'; + require_once Config::get('prefix') . '/templates/show_search.inc.php'; break; } case 'search': - require_once Config::get('prefix') . '/templates/show_search.inc.php'; - require_once Config::get('prefix') . '/templates/show_search_options.inc.php'; + require_once Config::get('prefix') . '/templates/show_search.inc.php'; + require_once Config::get('prefix') . '/templates/show_search_options.inc.php'; $results = run_search($_REQUEST); - Browse::set_type('song'); - Browse::reset(); - Browse::show_objects($results); + Browse::set_type('song'); + Browse::reset(); + Browse::show_objects($results); break; case 'save_as_track': $playlist_id = save_search($_REQUEST); @@ -54,14 +54,14 @@ switch ($_REQUEST['action']) { show_confirmation("Search Saved","Your Search has been saved as a track in $playlist->name",conf('web_path') . "/search.php"); break; default: - require_once Config::get('prefix') . '/templates/show_search.inc.php'; + require_once Config::get('prefix') . '/templates/show_search.inc.php'; break; - case 'descriptor': + case 'descriptor': // This is a little special we don't want header/footers so trash what we've got in the OB - ob_clean(); - require_once Config::get('prefix') . '/templates/show_search_descriptor.inc.php'; - exit; - break; + ob_clean(); + require_once Config::get('prefix') . '/templates/show_search_descriptor.inc.php'; + exit; + break; } /* Show the Footer */ diff --git a/server/ajax.server.php b/server/ajax.server.php index ca10e0cc..96a510cf 100644 --- a/server/ajax.server.php +++ b/server/ajax.server.php @@ -20,208 +20,208 @@ */ -/* Because this is accessed via Ajax we are going to allow the session_id +/* Because this is accessed via Ajax we are going to allow the session_id * as part of the get request */ // Set that this is an ajax include -define('AJAX_INCLUDE','1'); +define('AJAX_INCLUDE','1'); require_once '../lib/init.php'; /* Set the correct headers */ header("Content-type: text/xml; charset=" . Config::get('site_charset')); header("Content-Disposition: attachment; filename=ajax.xml"); -header("Expires: Tuesday, 27 Mar 1984 05:00:00 GMT"); +header("Expires: Tuesday, 27 Mar 1984 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); -header("Pragma: no-cache"); +header("Pragma: no-cache"); -switch ($_REQUEST['page']) { - case 'flag': - require_once Config::get('prefix') . '/server/flag.ajax.php'; - exit; +switch ($_REQUEST['page']) { + case 'flag': + require_once Config::get('prefix') . '/server/flag.ajax.php'; + exit; break; - case 'stats': - require_once Config::get('prefix') . '/server/stats.ajax.php'; - exit; + case 'stats': + require_once Config::get('prefix') . '/server/stats.ajax.php'; + exit; break; - case 'browse': - require_once Config::get('prefix') . '/server/browse.ajax.php'; - exit; + case 'browse': + require_once Config::get('prefix') . '/server/browse.ajax.php'; + exit; break; - case 'random': - require_once Config::get('prefix') . '/server/random.ajax.php'; - exit; + case 'random': + require_once Config::get('prefix') . '/server/random.ajax.php'; + exit; break; - case 'playlist': - require_once Config::get('prefix') . '/server/playlist.ajax.php'; - exit; + case 'playlist': + require_once Config::get('prefix') . '/server/playlist.ajax.php'; + exit; break; - case 'localplay': - require_once Config::get('prefix') . '/server/localplay.ajax.php'; - exit; + case 'localplay': + require_once Config::get('prefix') . '/server/localplay.ajax.php'; + exit; break; case 'tag': require_once Config::get('prefix') . '/server/tag.ajax.php'; - exit; + exit; break; - case 'stream': + case 'stream': require_once Config::get('prefix') . '/server/stream.ajax.php'; - exit; + exit; break; - case 'song': - require_once Config::get('prefix') . '/server/song.ajax.php'; - exit; - break; - case 'democratic': - require_once Config::get('prefix') . '/server/democratic.ajax.php'; - exit; + case 'song': + require_once Config::get('prefix') . '/server/song.ajax.php'; + exit; break; - case 'index': - require_once Config::get('prefix') . '/server/index.ajax.php'; - exit; - break; - default: + case 'democratic': + require_once Config::get('prefix') . '/server/democratic.ajax.php'; + exit; + break; + case 'index': + require_once Config::get('prefix') . '/server/index.ajax.php'; + exit; + break; + default: // A taste of compatibility break; -} // end switch on page +} // end switch on page -switch ($_REQUEST['action']) { - case 'refresh_rightbar': - $results['rightbar'] = ajax_include('rightbar.inc.php'); +switch ($_REQUEST['action']) { + case 'refresh_rightbar': + $results['rightbar'] = ajax_include('rightbar.inc.php'); break; /* Controls the editing of objects */ - case 'show_edit_object': - + case 'show_edit_object': + // Set the default required level - $level = '50'; + $level = '50'; - switch ($_GET['type']) { - case 'album': - $key = 'album_' . $_GET['id']; - $album = new Album($_GET['id']); - $album->format(); + switch ($_GET['type']) { + case 'album': + $key = 'album_' . $_GET['id']; + $album = new Album($_GET['id']); + $album->format(); break; - case 'artist': - $key = 'artist_' . $_GET['id']; - $artist = new Artist($_GET['id']); - $artist->format(); + case 'artist': + $key = 'artist_' . $_GET['id']; + $artist = new Artist($_GET['id']); + $artist->format(); break; - case 'song': - $key = 'song_' . $_GET['id']; - $song = new Song($_GET['id']); - $song->format(); + case 'song': + $key = 'song_' . $_GET['id']; + $song = new Song($_GET['id']); + $song->format(); break; - case 'live_stream': - $key = 'live_stream_' . $_GET['id']; - $radio = new Radio($_GET['id']); - $radio->format(); + case 'live_stream': + $key = 'live_stream_' . $_GET['id']; + $radio = new Radio($_GET['id']); + $radio->format(); break; - case 'playlist': - $key = 'playlist_row_' . $_GET['id']; - $playlist = new Playlist($_GET['id']); - $playlist->format(); + case 'playlist': + $key = 'playlist_row_' . $_GET['id']; + $playlist = new Playlist($_GET['id']); + $playlist->format(); // If the current user is the owner, only user is required - if ($playlist->user == $GLOBALS['user']->id) { - $level = '25'; - } + if ($playlist->user == $GLOBALS['user']->id) { + $level = '25'; + } break; - default: - $key = 'rfc3514'; - echo xml_from_array(array($key=>'0x1')); - exit; - break; - } // end switch on type - - // Make sure they got them rights - if (!Access::check('interface',$level)) { - $results['rfc3514'] = '0x1'; - break; - } - - ob_start(); - require Config::get('prefix') . '/templates/show_edit_' . $_GET['type'] . '_row.inc.php'; - $results[$key] = ob_get_contents(); - ob_end_clean(); - break; - case 'edit_object': - - $level = '50'; - - if ($_POST['type'] == 'playlist') { - $playlist = new Playlist($_POST['id']); - if ($GLOBALS['user']->id == $playlist->user) { - $level = '25'; - } - } - - // Make sure we've got them rights - if (!Access::check('interface',$level) || Config::get('demo_mode')) { - $results['rfc3514'] = '0x1'; - break; - } - - switch ($_POST['type']) { - case 'album': - $key = 'album_' . $_POST['id']; - $album = new Album($_POST['id']); - $songs = $album->get_songs(); - $new_id = $album->update($_POST); - if ($new_id != $_POST['id']) { - $album = new Album($new_id); - foreach ($songs as $song_id) { - Flag::add($song_id,'song','retag','Inline Album Update'); - } - } - $album->format(); - break; - case 'artist': - $key = 'artist_' . $_POST['id']; - $artist = new Artist($_POST['id']); - $songs = $artist->get_songs(); - $new_id = $artist->update($_POST); - if ($new_id != $_POST['id']) { - $artist = new Artist($new_id); - foreach ($songs as $song_id) { - Flag::add($song_id,'song','retag','Inline Artist Update'); - } - } - $artist->format(); - break; - case 'song': - $key = 'song_' . $_POST['id']; - $song = new Song($_POST['id']); - Flag::add($song->id,'song','retag','Inline Single Song Update'); - $song->update($_POST); - $song->format(); - break; - case 'playlist': - $key = 'playlist_row_' . $_POST['id']; - $playlist->update($_POST); - $playlist->format(); - $count = $playlist->get_song_count(); - break; - case 'live_stream': - $key = 'live_stream_' . $_POST['id']; - Radio::update($_POST); - $radio = new Radio($_POST['id']); - $radio->format(); - break; - default: + default: $key = 'rfc3514'; - echo xml_from_array(array($key=>'0x1')); - exit; + echo xml_from_array(array($key=>'0x1')); + exit; break; } // end switch on type - ob_start(); - require Config::get('prefix') . '/templates/show_' . $_POST['type'] . '_row.inc.php'; - $results[$key] = ob_get_contents(); - ob_end_clean(); + // Make sure they got them rights + if (!Access::check('interface',$level)) { + $results['rfc3514'] = '0x1'; + break; + } + + ob_start(); + require Config::get('prefix') . '/templates/show_edit_' . $_GET['type'] . '_row.inc.php'; + $results[$key] = ob_get_contents(); + ob_end_clean(); + break; + case 'edit_object': + + $level = '50'; + + if ($_POST['type'] == 'playlist') { + $playlist = new Playlist($_POST['id']); + if ($GLOBALS['user']->id == $playlist->user) { + $level = '25'; + } + } + + // Make sure we've got them rights + if (!Access::check('interface',$level) || Config::get('demo_mode')) { + $results['rfc3514'] = '0x1'; + break; + } + + switch ($_POST['type']) { + case 'album': + $key = 'album_' . $_POST['id']; + $album = new Album($_POST['id']); + $songs = $album->get_songs(); + $new_id = $album->update($_POST); + if ($new_id != $_POST['id']) { + $album = new Album($new_id); + foreach ($songs as $song_id) { + Flag::add($song_id,'song','retag','Inline Album Update'); + } + } + $album->format(); + break; + case 'artist': + $key = 'artist_' . $_POST['id']; + $artist = new Artist($_POST['id']); + $songs = $artist->get_songs(); + $new_id = $artist->update($_POST); + if ($new_id != $_POST['id']) { + $artist = new Artist($new_id); + foreach ($songs as $song_id) { + Flag::add($song_id,'song','retag','Inline Artist Update'); + } + } + $artist->format(); + break; + case 'song': + $key = 'song_' . $_POST['id']; + $song = new Song($_POST['id']); + Flag::add($song->id,'song','retag','Inline Single Song Update'); + $song->update($_POST); + $song->format(); + break; + case 'playlist': + $key = 'playlist_row_' . $_POST['id']; + $playlist->update($_POST); + $playlist->format(); + $count = $playlist->get_song_count(); + break; + case 'live_stream': + $key = 'live_stream_' . $_POST['id']; + Radio::update($_POST); + $radio = new Radio($_POST['id']); + $radio->format(); + break; + default: + $key = 'rfc3514'; + echo xml_from_array(array($key=>'0x1')); + exit; + break; + } // end switch on type + + ob_start(); + require Config::get('prefix') . '/templates/show_' . $_POST['type'] . '_row.inc.php'; + $results[$key] = ob_get_contents(); + ob_end_clean(); break; case 'current_playlist': - switch ($_REQUEST['type']) { + switch ($_REQUEST['type']) { case 'delete': $GLOBALS['user']->playlist->delete_track($_REQUEST['id']); break; @@ -229,84 +229,84 @@ switch ($_REQUEST['action']) { $results['rightbar'] = ajax_include('rightbar.inc.php'); break; - // Handle the users basketcases... - case 'basket': - switch ($_REQUEST['type']) { - case 'album': - case 'artist': - case 'tag': - $object = new $_REQUEST['type']($_REQUEST['id']); - $songs = $object->get_songs(); - foreach ($songs as $song_id) { - $GLOBALS['user']->playlist->add_object($song_id,'song'); + // Handle the users basketcases... + case 'basket': + switch ($_REQUEST['type']) { + case 'album': + case 'artist': + case 'tag': + $object = new $_REQUEST['type']($_REQUEST['id']); + $songs = $object->get_songs(); + foreach ($songs as $song_id) { + $GLOBALS['user']->playlist->add_object($song_id,'song'); } // end foreach break; case 'browse_set': - Browse::set_type($_REQUEST['object_type']); - $objects = Browse::get_saved(); - foreach ($objects as $object_id) { - $GLOBALS['user']->playlist->add_object($object_id,'song'); - } - break; - case 'album_random': - case 'artist_random': + Browse::set_type($_REQUEST['object_type']); + $objects = Browse::get_saved(); + foreach ($objects as $object_id) { + $GLOBALS['user']->playlist->add_object($object_id,'song'); + } + break; + case 'album_random': + case 'artist_random': case 'tag_random': - $data = explode('_',$_REQUEST['type']); + $data = explode('_',$_REQUEST['type']); $type = $data['0']; - $object = new $type($_REQUEST['id']); - $songs = $object->get_random_songs(); - foreach ($songs as $song_id) { - $GLOBALS['user']->playlist->add_object($song_id,'song'); - } - break; - case 'playlist': - $playlist = new Playlist($_REQUEST['id']); - $items = $playlist->get_items(); - foreach ($items as $item) { - $GLOBALS['user']->playlist->add_object($item['object_id'],$item['type']); - } + $object = new $type($_REQUEST['id']); + $songs = $object->get_random_songs(); + foreach ($songs as $song_id) { + $GLOBALS['user']->playlist->add_object($song_id,'song'); + } break; - case 'playlist_random': - $playlist = new Playlist($_REQUEST['id']); - $items = $playlist->get_random_items(); - foreach ($items as $item) { - $GLOBALS['user']->playlist->add_object($item['object_id'],$item['type']); - } + case 'playlist': + $playlist = new Playlist($_REQUEST['id']); + $items = $playlist->get_items(); + foreach ($items as $item) { + $GLOBALS['user']->playlist->add_object($item['object_id'],$item['type']); + } break; - case 'clear_all': - $GLOBALS['user']->playlist->clear(); + case 'playlist_random': + $playlist = new Playlist($_REQUEST['id']); + $items = $playlist->get_random_items(); + foreach ($items as $item) { + $GLOBALS['user']->playlist->add_object($item['object_id'],$item['type']); + } break; - case 'live_stream': - $object = new Radio($_REQUEST['id']); + case 'clear_all': + $GLOBALS['user']->playlist->clear(); + break; + case 'live_stream': + $object = new Radio($_REQUEST['id']); // Confirm its a valid ID - if ($object->name) { - $GLOBALS['user']->playlist->add_object($object->id,'radio'); - } + if ($object->name) { + $GLOBALS['user']->playlist->add_object($object->id,'radio'); + } break; - case 'dynamic': - $random_id = Random::get_type_id($_REQUEST['random_type']); - $GLOBALS['user']->playlist->add_object($random_id,'random'); + case 'dynamic': + $random_id = Random::get_type_id($_REQUEST['random_type']); + $GLOBALS['user']->playlist->add_object($random_id,'random'); break; - case 'video': - $GLOBALS['user']->playlist->add_object($_REQUEST['id'],'video'); - break; - default: - case 'song': - $GLOBALS['user']->playlist->add_object($_REQUEST['id'],'song'); + case 'video': + $GLOBALS['user']->playlist->add_object($_REQUEST['id'],'video'); + break; + default: + case 'song': + $GLOBALS['user']->playlist->add_object($_REQUEST['id'],'song'); break; } // end switch - - $results['rightbar'] = ajax_include('rightbar.inc.php'); + + $results['rightbar'] = ajax_include('rightbar.inc.php'); break; /* Setting ratings */ case 'set_rating': - ob_start(); + ob_start(); $rating = new Rating($_GET['object_id'],$_GET['rating_type']); $rating->set_rating($_GET['rating']); // We have to clear the cache now :( Rating::remove_from_cache('rating_' . $_GET['rating_type'] . '_all',$_GET['object_id']); Rating::remove_from_cache('rating_' . $_GET['rating_type'] . '_user',$_GET['object_id']); - Rating::show($_GET['object_id'],$_GET['rating_type']); + Rating::show($_GET['object_id'],$_GET['rating_type']); $key = "rating_" . $_GET['object_id'] . "_" . $_GET['rating_type']; $results[$key] = ob_get_contents(); ob_end_clean(); @@ -315,20 +315,20 @@ switch ($_REQUEST['action']) { case 'browse': if ($_REQUEST['key'] && $_REQUEST['value']) { // Set any new filters we've just added - Browse::set_filter($_REQUEST['key'],$_REQUEST['value']); - } - if ($_REQUEST['sort']) { + Browse::set_filter($_REQUEST['key'],$_REQUEST['value']); + } + if ($_REQUEST['sort']) { // Set the new sort value - Browse::set_sort($_REQUEST['sort']); - } + Browse::set_sort($_REQUEST['sort']); + } // Refresh the browse div with our new filter options - $object_ids = Browse::get_objects(); + $object_ids = Browse::get_objects(); - ob_start(); - Browse::show_objects($object_ids, true); - $results['browse_content'] = ob_get_contents(); - ob_end_clean(); + ob_start(); + Browse::show_objects($object_ids, true); + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); break; default: $results['rfc3514'] = '0x1'; @@ -336,6 +336,6 @@ switch ($_REQUEST['action']) { } // end switch action // Go ahead and do the echo -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/browse.ajax.php b/server/browse.ajax.php index 13cd0153..39966303 100644 --- a/server/browse.ajax.php +++ b/server/browse.ajax.php @@ -23,20 +23,20 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { - case 'browse': +switch ($_REQUEST['action']) { + case 'browse': - $object_ids = array(); + $object_ids = array(); - Browse::set_type($_REQUEST['type']); + Browse::set_type($_REQUEST['type']); // Check 'value' with isset because it can null //(user type a "start with" word and deletes it) if ($_REQUEST['key'] && (isset($_REQUEST['multi_alpha_filter']) OR isset($_REQUEST['value']))) { // Set any new filters we've just added - Browse::set_filter($_REQUEST['key'],$_REQUEST['multi_alpha_filter']); + Browse::set_filter($_REQUEST['key'],$_REQUEST['multi_alpha_filter']); } if ($_REQUEST['sort']) { @@ -50,63 +50,63 @@ switch ($_REQUEST['action']) { break; case 'set_sort': - Browse::set_type($_REQUEST['type']); + Browse::set_type($_REQUEST['type']); - if ($_REQUEST['sort']) { - Browse::set_sort($_REQUEST['sort']); - } + if ($_REQUEST['sort']) { + Browse::set_sort($_REQUEST['sort']); + } - ob_start(); - Browse::show_objects(false); - $results['browse_content'] = ob_get_clean(); - break; - case 'toggle_tag': + ob_start(); + Browse::show_objects(false); + $results['browse_content'] = ob_get_clean(); + break; + case 'toggle_tag': $type = $_SESSION['tagcloud_type'] ? $_SESSION['tagcloud_type'] : 'song'; - Browse::set_type($type); - - + Browse::set_type($type); - break; - case 'delete_object': - switch ($_REQUEST['type']) { - case 'playlist': + + + break; + case 'delete_object': + switch ($_REQUEST['type']) { + case 'playlist': // Check the perms we need to on this - $playlist = new Playlist($_REQUEST['id']); - if (!$playlist->has_access()) { exit; } + $playlist = new Playlist($_REQUEST['id']); + if (!$playlist->has_access()) { exit; } // Delete it! - $playlist->delete(); + $playlist->delete(); $key = 'playlist_row_' . $playlist->id; break; - case 'live_stream': - if (!$GLOBALS['user']->has_access('75')) { exit; } + case 'live_stream': + if (!$GLOBALS['user']->has_access('75')) { exit; } $radio = new Radio($_REQUEST['id']); - $radio->delete(); - $key = 'live_stream_' . $radio->id; - break; - default: + $radio->delete(); + $key = 'live_stream_' . $radio->id; + break; + default: break; } // end switch on type - $results[$key] = ''; + $results[$key] = ''; - break; - case 'page': - Browse::set_type($_REQUEST['type']); - Browse::set_start($_REQUEST['start']); - - ob_start(); - Browse::show_objects(); - $results['browse_content'] = ob_get_clean(); - - break; - default: - $results['rfc3514'] = '0x1'; break; -} // switch on action; + case 'page': + Browse::set_type($_REQUEST['type']); + Browse::set_start($_REQUEST['start']); + + ob_start(); + Browse::show_objects(); + $results['browse_content'] = ob_get_clean(); + + break; + default: + $results['rfc3514'] = '0x1'; + break; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/democratic.ajax.php b/server/democratic.ajax.php index 35593439..241d1211 100644 --- a/server/democratic.ajax.php +++ b/server/democratic.ajax.php @@ -23,96 +23,96 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { - case 'delete_vote': - $democratic = Democratic::get_current_playlist(); - $democratic->set_parent(); - $democratic->remove_vote($_REQUEST['row_id']); - - ob_start(); - $object_ids = $democratic->get_items(); +switch ($_REQUEST['action']) { + case 'delete_vote': + $democratic = Democratic::get_current_playlist(); + $democratic->set_parent(); + $democratic->remove_vote($_REQUEST['row_id']); + + ob_start(); + $object_ids = $democratic->get_items(); Browse::set_type('democratic'); - Browse::reset(); - Browse::set_static_content(1); - Browse::show_objects($object_ids); + Browse::reset(); + Browse::set_static_content(1); + Browse::show_objects($object_ids); - require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php'; + require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php'; $results['browse_content'] = ob_get_contents(); - ob_end_clean(); + ob_end_clean(); break; - case 'add_vote': + case 'add_vote': - $democratic = Democratic::get_current_playlist(); - $democratic->set_parent(); - $democratic->add_vote($_REQUEST['object_id'],$_REQUEST['type']); + $democratic = Democratic::get_current_playlist(); + $democratic->set_parent(); + $democratic->add_vote($_REQUEST['object_id'],$_REQUEST['type']); - ob_start(); - $object_ids = $democratic->get_items(); + ob_start(); + $object_ids = $democratic->get_items(); Browse::set_type('democratic'); - Browse::reset(); - Browse::set_static_content(1); - Browse::show_objects($object_ids); + Browse::reset(); + Browse::set_static_content(1); + Browse::show_objects($object_ids); - require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php'; - $results['browse_content'] = ob_get_contents(); - ob_end_clean(); + require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php'; + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); - break; - case 'delete': - if (!$GLOBALS['user']->has_access('75')) { - exit; - } + break; + case 'delete': + if (!$GLOBALS['user']->has_access('75')) { + exit; + } - $democratic = Democratic::get_current_playlist(); - $democratic->set_parent(); - $democratic->delete_votes($_REQUEST['row_id']); + $democratic = Democratic::get_current_playlist(); + $democratic->set_parent(); + $democratic->delete_votes($_REQUEST['row_id']); - ob_start(); - $object_ids = $democratic->get_items(); + ob_start(); + $object_ids = $democratic->get_items(); Browse::set_type('democratic'); - Browse::reset(); - Browse::set_static_content(1); - Browse::show_objects($object_ids); - $results['browse_content'] = ob_get_contents(); - ob_end_clean(); - - break; - case 'send_playlist': - if (!Access::check('interface','75')) { - exit; - } + Browse::reset(); + Browse::set_static_content(1); + Browse::show_objects($object_ids); + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); - $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=democratic&democratic_id=' . scrub_out($_REQUEST['democratic_id']); + break; + case 'send_playlist': + if (!Access::check('interface','75')) { + exit; + } + + $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=democratic&democratic_id=' . scrub_out($_REQUEST['democratic_id']); $results['rfc3514'] = ''; - break; - case 'clear_playlist': - - if (!Access::check('interface','100')) { - exit; - } - - $democratic = new Democratic($_REQUEST['democratic_id']); - $democratic->set_parent(); - $democratic->clear(); - - ob_start(); - $object_ids = array(); - Browse::set_type('democratic'); - Browse::reset(); - Browse::set_static_content(1); - Browse::show_objects($object_ids); - $results['browse_content'] = ob_get_contents(); - ob_end_clean(); - - break; - default: - $results['rfc3514'] = '0x1'; break; -} // switch on action; + case 'clear_playlist': + + if (!Access::check('interface','100')) { + exit; + } + + $democratic = new Democratic($_REQUEST['democratic_id']); + $democratic->set_parent(); + $democratic->clear(); + + ob_start(); + $object_ids = array(); + Browse::set_type('democratic'); + Browse::reset(); + Browse::set_static_content(1); + Browse::show_objects($object_ids); + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); + + break; + default: + $results['rfc3514'] = '0x1'; + break; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/flag.ajax.php b/server/flag.ajax.php index a725d98d..7ba8b3d3 100644 --- a/server/flag.ajax.php +++ b/server/flag.ajax.php @@ -23,49 +23,49 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { - case 'reject': - if (!Access::check('interface','75')) { - $results['rfc3514'] = '0x1'; - break; - } +switch ($_REQUEST['action']) { + case 'reject': + if (!Access::check('interface','75')) { + $results['rfc3514'] = '0x1'; + break; + } - // Remove the flag from the table - $flag = new Flag($_REQUEST['flag_id']); - $flag->delete(); + // Remove the flag from the table + $flag = new Flag($_REQUEST['flag_id']); + $flag->delete(); - $flagged = Flag::get_all(); - ob_start(); - Browse::set_type('flagged'); - Browse::set_static_content(1); - Browse::save_objects($flagged); - Browse::show_objects($flagged); - $results['browse_content'] = ob_get_contents(); - ob_end_clean(); + $flagged = Flag::get_all(); + ob_start(); + Browse::set_type('flagged'); + Browse::set_static_content(1); + Browse::save_objects($flagged); + Browse::show_objects($flagged); + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); break; - case 'accept': - if (!Access::check('interface','75')) { - $results['rfc3514'] = '0x1'; - break; - } + case 'accept': + if (!Access::check('interface','75')) { + $results['rfc3514'] = '0x1'; + break; + } - $flag = new Flag($_REQUEST['flag_id']); - $flag->approve(); - $flag->format(); - ob_start(); - require_once Config::get('prefix') . '/templates/show_flag_row.inc.php'; - $results['flagged_' . $flag->id] = ob_get_contents(); - ob_end_clean(); + $flag = new Flag($_REQUEST['flag_id']); + $flag->approve(); + $flag->format(); + ob_start(); + require_once Config::get('prefix') . '/templates/show_flag_row.inc.php'; + $results['flagged_' . $flag->id] = ob_get_contents(); + ob_end_clean(); - break; - default: - $results['rfc3514'] = '0x1'; break; -} // switch on action; + default: + $results['rfc3514'] = '0x1'; + break; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/index.ajax.php b/server/index.ajax.php index 674a75f2..e84e5bf5 100644 --- a/server/index.ajax.php +++ b/server/index.ajax.php @@ -23,33 +23,33 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { - case 'random_albums': - $albums = Album::get_random_albums('6'); - if (count($albums) AND is_array($albums)) { - ob_start(); - require_once Config::get('prefix') . '/templates/show_random_albums.inc.php'; - $results['random_selection'] = ob_get_clean(); - } - else { - $results['random_selection'] = ''; - } +switch ($_REQUEST['action']) { + case 'random_albums': + $albums = Album::get_random_albums('6'); + if (count($albums) AND is_array($albums)) { + ob_start(); + require_once Config::get('prefix') . '/templates/show_random_albums.inc.php'; + $results['random_selection'] = ob_get_clean(); + } + else { + $results['random_selection'] = ''; + } break; - case 'reloadnp': - ob_start(); - show_now_playing(); - $results['now_playing'] = ob_get_clean(); - ob_start(); - $data = Song::get_recently_played(); - Song::build_cache(array_keys($data)); - if (count($data)) { + case 'reloadnp': + ob_start(); + show_now_playing(); + $results['now_playing'] = ob_get_clean(); + ob_start(); + $data = Song::get_recently_played(); + Song::build_cache(array_keys($data)); + if (count($data)) { require_once Config::get('prefix') . '/templates/show_recently_played.inc.php'; - } - $results['recently_played'] = ob_get_clean(); - break; - case 'sidebar': + } + $results['recently_played'] = ob_get_clean(); + break; + case 'sidebar': switch ($_REQUEST['button']) { case 'home': case 'modules': @@ -65,18 +65,18 @@ switch ($_REQUEST['action']) { default: exit; break; - } // end switch on button + } // end switch on button ob_start(); $_SESSION['state']['sidebar_tab'] = $button; require_once Config::get('prefix') . '/templates/sidebar.inc.php'; $results['sidebar'] = ob_get_contents(); ob_end_clean(); - default: - $results['rfc3514'] = '0x1'; + default: + $results['rfc3514'] = '0x1'; break; -} // switch on action; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/localplay.ajax.php b/server/localplay.ajax.php index 9d4299cb..d505b956 100644 --- a/server/localplay.ajax.php +++ b/server/localplay.ajax.php @@ -23,69 +23,69 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { - case 'set_instance': +switch ($_REQUEST['action']) { + case 'set_instance': // Make sure they they are allowed to do this - if (!Access::check('localplay','5')) { - debug_event('DENIED','Error attempted to set instance without required level','1'); - exit; - } + if (!Access::check('localplay','5')) { + debug_event('DENIED','Error attempted to set instance without required level','1'); + exit; + } $type = $_REQUEST['instance'] ? 'localplay' : 'stream'; - $localplay = new Localplay(Config::get('localplay_controller')); - $localplay->set_active_instance($_REQUEST['instance']); - Preference::update('play_type',$GLOBALS['user']->id,$type); + $localplay = new Localplay(Config::get('localplay_controller')); + $localplay->set_active_instance($_REQUEST['instance']); + Preference::update('play_type',$GLOBALS['user']->id,$type); // We should also refesh the sidebar - ob_start(); - require_once Config::get('prefix') . '/templates/sidebar.inc.php'; - $results['sidebar'] = ob_get_contents(); - ob_end_clean(); + ob_start(); + require_once Config::get('prefix') . '/templates/sidebar.inc.php'; + $results['sidebar'] = ob_get_contents(); + ob_end_clean(); break; - case 'command': + case 'command': // Make sure they are allowed to do this - if (!Access::check('localplay','50')) { - debug_event('DENIED','Attempted to control Localplay without sufficient access','1'); + if (!Access::check('localplay','50')) { + debug_event('DENIED','Attempted to control Localplay without sufficient access','1'); exit; - } + } + + $localplay = new Localplay(Config::get('localplay_controller')); + $localplay->connect(); - $localplay = new Localplay(Config::get('localplay_controller')); - $localplay->connect(); - // Switch on valid commands - switch ($_REQUEST['command']) { - case 'prev': - case 'next': - case 'stop': - case 'play': - case 'pause': - $command = scrub_in($_REQUEST['command']); - $localplay->$command(); + switch ($_REQUEST['command']) { + case 'prev': + case 'next': + case 'stop': + case 'play': + case 'pause': + $command = scrub_in($_REQUEST['command']); + $localplay->$command(); break; - case 'volume_up': - case 'volume_down': - case 'volume_mute': - $command = scrub_in($_REQUEST['command']); - $localplay->$command(); + case 'volume_up': + case 'volume_down': + case 'volume_mute': + $command = scrub_in($_REQUEST['command']); + $localplay->$command(); // We actually want to refresh something here - ob_start(); + ob_start(); require_once Config::get('prefix') . '/templates/show_localplay_status.inc.php'; - $results['localplay_status'] = ob_get_contents(); - ob_end_clean(); + $results['localplay_status'] = ob_get_contents(); + ob_end_clean(); break; - case 'delete_all': - $localplay->delete_all(); - Browse::save_objects(array()); - ob_start(); - Browse::show_objects(); - $results['browse_content'] = ob_get_contents(); - ob_end_clean(); + case 'delete_all': + $localplay->delete_all(); + Browse::save_objects(array()); + ob_start(); + Browse::show_objects(); + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); break; - case 'skip': + case 'skip': $localplay->skip(intval($_REQUEST['id'])); $objects = $localplay->get(); ob_start(); @@ -95,94 +95,94 @@ switch ($_REQUEST['action']) { $results['browse_content'] = ob_get_contents(); ob_end_clean(); break; - default: + default: // Nothing - break; + break; } // end whitelist - break; - case 'delete_track': + break; + case 'delete_track': // Load Connect... yada yada - if (!Access::check('localplay','50')) { - debug_event('DENIED','Attempted to delete track without access','1'); - exit; - } - $localplay = new Localplay(Config::get('localplay_controller')); - $localplay->connect(); + if (!Access::check('localplay','50')) { + debug_event('DENIED','Attempted to delete track without access','1'); + exit; + } + $localplay = new Localplay(Config::get('localplay_controller')); + $localplay->connect(); // Scrub in the delete request - $id = intval($_REQUEST['id']); + $id = intval($_REQUEST['id']); + + $localplay->delete_track($id); - $localplay->delete_track($id); - // Wait incase we just deleted what we were playing sleep(3); - $objects = $localplay->get(); - $status = $localplay->status(); + $objects = $localplay->get(); + $status = $localplay->status(); - ob_start(); + ob_start(); Browse::set_type('playlist_localplay'); Browse::set_static_content(1); Browse::show_objects($objects); - $results['browse_content'] = ob_get_contents(); - ob_end_clean(); + $results['browse_content'] = ob_get_contents(); + ob_end_clean(); - break; - case 'delete_instance': + break; + case 'delete_instance': // Make sure that you have access to do this... - if (!Access::check('localplay','75')) { - debug_event('DENIED','Attempted to delete instance without access','1'); - exit; - } + if (!Access::check('localplay','75')) { + debug_event('DENIED','Attempted to delete instance without access','1'); + exit; + } // Scrub it in - $localplay = new Localplay(Config::get('localplay_controller')); - $localplay->delete_instance($_REQUEST['instance']); - - $key = 'localplay_instance_' . $_REQUEST['instance']; - $results[$key] = ''; - break; - case 'repeat': + $localplay = new Localplay(Config::get('localplay_controller')); + $localplay->delete_instance($_REQUEST['instance']); + + $key = 'localplay_instance_' . $_REQUEST['instance']; + $results[$key] = ''; + break; + case 'repeat': // Make sure that they have access to do this again no clue - if (!Access::check('localplay','50')) { - debug_event('DENIED','Attempted to set repeat without access','1'); - exit; - } - - // Scrub her in - $localplay = new Localplay(Config::get('localplay_controller')); - $localplay->connect(); + if (!Access::check('localplay','50')) { + debug_event('DENIED','Attempted to set repeat without access','1'); + exit; + } + + // Scrub her in + $localplay = new Localplay(Config::get('localplay_controller')); + $localplay->connect(); $localplay->repeat(make_bool($_REQUEST['value'])); - ob_start(); - require_once Config::get('prefix') . '/templates/show_localplay_status.inc.php'; - $results['localplay_status'] = ob_get_contents(); - ob_end_clean(); + ob_start(); + require_once Config::get('prefix') . '/templates/show_localplay_status.inc.php'; + $results['localplay_status'] = ob_get_contents(); + ob_end_clean(); break; - case 'random': + case 'random': // Make sure that they have access to do this - if (!Access::check('localplay','50')) { - debug_event('DENIED','Attempted to set random without access','1'); - exit; - } - + if (!Access::check('localplay','50')) { + debug_event('DENIED','Attempted to set random without access','1'); + exit; + } + // Scrub her in - $localplay = new Localplay(Config::get('localplay_controller')); - $localplay->connect(); - $localplay->random(make_bool($_REQUEST['value'])); + $localplay = new Localplay(Config::get('localplay_controller')); + $localplay->connect(); + $localplay->random(make_bool($_REQUEST['value'])); - ob_start(); - require_once Config::get('prefix') . '/templates/show_localplay_status.inc.php'; - $results['localplay_status'] = ob_get_contents(); - ob_end_clean(); + ob_start(); + require_once Config::get('prefix') . '/templates/show_localplay_status.inc.php'; + $results['localplay_status'] = ob_get_contents(); + ob_end_clean(); - break; - default: - $results['rfc3514'] = '0x1'; break; -} // switch on action; + default: + $results['rfc3514'] = '0x1'; + break; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/playlist.ajax.php b/server/playlist.ajax.php index acf47685..9cf209cc 100644 --- a/server/playlist.ajax.php +++ b/server/playlist.ajax.php @@ -23,130 +23,130 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { - case 'delete_track': +switch ($_REQUEST['action']) { + case 'delete_track': // Create the object and remove the track - $playlist = new Playlist($_REQUEST['playlist_id']); - $playlist->format(); + $playlist = new Playlist($_REQUEST['playlist_id']); + $playlist->format(); if ($playlist->has_access()) { - $playlist->delete_track($_REQUEST['track_id']); - } + $playlist->delete_track($_REQUEST['track_id']); + } - $object_ids = $playlist->get_items(); - ob_start(); + $object_ids = $playlist->get_items(); + ob_start(); Browse::set_type('playlist_song'); Browse::add_supplemental_object('playlist',$playlist->id); Browse::save_objects($object_ids); Browse::show_objects($object_ids); - $results['browse_content'] = ob_get_clean(); + $results['browse_content'] = ob_get_clean(); break; - case 'edit_track': - $playlist = new Playlist($_REQUEST['playlist_id']); - if (!$playlist->has_access()) { - $results['rfc3514'] = '0x1'; - break; - } + case 'edit_track': + $playlist = new Playlist($_REQUEST['playlist_id']); + if (!$playlist->has_access()) { + $results['rfc3514'] = '0x1'; + break; + } // They've got access, show the edit page - $track = $playlist->get_track($_REQUEST['track_id']); - $song = new Song($track['object_id']); - $song->format(); - require_once Config::get('prefix') . '/templates/show_edit_playlist_song_row.inc.php'; - $results['track_' . $track['id']] = ob_get_clean(); - break; - case 'save_track': - $playlist = new Playlist($_REQUEST['playlist_id']); - if (!$playlist->has_access()) { - $results['rfc3514'] = '0x1'; - break; - } - $playlist->format(); + $track = $playlist->get_track($_REQUEST['track_id']); + $song = new Song($track['object_id']); + $song->format(); + require_once Config::get('prefix') . '/templates/show_edit_playlist_song_row.inc.php'; + $results['track_' . $track['id']] = ob_get_clean(); + break; + case 'save_track': + $playlist = new Playlist($_REQUEST['playlist_id']); + if (!$playlist->has_access()) { + $results['rfc3514'] = '0x1'; + break; + } + $playlist->format(); // They've got access, save this guy and re-display row - $playlist->update_track_number($_GET['track_id'],$_POST['track']); - $track = $playlist->get_track($_GET['track_id']); - $song = new Song($track['object_id']); - $song->format(); - $playlist_track = $track['track']; + $playlist->update_track_number($_GET['track_id'],$_POST['track']); + $track = $playlist->get_track($_GET['track_id']); + $song = new Song($track['object_id']); + $song->format(); + $playlist_track = $track['track']; require Config::get('prefix') . '/templates/show_playlist_song_row.inc.php'; - $results['track_' . $track['id']] = ob_get_clean(); - break; + $results['track_' . $track['id']] = ob_get_clean(); + break; case 'create': - if (!Access::check('interface','25')) { - debug_event('DENIED','Error:' . $GLOBALS['user']->username . ' does not have user access, unable to create playlist','1'); - break; - } + if (!Access::check('interface','25')) { + debug_event('DENIED','Error:' . $GLOBALS['user']->username . ' does not have user access, unable to create playlist','1'); + break; + } // Pull the current active playlist items - $objects = $GLOBALS['user']->playlist->get_items(); + $objects = $GLOBALS['user']->playlist->get_items(); + + $name = $GLOBALS['user']->username . ' - ' . date("d/m/Y H:i:s",time()); - $name = $GLOBALS['user']->username . ' - ' . date("d/m/Y H:i:s",time()); - // generate the new playlist - $playlist_id = Playlist::create($name,'public'); - if (!$playlist_id) { break; } - $playlist = new Playlist($playlist_id); + $playlist_id = Playlist::create($name,'public'); + if (!$playlist_id) { break; } + $playlist = new Playlist($playlist_id); // Itterate through and add them to our new playlist - foreach ($objects as $object_data) { + foreach ($objects as $object_data) { // For now only allow songs on here, we'll change this later $type = array_shift($object_data); - if ($type == 'song') { - $songs[] = array_shift($object_data); - } + if ($type == 'song') { + $songs[] = array_shift($object_data); + } } // object_data - + // Add our new songs - $playlist->add_songs($songs,'ORDERED'); - $playlist->format(); - $object_ids = $playlist->get_items(); - ob_start(); - require_once Config::get('prefix') . '/templates/show_playlist.inc.php'; - $results['content'] = ob_get_clean(); + $playlist->add_songs($songs,'ORDERED'); + $playlist->format(); + $object_ids = $playlist->get_items(); + ob_start(); + require_once Config::get('prefix') . '/templates/show_playlist.inc.php'; + $results['content'] = ob_get_clean(); break; - case 'append': + case 'append': // Pull the current active playlist items - $objects = $GLOBALS['user']->playlist->get_items(); + $objects = $GLOBALS['user']->playlist->get_items(); // Create the playlist object - $playlist = new Playlist($_REQUEST['playlist_id']); + $playlist = new Playlist($_REQUEST['playlist_id']); - // We need to make sure that they have access - if (!$playlist->has_access()) { - break; - } + // We need to make sure that they have access + if (!$playlist->has_access()) { + break; + } - $songs = array(); + $songs = array(); // Itterate through and add them to our new playlist - foreach ($objects as $element) { - $type = array_shift($element); - switch ($type) { - case 'song': - $songs[] = array_shift($element); - break; - } // end switch + foreach ($objects as $element) { + $type = array_shift($element); + switch ($type) { + case 'song': + $songs[] = array_shift($element); + break; + } // end switch } // foreach - // Override normal include procedure - Ajax::set_include_override(true); + // Override normal include procedure + Ajax::set_include_override(true); // Add our new songs - $playlist->add_songs($songs,'ORDERED'); - $playlist->format(); - $object_ids = $playlist->get_items(); - ob_start(); - require_once Config::get('prefix') . '/templates/show_playlist.inc.php'; - $results['content'] = ob_get_contents(); - ob_end_clean(); + $playlist->add_songs($songs,'ORDERED'); + $playlist->format(); + $object_ids = $playlist->get_items(); + ob_start(); + require_once Config::get('prefix') . '/templates/show_playlist.inc.php'; + $results['content'] = ob_get_contents(); + ob_end_clean(); break; - default: - $results['rfc3514'] = '0x1'; + default: + $results['rfc3514'] = '0x1'; break; -} // switch on action; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/random.ajax.php b/server/random.ajax.php index fa4b850e..f7d69b3c 100644 --- a/server/random.ajax.php +++ b/server/random.ajax.php @@ -23,14 +23,14 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { +switch ($_REQUEST['action']) { case 'album': $album_id = Random::album(); // If we don't get anything stop - if (!$album_id) { $results['rfc3514'] = '0x1'; break; } + if (!$album_id) { $results['rfc3514'] = '0x1'; break; } $album = new Album($album_id); $songs = $album->get_songs(); @@ -43,7 +43,7 @@ switch ($_REQUEST['action']) { $artist_id = Random::artist(); // If we don't get anything stop - if (!$artist_id) { $results['rfc3514'] = '0x1'; break; } + if (!$artist_id) { $results['rfc3514'] = '0x1'; break; } $artist = new Artist($artist_id); $songs = $artist->get_songs(); @@ -54,9 +54,9 @@ switch ($_REQUEST['action']) { break; case 'playlist': $playlist_id = Random::playlist(); - + // If we don't get any results stop right here! - if (!$playlist_id) { $results['rfc3514'] = '0x1'; break; } + if (!$playlist_id) { $results['rfc3514'] = '0x1'; break; } $playlist = new Playlist($playlist_id); $items = $playlist->get_items(); @@ -65,29 +65,29 @@ switch ($_REQUEST['action']) { } $results['rightbar'] = ajax_include('rightbar.inc.php'); break; - case 'advanced_random': - $object_ids = Random::advanced($_POST); + case 'advanced_random': + $object_ids = Random::advanced($_POST); // First add them to the active playlist - foreach ($object_ids as $object_id) { - $GLOBALS['user']->playlist->add_object($object_id,'song'); - } - $results['rightbar'] = ajax_include('rightbar.inc.php'); + foreach ($object_ids as $object_id) { + $GLOBALS['user']->playlist->add_object($object_id,'song'); + } + $results['rightbar'] = ajax_include('rightbar.inc.php'); // Now setup the browse and show them below! - Browse::set_type('song'); + Browse::set_type('song'); Browse::save_objects($object_ids); - ob_start(); - Browse::show_objects(); - $results['browse'] = ob_get_contents(); - ob_end_clean(); - + ob_start(); + Browse::show_objects(); + $results['browse'] = ob_get_contents(); + ob_end_clean(); + break; - default: - $results['rfc3514'] = '0x1'; + default: + $results['rfc3514'] = '0x1'; break; -} // switch on action; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/song.ajax.php b/server/song.ajax.php index 1ce060e7..14f354d2 100644 --- a/server/song.ajax.php +++ b/server/song.ajax.php @@ -23,32 +23,32 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { - case 'flip_state': - if (!Access::check('interface','75')) { - debug_event('DENIED',$GLOBALS['user']->username . ' attempted to change the state of a song','1'); - exit; - } +switch ($_REQUEST['action']) { + case 'flip_state': + if (!Access::check('interface','75')) { + debug_event('DENIED',$GLOBALS['user']->username . ' attempted to change the state of a song','1'); + exit; + } + + $song = new Song($_REQUEST['song_id']); + $new_enabled = $song->enabled ? '0' : '1'; + $song->update_enabled($new_enabled,$song->id); + $song->enabled = $new_enabled; + $song->format(); - $song = new Song($_REQUEST['song_id']); - $new_enabled = $song->enabled ? '0' : '1'; - $song->update_enabled($new_enabled,$song->id); - $song->enabled = $new_enabled; - $song->format(); - //Return the new Ajax::button $id = 'button_flip_state_' . $song->id; $button = $song->enabled ? 'disable' : 'enable'; - $results[$id] = Ajax::button('?page=song&action=flip_state&song_id=' . $song->id,$button,_(ucfirst($button)),'flip_state_' . $song->id); + $results[$id] = Ajax::button('?page=song&action=flip_state&song_id=' . $song->id,$button,_(ucfirst($button)),'flip_state_' . $song->id); break; - default: - $results['rfc3514'] = '0x1'; + default: + $results['rfc3514'] = '0x1'; break; -} // switch on action; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/stats.ajax.php b/server/stats.ajax.php index d3f11a87..3b824c5f 100644 --- a/server/stats.ajax.php +++ b/server/stats.ajax.php @@ -23,14 +23,14 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { - default: - $results['rfc3514'] = '0x1'; +switch ($_REQUEST['action']) { + default: + $results['rfc3514'] = '0x1'; break; -} // switch on action; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/stream.ajax.php b/server/stream.ajax.php index db5d035a..01d6396f 100644 --- a/server/stream.ajax.php +++ b/server/stream.ajax.php @@ -23,74 +23,74 @@ /** * Sub-Ajax page, requires AJAX_INCLUDE as one */ -if (AJAX_INCLUDE != '1') { exit; } +if (AJAX_INCLUDE != '1') { exit; } -switch ($_REQUEST['action']) { - case 'set_play_type': +switch ($_REQUEST['action']) { + case 'set_play_type': // Make sure they have the rights to do this - if (!Preference::has_access('play_type')) { - $results['rfc3514'] = '0x1'; + if (!Preference::has_access('play_type')) { + $results['rfc3514'] = '0x1'; break; - } + } - switch ($_POST['type']) { - case 'stream': + switch ($_POST['type']) { + case 'stream': case 'localplay': - case 'democratic': - $key = 'allow_' . $_POST['type'] . '_playback'; - if (!Config::get($key)) { - $results['rfc3514'] = '0x1'; - break 2; - } - $new = $_POST['type']; - break; - case 'xspf_player': - $new = $_POST['type']; + case 'democratic': + $key = 'allow_' . $_POST['type'] . '_playback'; + if (!Config::get($key)) { + $results['rfc3514'] = '0x1'; + break 2; + } + $new = $_POST['type']; + break; + case 'xspf_player': + $new = $_POST['type']; // Rien a faire - break; - default: - $new = 'stream'; - $results['rfc3514'] = '0x1'; - break 2; - } // end switch + break; + default: + $new = 'stream'; + $results['rfc3514'] = '0x1'; + break 2; + } // end switch - $current = Config::get('play_type'); + $current = Config::get('play_type'); // Go ahead and update their preference - if (Preference::update('play_type',$GLOBALS['user']->id,$new)) { - Config::set('play_type',$new,'1'); - } - + if (Preference::update('play_type',$GLOBALS['user']->id,$new)) { + Config::set('play_type',$new,'1'); + } - if (($new == 'localplay' AND $current != 'localplay') OR ($current == 'localplay' AND $new != 'localplay')) { - $results['rightbar'] = ajax_include('rightbar.inc.php'); - } - $results['rfc3514'] = '0x0'; + if (($new == 'localplay' AND $current != 'localplay') OR ($current == 'localplay' AND $new != 'localplay')) { + $results['rightbar'] = ajax_include('rightbar.inc.php'); + } + + $results['rfc3514'] = '0x0'; break; - case 'basket': + case 'basket': // Go ahead and see if we should clear the playlist here or not, we might not actually clear it in the session - // we'll just have to feed it bad data. - // FIXME: This is sad, will be fixed when I switch how streaming works. + // we'll just have to feed it bad data. + // FIXME: This is sad, will be fixed when I switch how streaming works. // Check to see if 'clear' was passed if it was then we need to reset the basket if ( ($_REQUEST['playlist_method'] == 'clear' || Config::get('playlist_method') == 'clear') AND Config::get('play_type') != 'xspf_player') { - define('NO_SONGS','1'); - ob_start(); - require_once Config::get('prefix') . '/templates/rightbar.inc.php'; - $results['rightbar'] = ob_get_clean(); + define('NO_SONGS','1'); + ob_start(); + require_once Config::get('prefix') . '/templates/rightbar.inc.php'; + $results['rightbar'] = ob_get_clean(); } // We need to set the basket up! - $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket&playlist_method=' . scrub_out($_REQUEST['playlist_method']); - $results['rfc3514'] = ''; + $_SESSION['iframe']['target'] = Config::get('web_path') . '/stream.php?action=basket&playlist_method=' . scrub_out($_REQUEST['playlist_method']); + $results['rfc3514'] = ''; break; - default: - $results['rfc3514'] = '0x1'; + default: + $results['rfc3514'] = '0x1'; break; -} // switch on action; +} // switch on action; // We always do this -echo xml_from_array($results); +echo xml_from_array($results); ?> diff --git a/server/tag.ajax.php b/server/tag.ajax.php index 511265a0..a1c43988 100644 --- a/server/tag.ajax.php +++ b/server/tag.ajax.php @@ -44,11 +44,11 @@ switch ($_REQUEST['action']) { // Set browse method Browse::set_type('song'); - Browse::set_filter('tag',$_GET['tag_id']); - $object_ids = Browse::get_objects(); - ob_start(); - Browse::show_objects($object_ids); - $results['browse_content'] = ob_get_clean(); + Browse::set_filter('tag',$_GET['tag_id']); + $object_ids = Browse::get_objects(); + ob_start(); + Browse::show_objects($object_ids); + $results['browse_content'] = ob_get_clean(); // Retrive current objects of type based on combined filters break; diff --git a/server/xml.server.php b/server/xml.server.php index f568ca03..1797ece1 100644 --- a/server/xml.server.php +++ b/server/xml.server.php @@ -20,30 +20,30 @@ */ /** - * This is accessed remotly to allow outside scripts access to ampache information - * as such it needs to verify the session id that is passed + * This is accessed remotly to allow outside scripts access to ampache information + * as such it needs to verify the session id that is passed */ define('NO_SESSION','1'); require_once '../lib/init.php'; // If it's not a handshake then we can allow it to take up lots of time -if ($_REQUEST['action'] != 'handshake') { - set_time_limit(0); -} +if ($_REQUEST['action'] != 'handshake') { + set_time_limit(0); +} /* Set the correct headers */ header("Content-type: text/xml; charset=" . Config::get('site_charset')); header("Content-Disposition: attachment; filename=information.xml"); // If we don't even have access control on then we can't use this! -if (!Config::get('access_control')) { - ob_end_clean(); - debug_event('Access Control','Error Attempted to use XML API with Access Control turned off','3'); +if (!Config::get('access_control')) { + ob_end_clean(); + debug_event('Access Control','Error Attempted to use XML API with Access Control turned off','3'); echo xmlData::error('501',_('Access Control not Enabled')); - exit; -} + exit; +} -/** +/** * Verify the existance of the Session they passed in we do allow them to * login via this interface so we do have an exception for action=login */ @@ -58,37 +58,37 @@ if (!vauth::session_exists('api', $_REQUEST['auth']) AND $_REQUEST['action'] != $session = vauth::get_session_data($_REQUEST['auth']); $username = ($_REQUEST['action'] == 'handshake' || $_REQUEST['action'] == 'ping') ? $_REQUEST['user'] : $session['username']; -if (!Access::check_network('init-api',$username,'5')) { +if (!Access::check_network('init-api',$username,'5')) { debug_event('Access Denied','Unauthorized access attempt to API [' . $_SERVER['REMOTE_ADDR'] . ']', '3'); - ob_end_clean(); + ob_end_clean(); echo xmlData::error('403',_('Unauthorized access attempt to API - ACL Error')); - exit(); + exit(); } -if ($_REQUEST['action'] != 'handshake' AND $_REQUEST['action'] != 'ping') { - vauth::session_extend($_REQUEST['auth']); +if ($_REQUEST['action'] != 'handshake' AND $_REQUEST['action'] != 'ping') { + vauth::session_extend($_REQUEST['auth']); $GLOBALS['user'] = User::get_from_username($session['username']); -} +} // Get the list of possible methods for the Ampache API -$methods = get_class_methods('api'); +$methods = get_class_methods('api'); // Define list of internal functions that should be skipped -$interal_functions = array('set_filter'); +$interal_functions = array('set_filter'); // Recurse through them and see if we're calling one of them -foreach ($methods as $method) { - if (in_array($method,$internal_functions)) { continue; } +foreach ($methods as $method) { + if (in_array($method,$internal_functions)) { continue; } // If the method is the same as the action being called // Then let's call this function! - if ($_GET['action'] == $method) { + if ($_GET['action'] == $method) { call_user_func(array('api',$method),$_GET); // We only allow a single function to be called, and we assume it's cleaned up! - exit; - } + exit; + } -} // end foreach methods in API +} // end foreach methods in API // If we manage to get here, we still need to hand out an XML document ob_end_clean(); diff --git a/shout.php b/shout.php index 1ab93ef6..fa53879b 100644 --- a/shout.php +++ b/shout.php @@ -21,42 +21,42 @@ */ require_once 'lib/init.php'; -show_header(); +show_header(); // Switch on the incomming action -switch ($_REQUEST['action']) { - case 'add_shout': +switch ($_REQUEST['action']) { + case 'add_shout': // Must be at least a user to do this - if (!Access::check('interface','25')) { - access_denied(); - exit; - } + if (!Access::check('interface','25')) { + access_denied(); + exit; + } - if (!Core::form_verify('add_shout','post')) { - access_denied(); - exit; - } + if (!Core::form_verify('add_shout','post')) { + access_denied(); + exit; + } - $shout_id = shoutBox::create($_POST); - header("Location:" . Config::get('web_path')); - break; - case 'show_add_shout': + $shout_id = shoutBox::create($_POST); + header("Location:" . Config::get('web_path')); + break; + case 'show_add_shout': // Get our object first - $object = shoutBox::get_object($_REQUEST['type'],$_REQUEST['id']); + $object = shoutBox::get_object($_REQUEST['type'],$_REQUEST['id']); - if (!$object->id) { - Error::add('general',_('Invalid Object Selected')); - Error::display('general'); + if (!$object->id) { + Error::add('general',_('Invalid Object Selected')); + Error::display('general'); break; - } + } // Now go ahead and display the page where we let them add a comment etc - require_once Config::get('prefix') . '/templates/show_add_shout.inc.php'; - break; - default: - header("Location:" . Config::get('web_path')); + require_once Config::get('prefix') . '/templates/show_add_shout.inc.php'; + break; + default: + header("Location:" . Config::get('web_path')); break; } // end switch on action -show_footer(); +show_footer(); ?> diff --git a/stats.php b/stats.php index 19ef23c5..7cf6f4cb 100644 --- a/stats.php +++ b/stats.php @@ -25,18 +25,18 @@ */ require_once 'lib/init.php'; -show_header(); +show_header(); /* Switch on the action to be performed */ -switch ($_REQUEST['action']) { +switch ($_REQUEST['action']) { // Show a Users "Profile" page - case 'show_user': - $client = new User($_REQUEST['user_id']); - require_once Config::get('prefix') . '/templates/show_user.inc.php'; + case 'show_user': + $client = new User($_REQUEST['user_id']); + require_once Config::get('prefix') . '/templates/show_user.inc.php'; break; case 'user_stats': /* Get em! */ - $working_user = new User($_REQUEST['user_id']); + $working_user = new User($_REQUEST['user_id']); /* Pull favs */ $favorite_artists = $working_user->get_favorites('artist'); @@ -44,21 +44,21 @@ switch ($_REQUEST['action']) { $favorite_songs = $working_user->get_favorites('song'); require_once Config::get('prefix') . '/templates/show_user_stats.inc.php'; - + break; // Show stats - case 'newest': - require_once Config::get('prefix') . '/templates/show_newest.inc.php'; - break; - case 'popular': - require_once Config::get('prefix') . '/templates/show_popular.inc.php'; - break; - case 'show': - default: - require_once Config::get('prefix') . '/templates/show_stats.inc.php'; + case 'newest': + require_once Config::get('prefix') . '/templates/show_newest.inc.php'; + break; + case 'popular': + require_once Config::get('prefix') . '/templates/show_popular.inc.php'; + break; + case 'show': + default: + require_once Config::get('prefix') . '/templates/show_stats.inc.php'; break; } // end switch on action -show_footer(); +show_footer(); ?> diff --git a/stream.php b/stream.php index 911e6b12..7e0ab8b3 100644 --- a/stream.php +++ b/stream.php @@ -31,17 +31,17 @@ $media_ids = array(); $web_path = Config::get('web_path'); /** - * action switch + * action switch */ -switch ($_REQUEST['action']) { - case 'basket': - // Pull in our items (multiple types) - $media_ids = $GLOBALS['user']->playlist->get_items(); +switch ($_REQUEST['action']) { + case 'basket': + // Pull in our items (multiple types) + $media_ids = $GLOBALS['user']->playlist->get_items(); // Check to see if 'clear' was passed if it was then we need to reset the basket - if ( ($_REQUEST['playlist_method'] == 'clear' || Config::get('playlist_method') == 'clear') AND Config::get('play_type') != 'xspf_player') { - $GLOBALS['user']->playlist->clear(); - } + if ( ($_REQUEST['playlist_method'] == 'clear' || Config::get('playlist_method') == 'clear') AND Config::get('play_type') != 'xspf_player') { + $GLOBALS['user']->playlist->clear(); + } break; /* This is run if we need to gather info based on a tmp playlist */ @@ -50,25 +50,25 @@ switch ($_REQUEST['action']) { $media_ids = $tmp_playlist->get_items(); break; case 'play_favorite': - $data = $GLOBALS['user']->get_favorites($_REQUEST['type']); - $media_ids = array(); - switch ($_REQUEST['type']) { + $data = $GLOBALS['user']->get_favorites($_REQUEST['type']); + $media_ids = array(); + switch ($_REQUEST['type']) { case 'artist': case 'album': - foreach ($data as $value) { - $songs = $value->get_songs(); - $media_ids = array_merge($media_ids,$songs); - } + foreach ($data as $value) { + $songs = $value->get_songs(); + $media_ids = array_merge($media_ids,$songs); + } break; case 'song': - foreach ($data as $value) { - $media_ids[] = $value->id; - } + foreach ($data as $value) { + $media_ids[] = $value->id; + } break; } // end switch on type break; case 'single_song': - $media_ids[] = array('song',scrub_in($_REQUEST['song_id'])); + $media_ids[] = array('song',scrub_in($_REQUEST['song_id'])); break; case 'your_popular_songs': $media_ids = get_popular_songs($_REQUEST['limit'], 'your', $GLOBALS['user']->id); @@ -112,25 +112,25 @@ switch ($_REQUEST['action']) { $options = array('limit' => $_REQUEST['random'], 'random_type' => $_REQUEST['random_type'],'size_limit'=>$_REQUEST['size_limit']); $media_ids = get_random_songs($options, $matchlist); break; - case 'democratic': - $democratic = new Democratic($_REQUEST['democratic_id']); - $urls = array($democratic->play_url()); + case 'democratic': + $democratic = new Democratic($_REQUEST['democratic_id']); + $urls = array($democratic->play_url()); break; - case 'download': - $media_ids[] = array('song',scrub_in($_REQUEST['song_id'])); + case 'download': + $media_ids[] = array('song',scrub_in($_REQUEST['song_id'])); default: break; } // end action switch -/* Now that we've gathered the song information we decide what +/* Now that we've gathered the song information we decide what * we should do with it, this is a sensitive time for the song id's * they don't know where they want to go.. let's help them out */ -switch ($_REQUEST['method']) { +switch ($_REQUEST['method']) { case 'download': // Run the access check and exit if they are not allowed to download - if (!Access::check_function('batch_download')) { access_denied(); exit; } + if (!Access::check_function('batch_download')) { access_denied(); exit; } // Format the zip file @@ -142,30 +142,30 @@ switch ($_REQUEST['method']) { case 'stream': default: // See if we need a special streamtype - switch ($_REQUEST['action']) { - case 'download': - $stream_type = 'download'; + switch ($_REQUEST['action']) { + case 'download': + $stream_type = 'download'; break; - case 'democratic': + case 'democratic': // Don't let them loop it - if (Config::get('play_type') == 'democratic') { - Config::set('play_type','stream','1'); + if (Config::get('play_type') == 'democratic') { + Config::set('play_type','stream','1'); } default: - if (Config::get('play_type') == 'stream') { + if (Config::get('play_type') == 'stream') { $stream_type = Config::get('playlist_type'); - } - else { - $stream_type = Config::get('play_type'); - } + } + else { + $stream_type = Config::get('play_type'); + } break; - } + } /* Start the Stream */ debug_event('stream.php' , 'Stream Type: '.$stream_type.' Media IDs: '.$media_ids, '5'); $stream = new Stream($stream_type,$media_ids); - $stream->add_urls($urls); - $stream->start(); + $stream->add_urls($urls); + $stream->start(); -} // end method switch +} // end method switch ?> diff --git a/templates/footer.inc.php b/templates/footer.inc.php index 4d63a1e3..8a0ac738 100644 --- a/templates/footer.inc.php +++ b/templates/footer.inc.php @@ -29,7 +29,7 @@ diff --git a/templates/header.inc.php b/templates/header.inc.php index 7cda0e5f..41df950c 100644 --- a/templates/header.inc.php +++ b/templates/header.inc.php @@ -48,7 +48,7 @@ if (Config::get('use_rss')) { ?> - +