1
0
Fork 0
mirror of https://github.com/Yetangitu/ampache synced 2025-10-05 19:41:55 +02:00
Conflicts:
	lib/class/ajax.class.php
	lib/general.lib.php
	themes/fresh/templates/default.css
This commit is contained in:
John Moore 2013-11-19 19:27:31 -06:00
commit f4d7b64fd0
398 changed files with 33598 additions and 4616 deletions

15
.php_cs Normal file
View file

@ -0,0 +1,15 @@
<?php
use Symfony\CS\FixerInterface;
$finder = Symfony\CS\Finder\DefaultFinder::create()
->exclude('modules')
->in(__DIR__)
->in(__DIR__ . '/modules/localplay')
->in(__DIR__ . '/modules/catalog')
->in(__DIR__ . '/modules/ampacheapi')
;
return Symfony\CS\Config\Config::create()
->finder($finder)
;

17
.travis.yml Normal file
View file

@ -0,0 +1,17 @@
language: php
php:
- 5.3
- 5.4
- 5.5
before_install:
- wget http://cs.sensiolabs.org/get/php-cs-fixer.phar
before_script:
- chmod +x scripts/tests/syntax.sh
- chmod +x scripts/tests/codestyle.sh
script:
- scripts/tests/syntax.sh
- scripts/tests/codestyle.sh

View file

@ -18,7 +18,8 @@ choosing a suitable method for doing so.
Recommended Version
-------------------
Currently, the recommended version is [git HEAD](https://github.com/ampache/ampache/archive/master.tar.gz).
Currently, the recommended version is [git HEAD](https://github.com/ampache-doped/ampache/archive/master.tar.gz).
[![Build Status](https://api.travis-ci.org/ampache-doped/ampache.png?branch=master)](https://travis-ci.org/ampache-doped/ampache)
Requirements
------------
@ -44,7 +45,7 @@ receives the most testing:
Installation
------------
Please see [the wiki](https://github.com/ampache/ampache/wiki/Installation)
Please see [the wiki](https://github.com/ampache-doped/ampache/wiki/Installation)
Upgrading
---------
@ -74,6 +75,7 @@ Ampache includes some external modules that carry their own licensing.
* [Whatever:hover](http://www.xs4all.nl/~peterned): LGPL v2.1
* [xbmc-php-rpc](https://github.com/karlrixon/xbmc-php-rpc): GPL v3
* [JPlayer](http://jplayer.org/): MIT
* [unofficial-google-music-api-php](http://code.google.com/p/unofficial-google-music-api-php/): GPL v3
Translations
------------
@ -123,8 +125,8 @@ Contact Us
Hate it? Love it? Let us know. Also let us know if you think of any
more features, encounter bugs, etc.
* [Public Repository](http://github.com/ampache)
* [Public Repository](http://github.com/ampache-doped)
* IRC: chat.freenode.net #ampache
* [Issue Tracker](https://github.com/ampache/ampache/issues)
* [Documentation](https://github.com/ampache/ampache/wiki)
* [Issue Tracker](https://github.com/ampache-doped/ampache/issues)
* [Documentation](https://github.com/ampache-doped/ampache/wiki)

View file

@ -70,8 +70,7 @@ switch ($_REQUEST['action']) {
if (!Error::occurred()) {
$url = Config::get('web_path') . '/admin/access.php';
show_confirmation(T_('Added'), T_('Your new Access Control List(s) have been created'),$url);
}
else {
} else {
$action = 'show_add_' . $_POST['type'];
require_once Config::get('prefix') . '/templates/show_add_access.inc.php';
}
@ -85,8 +84,7 @@ switch ($_REQUEST['action']) {
$access->update($_POST);
if (!Error::occurred()) {
show_confirmation(T_('Updated'), T_('Access List Entry updated'), Config::get('web_path').'/admin/access.php');
}
else {
} else {
$access->format();
require_once Config::get('prefix') . '/templates/show_edit_access.inc.php';
}
@ -110,4 +108,3 @@ switch ($_REQUEST['action']) {
break;
} // end switch on action
UI::show_footer();
?>

View file

@ -21,6 +21,7 @@
*/
require_once '../lib/init.php';
require_once Config::get('prefix') . '/modules/catalog/local.catalog.php';
if (!Access::check('interface','100')) {
UI::access_denied();
@ -45,8 +46,8 @@ switch ($_REQUEST['action']) {
if (Config::get('demo_mode')) { break; }
if ($_REQUEST['catalogs']) {
foreach ($_REQUEST['catalogs'] as $catalog_id) {
$catalog = new Catalog($catalog_id);
$catalog->add_to_catalog();
$catalog = Catalog::create_from_id($catalog_id);
$catalog->add_to_catalog($_POST);
}
}
$url = Config::get('web_path') . '/admin/catalog.php';
@ -65,7 +66,7 @@ switch ($_REQUEST['action']) {
if (isset($_REQUEST['catalogs'])) {
foreach ($_REQUEST['catalogs'] as $catalog_id) {
$catalog = new Catalog($catalog_id);
$catalog = Catalog::create_from_id($catalog_id);
$catalog->verify_catalog();
}
}
@ -87,7 +88,7 @@ switch ($_REQUEST['action']) {
/* This runs the clean/verify/add in that order */
foreach ($_REQUEST['catalogs'] as $catalog_id) {
$catalog = new Catalog($catalog_id);
$catalog = Catalog::create_from_id($catalog_id);
$catalog->clean_catalog();
$catalog->count = 0;
$catalog->verify_catalog();
@ -129,8 +130,7 @@ switch ($_REQUEST['action']) {
if (count($song)) {
$catalog->remove_songs($song);
$body = T_ngettext('Song Removed', 'Songs Removed', count($song));
}
else {
} else {
$body = T_('No Songs Removed');
}
$url = Config::get('web_path') . '/admin/catalog.php';
@ -138,7 +138,6 @@ switch ($_REQUEST['action']) {
show_confirmation($title,$body,$url);
break;
case 'clean_all_catalogs':
$catalog = new Catalog();
$_REQUEST['catalogs'] = Catalog::get_catalogs();
case 'clean_catalog':
toggle_visible('ajax-loading');
@ -149,7 +148,7 @@ switch ($_REQUEST['action']) {
// Make sure they checked something
if (isset($_REQUEST['catalogs'])) {
foreach ($_REQUEST['catalogs'] as $catalog_id) {
$catalog = new Catalog($catalog_id);
$catalog = Catalog::create_from_id($catalog_id);
$catalog->clean_catalog();
} // end foreach catalogs
Dba::optimize_tables();
@ -178,20 +177,21 @@ switch ($_REQUEST['action']) {
// 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 ($catalog_id = Catalog_local::get_from_path($_POST['add_path'])) {
$catalog = Catalog::create_from_id($catalog_id);
$catalog->add_to_catalog(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'])) {
if ($catalog_id = Catalog_local::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
echo T_("Done.");
break;
case 'add_catalog':
/* Wah Demo! */
@ -199,15 +199,12 @@ switch ($_REQUEST['action']) {
ob_end_flush();
if (!strlen($_POST['path']) || !strlen($_POST['name'])) {
Error::add('general', T_('Error: Name and path not specified'));
if (!strlen($_POST['type']) || $_POST['type'] == 'none') {
Error::add('general', T_('Error: Please select a catalog type'));
}
if (substr($_POST['path'],0,7) != 'http://' && $_POST['type'] == 'remote') {
Error::add('general', T_('Error: Remote selected, but path is not a URL'));
}
if ($POST['type'] == 'remote' AND (!strlen($POST['remote_username']) OR !strlen($POST['remote_password']))) {
Error::add('general', T_('Error: Username and Password Required for Remote Catalogs'));
if (!strlen($_POST['name'])) {
Error::add('general', T_('Error: Name not specified'));
}
if (!Core::form_verify('add_catalog','post')) {
@ -215,11 +212,6 @@ switch ($_REQUEST['action']) {
exit;
}
// Make sure that there isn't a catalog with a directory above this one
if (Catalog::get_from_path($_POST['path'])) {
Error::add('general', T_('Error: Defined Path is inside an existing catalog'));
}
// If an error hasn't occured
if (!Error::occurred()) {
@ -230,10 +222,10 @@ switch ($_REQUEST['action']) {
break;
}
$catalog = new Catalog($catalog_id);
$catalog = Catalog::create_from_id($catalog_id);
// Run our initial add
$catalog->run_add($_POST);
$catalog->add_to_catalog($_POST);
UI::show_box_top(T_('Catalog Created'), 'box box_catalog_created');
echo "<h2>" . T_('Catalog Created') . "</h2>";
@ -243,8 +235,7 @@ switch ($_REQUEST['action']) {
show_confirmation('','', Config::get('web_path').'/admin/catalog.php');
}
else {
} else {
require Config::get('prefix') . '/templates/show_add_catalog.inc.php';
}
break;
@ -275,8 +266,7 @@ switch ($_REQUEST['action']) {
$songs = Song::get_disabled();
if (count($songs)) {
require Config::get('prefix') . '/templates/show_disabled_songs.inc.php';
}
else {
} else {
echo "<div class=\"error\" align=\"center\">" . T_('No Disabled songs found') . "</div>";
}
break;
@ -284,12 +274,13 @@ switch ($_REQUEST['action']) {
/* Stop the demo hippies */
if (Config::get('demo_mode')) { UI::access_denied(); break; }
$catalog = new Catalog($_REQUEST['catalog_id']);
$catalog = Catalog::create_from_id($_REQUEST['catalog_id']);
$nexturl = Config::get('web_path') . '/admin/catalog.php?action=delete_catalog&amp;catalog_id=' . scrub_out($_REQUEST['catalog_id']);
show_confirmation(T_('Delete Catalog'), T_('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 = Catalog::create_from_id($_REQUEST['catalog_id']);
$catalog->format();
require_once Config::get('prefix') . '/templates/show_edit_catalog.inc.php';
break;
case 'gather_album_art':
@ -300,7 +291,7 @@ switch ($_REQUEST['action']) {
// Iterate throught the catalogs and gather as needed
foreach ($catalogs as $catalog_id) {
$catalog = new Catalog($catalog_id);
$catalog = Catalog::create_from_id($catalog_id);
require Config::get('prefix') . '/templates/show_gather_art.inc.php';
flush();
$catalog->gather_art();
@ -314,5 +305,3 @@ switch ($_REQUEST['action']) {
/* Show the Footer */
UI::show_footer();
?>

View file

@ -43,4 +43,3 @@ switch ($_REQUEST['action']) {
} // end switch on action
UI::show_footer();
?>

View file

@ -36,7 +36,7 @@ switch ($_REQUEST['action']) {
// This may take a while
set_time_limit(0);
$catalog = new Catalog($_REQUEST['export_catalog']);
$catalog = Catalog::create_from_id($_REQUEST['export_catalog']);
// Clear everything we've done so far
ob_end_clean();
@ -74,4 +74,3 @@ switch ($_REQUEST['action']) {
} // end switch on action
UI::show_footer();
?>

View file

@ -31,7 +31,6 @@ UI::show_header();
switch ($_REQUEST['action']) {
case 'edit_song':
$catalog = new Catalog();
$song = new Song($_REQUEST['song_id']);
$new_song = new Song();
@ -44,21 +43,19 @@ switch ($_REQUEST['action']) {
/* If no change in string take Drop down */
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) {
$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->album = $catalog->check_album(unhtmlentities($album));
$new_song->artist = $catalog->check_artist(unhtmlentities($artist));
$new_song->album = Album::check_album(unhtmlentities($album));
$new_song->artist = Artist::check_artist(unhtmlentities($artist));
/* Update this mofo, store an old copy for cleaning */
$old_song = new Song();
@ -67,8 +64,7 @@ switch ($_REQUEST['action']) {
$song->update_song($song->id,$new_song);
/* Now that it's been updated clean old junk entries */
$catalog = new Catalog();
$cleaned = $catalog->clean_single_song($old_song);
$cleaned = Catalog::clean_single_song($old_song);
/* Add a tagging record of this so we can fix the file */
if ($_REQUEST['flag']) {
@ -94,13 +90,10 @@ switch ($_REQUEST['action']) {
// 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 = Album::check_album($_REQUEST['name'],$_REQUEST['year']);
$songs = $album->get_songs();
@ -138,11 +131,10 @@ switch ($_REQUEST['action']) {
$artist = new Artist($_REQUEST['artist_id']);
// Create the needed objects, a pox on PHP4
$catalog = new Catalog();
$flag = new Flag();
/* Check the new Name */
$artist_id = $catalog->check_artist($_REQUEST['name']);
$artist_id = Artist::check_artist($_REQUEST['name']);
$songs = $artist->get_songs();
@ -168,7 +160,6 @@ switch ($_REQUEST['action']) {
/* Done by 'Select' code passes array of song ids */
case 'mass_update':
$songs = $_REQUEST['song'];
$catalog = new Catalog();
$object = $_REQUEST['update_field'];
$flag = new Flag();
@ -199,10 +190,10 @@ switch ($_REQUEST['action']) {
/* Restrict which fields can be updated */
switch ($object) {
case 'album':
$new_song->album = $catalog->check_album(unhtmlentities($_REQUEST['update_value']));
$new_song->album = Album::check_album(unhtmlentities($_REQUEST['update_value']));
break;
case 'artist':
$new_song->artist = $catalog->check_artist(unhtmlentities($_REQUEST['update_value']));
$new_song->artist = Artist::check_artist(unhtmlentities($_REQUEST['update_value']));
break;
case 'year':
$new_song->year = intval($_REQUEST['update_value']);
@ -242,8 +233,7 @@ switch ($_REQUEST['action']) {
$flag = new Flag($flag_id);
if ($_REQUEST['update_action'] == 'reject') {
$flag->delete_flag();
}
else {
} else {
$flag->approve();
}
} // end foreach flags
@ -260,8 +250,7 @@ switch ($_REQUEST['action']) {
case 'disable':
$song_obj = new Song();
// If we pass just one, make it still work
if (!is_array($_REQUEST['song_ids'])) { $song_obj->update_enabled(0,$_REQUEST['song_ids']); }
else {
if (!is_array($_REQUEST['song_ids'])) { $song_obj->update_enabled(0,$_REQUEST['song_ids']); } else {
foreach ($_REQUEST['song_ids'] as $song_id) {
$song_obj->update_enabled(0,$song_id);
} // end foreach
@ -271,8 +260,7 @@ switch ($_REQUEST['action']) {
case 'enabled':
$song_obj = new Song();
// If we pass just one, make it still work
if (!is_array($_REQUEST['song_ids'])) { $song_obj->update_enabled(1,$_REQUEST['song_ids']); }
else {
if (!is_array($_REQUEST['song_ids'])) { $song_obj->update_enabled(1,$_REQUEST['song_ids']); } else {
foreach ($_REQUEST['song_ids'] as $song_id) {
$song_obj->update_enabled(1,$song_id);
} // end foreach
@ -302,4 +290,3 @@ switch ($_REQUEST['action']) {
} // end switch
UI::show_footer();
?>

View file

@ -43,4 +43,3 @@ switch ($_REQUEST['action']) {
}
UI::show_footer();
?>

View file

@ -51,8 +51,7 @@ switch ($_REQUEST['action']) {
if ($_REQUEST['from'] == 'system') {
$mailer->set_default_sender();
}
else {
} else {
$mailer->sender = $GLOBALS['user']->email;
$mailer->sender_name = $GLOBALS['user']->fullname;
}
@ -60,8 +59,7 @@ switch ($_REQUEST['action']) {
if ($mailer->send_to_group($_REQUEST['to'])) {
$title = T_('E-mail Sent');
$body = T_('Your E-mail was successfully sent.');
}
else {
} else {
$title = T_('E-mail Not Sent');
$body = T_('Your E-mail was not sent.');
}
@ -75,6 +73,3 @@ switch ($_REQUEST['action']) {
} // end switch
UI::show_footer();
?>

View file

@ -50,6 +50,23 @@ switch ($_REQUEST['action']) {
header("Location:" . Config::get('web_path') . '/admin/modules.php?action=show_localplay');
break;
case 'install_catalog_type':
$type = scrub_in($_REQUEST['type']);
$catalog = Catalog::create_catalog_type($type);
if ($catalog == null) {
Error::add('general', T_('Install Failed, Catalog Error'));
Error::display('general');
break;
}
$catalog->install();
/* Show Confirmation */
$url = Config::get('web_path') . '/admin/modules.php?action=show_catalog_types';
$title = T_('Plugin Installed');
$body = '';
show_confirmation($title ,$body, $url);
break;
case 'confirm_uninstall_localplay':
$type = scrub_in($_REQUEST['type']);
$url = Config::get('web_path') . '/admin/modules.php?action=uninstall_localplay&amp;type=' . $type;
@ -57,6 +74,13 @@ switch ($_REQUEST['action']) {
$body = '';
show_confirmation($title,$body,$url,1);
break;
case 'confirm_uninstall_catalog_type':
$type = scrub_in($_REQUEST['type']);
$url = Config::get('web_path') . '/admin/modules.php?action=uninstall_catalog_type&amp;type=' . $type;
$title = T_('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']);
@ -69,6 +93,23 @@ switch ($_REQUEST['action']) {
$body = '';
show_confirmation($title,$body,$url);
break;
case 'uninstall_catalog_type':
$type = scrub_in($_REQUEST['type']);
$catalog = Catalog::create_catalog_type($type);
if ($catalog == null) {
Error::add('general', T_('Uninstall Failed, Catalog Error'));
Error::display('general');
break;
}
$catalog->uninstall();
/* Show Confirmation */
$url = Config::get('web_path') . '/admin/modules.php?action=show_catalog_types';
$title = T_('Plugin Deactivated');
$body = '';
show_confirmation($title, $body, $url);
break;
case 'install_plugin':
/* Verify that this plugin exists */
$plugins = Plugin::get_plugins();
@ -148,11 +189,15 @@ switch ($_REQUEST['action']) {
require_once Config::get('prefix') . '/templates/show_localplay_controllers.inc.php';
UI::show_box_bottom();
break;
case 'show_catalog_types':
$catalogs = Catalog::get_catalog_types();
UI::show_box_top(T_('Catalog Types'), 'box box_catalog_types');
require_once Config::get('prefix') . '/templates/show_catalog_types.inc.php';
UI::show_box_bottom();
break;
default:
// Rien a faire
break;
} // end switch
UI::show_footer();
?>

View file

@ -59,4 +59,3 @@ switch ($_REQUEST['action']) {
} // end switch on action
UI::show_footer();
?>

View file

@ -57,5 +57,3 @@ switch ($_REQUEST['action']) {
} // end switch
UI::show_footer();
?>

View file

@ -123,9 +123,7 @@ switch ($_REQUEST['action']) {
$_REQUEST['action'] = 'show_add_user';
break;
}
if ($access == 5){ $access = T_('Guest');}
elseif ($access == 25){ $access = T_('User');}
elseif ($access == 100){ $access = T_('Admin');}
if ($access == 5) { $access = T_('Guest');} elseif ($access == 25) { $access = T_('User');} elseif ($access == 100) { $access = T_('Admin');}
/* HINT: %1 Username, %2 Access num */
show_confirmation(T_('New User Added'),sprintf(T_('%1$s has been created with an access level of %2$s'), $username, $access), Config::get('web_path').'/admin/users.php');
@ -139,8 +137,7 @@ switch ($_REQUEST['action']) {
$client = new User($_REQUEST['user_id']);
if ($client->disable()) {
show_confirmation(T_('User Disabled'),$client->fullname . ' (' . $client->username . ')', Config::get('web_path'). '/admin/users.php');
}
else {
} else {
show_confirmation(T_('Error'), T_('Unable to Disabled last Administrator'), Config::get('web_path').'/admin/users.php');
}
break;
@ -158,8 +155,7 @@ switch ($_REQUEST['action']) {
$client = new User($_REQUEST['user_id']);
if ($client->delete()) {
show_confirmation(T_('User Deleted'), sprintf(T_('%s has been Deleted'), $client->username), Config::get('web_path'). "/admin/users.php");
}
else {
} else {
show_confirmation(T_('Delete Error'), T_("Unable to delete last Admin User"), Config::get('web_path')."/admin/users.php");
}
break;
@ -177,8 +173,7 @@ switch ($_REQUEST['action']) {
if (!isset($_REQUEST['all'])) {
$history = $working_user->get_ip_history(0,1);
}
else {
} else {
$history = $working_user->get_ip_history();
}
require Config::get('prefix') . '/templates/show_ip_history.inc.php';
@ -206,5 +201,3 @@ switch ($_REQUEST['action']) {
/* Show the footer */
UI::show_footer();
?>

View file

@ -88,14 +88,12 @@ switch ($_REQUEST['action']) {
// Build the options for our search
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'])) {
$album_name = scrub_in($_REQUEST['album_name']);
}
else {
} else {
$album_name = $album->full_name;
}
@ -177,4 +175,3 @@ switch ($_REQUEST['action']) {
} // switch on view
UI::show_footer();
?>

View file

@ -73,8 +73,7 @@ switch($_REQUEST['action']) {
} else {
$GLOBALS['error']->add_error('general', sprintf(T_('Error: \'%s\' is not a valid ID'), $artist_id));
}
}
else
} else
$GLOBALS['error']->add_error('general', sprintf(T_('Error: No such artist \'%s\''), $_REQUEST['artist']));
} else {
$GLOBALS['error']->add_error('general', T_("Error: Errenous request"));
@ -118,7 +117,6 @@ switch($_REQUEST['action']) {
/* 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'] != "")) {
@ -181,8 +179,7 @@ switch($_REQUEST['action']) {
case 'match':
case 'Match':
$match = scrub_in($_REQUEST['match']);
if ($match == "Browse" || $match == "Show_all") { $chr = ""; }
else { $chr = $match; }
if ($match == "Browse" || $match == "Show_all") { $chr = ""; } else { $chr = $match; }
/* Enclose this in the purty box! */
require Config::get('prefix') . '/templates/show_box_top.inc.php';
show_alphabet_list('artists','artists.php',$match);
@ -191,16 +188,13 @@ switch($_REQUEST['action']) {
if ($match === "Browse") {
show_artists();
}
elseif ($match === "Show_all") {
} elseif ($match === "Show_all") {
$offset_limit = 999999;
show_artists();
}
else {
} else {
if ($chr == '') {
show_artists('A');
}
else {
} else {
show_artists($chr);
}
}
@ -208,4 +202,3 @@ switch($_REQUEST['action']) {
} // end switch
UI::show_footer();
?>

View file

@ -94,4 +94,3 @@ $song_files = get_song_files($media_ids);
set_memory_limit($song_files['1']+32);
send_zip($name,$song_files['0']);
exit;
?>

View file

@ -88,7 +88,7 @@ ob_start("ob_html_strip",'1024',true);
while ($row = Dba::fetch_row($db_results)) {
$catalog = new Catalog($row['0']);
$catalog = Catalog::create_from_id($row['0']);
printf(T_('Reading: %s'), $catalog->name);
ob_flush();
echo "\n";

View file

@ -38,7 +38,7 @@ if (count($_SERVER['argv']) > 1) {
$catalogs = Catalog::get_catalogs();
foreach ($catalogs as $catalog_id) {
$catalog = new Catalog($catalog_id);
$catalog = Catalog::create_from_id($catalog_id);
$catalog->dump_album_art(array('metadata' => $meta));
}

View file

@ -63,14 +63,15 @@ if (strlen($input) > 0) { $source_encoding = trim($input); }
printf (T_('Using %s as source character set'), $source_encoding);
echo "\n";
$sql = "SELECT * FROM `catalog` WHERE `catalog_type`='local'";
$sql = "SELECT id FROM `catalog` WHERE `catalog_type`='local'";
$db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
printf(T_('Checking %s (%s)'), $row['name'], $row['path']);
$catalog = Catalog::create_from_id($row['0']);
printf(T_('Checking %s (%s)'), $catalog->name, $catalog->path);
echo "\n";
charset_directory_correct($row['path']);
charset_directory_correct($catalog->path);
} // end of the catalogs

View file

@ -48,7 +48,7 @@ $sql = "SELECT `catalog`.`id` FROM `song` INNER JOIN `catalog` ON `song`.`catalo
$db_results = Dba::read($sql);
$results = Dba::fetch_assoc($db_results);
$catalog = new Catalog($results['id']);
$catalog = Catalog::create_from_id($results['id']);
$dir_pattern = $catalog->sort_pattern;
$file_pattern = $catalog->rename_pattern;

View file

@ -55,7 +55,7 @@ $catalogs = array();
while ($r = Dba::fetch_row($db_results)) {
$catalog = new Catalog($r['0']);
$catalog = Catalog::create_from_id($r['0']);
$songs = $catalog->get_songs();
printf (T_('Starting Catalog: %s'), stripslashes($catalog->name));

View file

@ -119,4 +119,3 @@ $browse->store();
/* Show the Footer */
UI::show_footer();
?>

View file

@ -77,8 +77,7 @@ switch ($_REQUEST['action']) {
// Create the playlist
Democratic::create($_POST);
$democratic = Democratic::get_current_playlist();
}
else {
} else {
$democratic->update($_POST);
}
@ -123,5 +122,3 @@ switch ($_REQUEST['action']) {
} // end switch on action
UI::show_footer();
?>

View file

@ -58,4 +58,3 @@ switch ($action) {
} // end action switch
UI::show_footer();
?>

View file

@ -23,5 +23,3 @@
require_once 'lib/init.php';
require_once Config::get('prefix') . '/templates/show_html5_player.inc.php';
?>

View file

@ -24,5 +24,3 @@ require_once 'lib/init.php';
$iframed = true;
require_once Config::get('prefix') . '/templates/show_html5_player.inc.php';
?>

View file

@ -99,8 +99,7 @@ switch ($_GET['type']) {
$image = file_get_contents(Config::get('prefix') .
Config::get('theme_path') .
'/images/blankalbum.jpg');
}
else {
} else {
if ($_GET['thumb']) {
$thumb_data = $art->get_thumb($size);
}
@ -124,5 +123,3 @@ if ($image) {
$browser->downloadHeaders($filename, $mime, true);
echo $image;
}
?>

View file

@ -49,5 +49,3 @@ if (Config::get('refresh_limit') > 5) {
require_once Config::get('prefix') . '/templates/show_index.inc.php';
UI::show_footer();
?>

View file

@ -64,16 +64,14 @@ $charset = $_REQUEST['charset'];
if (!$htmllang) {
if ($_ENV['LANG']) {
$lang = $_ENV['LANG'];
}
else {
} else {
$lang = 'en_US';
}
if (strpos($lang, '.')) {
$langtmp = explode('.', $lang);
$htmllang = $langtmp[0];
$charset = $langtmp[1];
}
else {
} else {
$htmllang = $lang;
}
}
@ -155,5 +153,3 @@ switch ($_REQUEST['action']) {
require_once 'templates/show_install_lang.inc.php';
break;
} // end action switch
?>

View file

@ -27,21 +27,25 @@
*
* @param array $media_ids Media IDs.
*/
function get_song_files($media_ids) {
function get_song_files($media_ids)
{
$media_files = array();
foreach ($media_ids as $element) {
if (is_array($element)) {
$type = array_shift($element);
$media = new $type(array_shift($element));
}
else {
} else {
$media = new Song($element);
}
if ($media->enabled) {
$total_size += sprintf("%.2f",($media->size/1048576));
array_push($media_files, $media->file);
$media->format();
$dirname = $media->f_album_full;
if (!array_key_exists($dirname, $media_files)) {
$media_files[$dirname] = array();
}
array_push($media_files[$dirname], $media->file);
}
}
@ -57,8 +61,8 @@ function get_song_files($media_ids) {
* @param string $name name of the zip file to be created
* @param string $song_files array of full paths to songs to zip create w/ call to get_song_files
*/
function send_zip( $name, $song_files ) {
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 writable.
if (Config::get('file_zip_download') && Config::get('file_zip_path')) {
@ -66,8 +70,7 @@ function send_zip( $name, $song_files ) {
if (!is_writable(Config::get('file_zip_path'))) {
$in_memory = '1';
debug_event('Error','File Zip Path:' . Config::get('file_zip_path') . ' is not writable','1');
}
else {
} else {
$in_memory = '0';
$basedir = Config::get('file_zip_path');
}
@ -88,7 +91,9 @@ function send_zip( $name, $song_files ) {
);
$arc->set_options( $options );
$arc->add_files( $song_files );
foreach ($song_files as $dir => $files) {
$arc->add_files( $files, $dir );
}
if (count($arc->error)) {
debug_event('archive',"Error: unable to add songs",'3');
@ -103,4 +108,3 @@ function send_zip( $name, $song_files ) {
$arc->download_file();
} // send_zip
?>

View file

@ -27,8 +27,8 @@
* access based on IP and maybe something else in the future.
*
*/
class Access {
class Access
{
// Variables from DB
public $id;
public $name;
@ -44,8 +44,8 @@ class Access {
*
* Takes an ID of the access_id dealie :)
*/
public function __construct($access_id = '') {
public function __construct($access_id = '')
{
if (!$access_id) { return false; }
/* Assign id for use in get_info() */
@ -64,7 +64,8 @@ class Access {
*
* Gets the vars for $this out of the database.
*/
private function _get_info() {
private function _get_info()
{
$sql = 'SELECT * FROM `access_list` WHERE `id` = ?';
$db_results = Dba::read($sql, array($this->id));
@ -79,7 +80,8 @@ class Access {
* 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);
@ -93,7 +95,8 @@ class Access {
*
* This outputs an error if the IP range is bad.
*/
private static function _verify_range($startp, $endp) {
private static function _verify_range($startp, $endp)
{
$startn = @inet_pton($startp);
$endn = @inet_pton($endp);
@ -120,7 +123,8 @@ class Access {
* This function takes a named array as a datasource and updates the current
* access list entry.
*/
public function update($data) {
public function update($data)
{
if (!self::_verify_range($data['start'], $data['end'])) {
return false;
}
@ -147,7 +151,8 @@ class Access {
* This takes a keyed array of data and trys to insert it as a
* new ACL entry
*/
public static function create($data) {
public static function create($data)
{
if (!self::_verify_range($data['start'], $data['end'])) {
return false;
}
@ -181,7 +186,8 @@ class Access {
* This sees if the ACL that we've specified already exists in order to
* prevent duplicates. The name is ignored.
*/
public static function exists($data) {
public static function exists($data)
{
$start = inet_pton($data['start']);
$end = inet_pton($data['end']);
$type = self::validate_type($data['type']);
@ -203,7 +209,8 @@ class Access {
*
* deletes the specified access_list entry
*/
public static function delete($id) {
public static function delete($id)
{
Dba::write('DELETE FROM `access_list` WHERE `id` = ?', array($id));
}
@ -212,7 +219,8 @@ class Access {
*
* This checks if specific functionality is enabled.
*/
public static function check_function($type) {
public static function check_function($type)
{
switch ($type) {
case 'download':
return Config::get('download');
@ -238,8 +246,8 @@ class Access {
* This takes a type, ip, user, level and key and then returns whether they
* are allowed. The IP is passed as a dotted quad.
*/
public static function check_network($type, $user, $level, $ip=null) {
public static function check_network($type, $user, $level, $ip=null)
{
if (!Config::get('access_control')) {
switch ($type) {
case 'interface':
@ -281,8 +289,7 @@ class Access {
if (strlen($user) && $user != '-1') {
$sql .= " AND `user` IN(?, '-1')";
$params[] = $user;
}
else {
} else {
$sql .= " AND `user` = '-1'";
}
@ -305,8 +312,8 @@ class Access {
* 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;
}
@ -323,8 +330,7 @@ class Access {
if (Config::get('localplay_level') >= $level
|| $GLOBALS['user']->access >= 100) {
return true;
}
else {
} else {
return false;
}
break;
@ -332,8 +338,7 @@ class Access {
// Check their standard user level
if ($GLOBALS['user']->access >= $level) {
return true;
}
else {
} else {
return false;
}
break;
@ -351,7 +356,8 @@ class Access {
* This validates the specified type; it will always return a valid type,
* even if you pass in an invalid one.
*/
public static function validate_type($type) {
public static function validate_type($type)
{
switch ($type) {
case 'rpc':
case 'interface':
@ -368,7 +374,8 @@ 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);
@ -387,7 +394,8 @@ class Access {
*
* take the int level and return a named level
*/
public function get_level_name() {
public function get_level_name()
{
if ($this->level >= '75') {
return T_('All');
}
@ -407,7 +415,8 @@ class Access {
*
* Return a name for the users covered by this ACL.
*/
public function get_user_name() {
public function get_user_name()
{
if ($this->user == '-1') { return T_('All'); }
$user = new User($this->user);
@ -419,7 +428,8 @@ class Access {
*
* This function returns the pretty name for our current type.
*/
public function get_type_name() {
public function get_type_name()
{
switch ($this->type) {
case 'rpc':
return T_('API/RPC');
@ -437,4 +447,3 @@ class Access {
}
}
}
?>

View file

@ -28,16 +28,16 @@
* raz-a-ma-taz.
*
*/
class Ajax {
class Ajax
{
private static $include_override;
/**
* constructor
* This is what is called when the class is loaded
*/
public function __construct() {
public function __construct()
{
// Rien a faire
} // constructor
@ -47,14 +47,13 @@ class Ajax {
* 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');
if (in_array($source,$non_quoted)) {
$source_txt = $source;
}
else {
} else {
$source_txt = "'#$source'";
}
@ -70,7 +69,8 @@ class Ajax {
* url
* This takes a string and makes an URL
*/
public static function url($action) {
public static function url($action)
{
return Config::get('ajax_url') . $action;
}
@ -79,23 +79,21 @@ class Ajax {
* This takes the action, the source and the post (if passed) and
* generates the full ajax link
*/
public static function action($action,$source,$post='') {
public static function action($action,$source,$post='')
{
$url = self::url($action);
$non_quoted = array('document','window');
if (in_array($source,$non_quoted)) {
$source_txt = $source;
}
else {
} else {
$source_txt = "'$source'";
}
if ($post) {
$ajax_string = "ajaxPost('$url','$post',$source_txt)";
}
else {
} else {
$ajax_string = "ajaxPut('$url',$source_txt)";
}
@ -108,8 +106,8 @@ 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);
@ -136,8 +134,8 @@ class Ajax {
* This prints out the specified text as a link and sets up 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);
@ -159,8 +157,8 @@ class Ajax {
* run
* This runs the specified action no questions asked
*/
public static function run($action) {
public static function run($action)
{
echo "<script type=\"text/javascript\"><!--\n";
echo "$action";
echo "\n--></script>";
@ -172,8 +170,8 @@ class Ajax {
* This sets the including 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);
} // set_include_override
@ -183,8 +181,8 @@ class Ajax {
* This checks to see if we're AJAXin'. If we aren't then it echoes 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 (defined('AJAX_INCLUDE') && !self::$include_override) { return true; }
echo '<div id="' . scrub_out($name) . '">';
@ -195,8 +193,8 @@ 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 (defined('AJAX_INCLUDE') && !self::$include_override) { return true; }
echo "</div>";
@ -206,4 +204,3 @@ class Ajax {
} // end_container
} // end Ajax class
?>

View file

@ -28,8 +28,8 @@
* it is related to the album table in the database.
*
*/
class Album extends database_object {
class Album extends database_object
{
/* Variables from DB */
public $id;
public $name;
@ -51,8 +51,8 @@ class Album extends database_object {
* pull the album or thumb art by default or
* get any of the counts.
*/
public function __construct($id='') {
public function __construct($id='')
{
if (!$id) { return false; }
/* Get the information from the db */
@ -75,8 +75,8 @@ 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;
@ -94,7 +94,8 @@ class Album extends database_object {
*
* Cleans out unused albums
*/
public static function gc() {
public static function gc()
{
Dba::write('DELETE FROM `album` USING `album` LEFT JOIN `song` ON `song`.`album` = `album`.`id` WHERE `song`.`id` IS NULL');
}
@ -103,8 +104,8 @@ class Album extends database_object {
* This takes an array of object ids and caches all of their information
* with a single query
*/
public static function build_cache($ids,$extra=false) {
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; }
@ -152,8 +153,8 @@ 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);
}
@ -196,6 +197,8 @@ class Album extends database_object {
public static function check($name, $year = 0, $disk = 0, $mbid = null,
$readonly = false) {
if ($mbid == '') $mbid = null;
$trimmed = Catalog::trim_prefix(trim($name));
$name = $trimmed['string'];
$prefix = $trimmed['prefix'];
@ -221,8 +224,7 @@ class Album extends database_object {
if ($mbid) {
$sql .= '= ? ';
$params[] = $mbid;
}
else {
} else {
$sql .= 'IS NULL ';
}
@ -230,8 +232,7 @@ class Album extends database_object {
if ($prefix) {
$sql .= '= ?';
$params[] = $prefix;
}
else {
} else {
$sql .= 'IS NULL';
}
@ -266,13 +267,13 @@ 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();
$sql = "SELECT `id` FROM `song` WHERE `album` = ? ";
$params = array($this->id);
if ($artist) {
if (strlen($artist)) {
$sql .= "AND `artist` = ?";
$params[] = $artist;
}
@ -294,8 +295,8 @@ 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)
{
$sql = "SELECT `id` FROM `song` WHERE `album` = ? AND `title` = ?";
$db_results = Dba::read($sql, array($this->id, $title));
@ -311,8 +312,8 @@ 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 */
@ -337,8 +338,7 @@ class Album extends database_object {
$artist = scrub_out(UI::truncate($artist), Config::get('ellipse_threshold_artist'));
$this->f_artist_link = "<a href=\"$web_path/artists.php?action=show&amp;artist=" . $this->artist_id . "\" title=\"" . scrub_out($this->artist_name) . "\">" . $artist . "</a>";
$this->f_artist = $artist;
}
else {
} else {
$this->f_artist_link = "<span title=\"$this->artist_count " . T_('Artists') . "\">" . T_('Various') . "</span>";
$this->f_artist = T_('Various');
$this->f_artist_name = $this->f_artist;
@ -359,8 +359,8 @@ class Album extends database_object {
* get_random_songs
* gets a random number, and a random assortment of songs from this album
*/
function get_random_songs() {
public function get_random_songs()
{
$sql = "SELECT `id` FROM `song` WHERE `album` = ? ORDER BY RAND()";
$db_results = Dba::read($sql, array($this->id));
@ -377,8 +377,8 @@ 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'];
@ -430,7 +430,8 @@ class Album extends database_object {
*
* This returns a number of random albums.
*/
public static function get_random($count = 1, $with_art = false) {
public static function get_random($count = 1, $with_art = false)
{
$results = false;
if ($with_art) {
@ -438,8 +439,7 @@ class Album extends database_object {
"ON (`image`.`object_type` = 'album' AND " .
'`image`.`object_id` = `album`.`id`) ' .
'WHERE `image`.`id` IS NOT NULL ';
}
else {
} else {
$sql = 'SELECT `id` FROM `album` ';
}
@ -454,5 +454,3 @@ class Album extends database_object {
}
} //end of album class
?>

View file

@ -25,8 +25,8 @@
* Ampache_RSS Class
*
*/
class Ampache_RSS {
class Ampache_RSS
{
private $type;
public $data;
@ -34,8 +34,8 @@ class Ampache_RSS {
* 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);
} // constructor
@ -45,8 +45,8 @@ class Ampache_RSS {
* 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;
@ -65,8 +65,8 @@ class Ampache_RSS {
* 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' => T_('Now Playing'),
'recently_played' => T_('Recently Played'),
'latest_album' => T_('Newest Albums'),
@ -80,8 +80,8 @@ class Ampache_RSS {
* 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';
@ -91,8 +91,8 @@ class Ampache_RSS {
* 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');
@ -108,8 +108,8 @@ class Ampache_RSS {
* 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);
@ -126,8 +126,8 @@ class Ampache_RSS {
* 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();
$results = array();
@ -167,8 +167,8 @@ class Ampache_RSS {
* 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();
@ -182,8 +182,8 @@ class Ampache_RSS {
* 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('', T_('seconds ago'), T_('minutes ago'), T_('hours ago'), T_('days ago'), T_('weeks ago'), T_('months ago'), T_('years ago'));
@ -240,8 +240,8 @@ class Ampache_RSS {
* 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();
$element = array_shift($data);

View file

@ -28,8 +28,8 @@
* integrate with Ampache.
*
*/
class Api {
class Api
{
public static $version = '350001';
private static $browse = null;
@ -38,8 +38,8 @@ class Api {
* constructor
* This really isn't anything to do here, so it's private
*/
private function __construct() {
private function __construct()
{
// Rien a faire
} // constructor
@ -48,7 +48,8 @@ class Api {
* _auto_init
* Automatically called when this class is loaded.
*/
public static function _auto_init() {
public static function _auto_init()
{
if (is_null(self::$browse)) {
self::$browse = new Browse(null, false);
}
@ -61,8 +62,8 @@ class Api {
* end users--so we have to do a little extra 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; }
switch ($filter) {
@ -72,8 +73,7 @@ class Api {
$elements = explode('/',$value);
self::$browse->set_filter('add_lt',strtotime($elements['1']));
self::$browse->set_filter('add_gt',strtotime($elements['0']));
}
else {
} else {
self::$browse->set_filter('add_gt',strtotime($value));
}
break;
@ -83,8 +83,7 @@ class Api {
$elements = explode('/',$value);
self::$browse->set_filter('update_lt',strtotime($elements['1']));
self::$browse->set_filter('update_gt',strtotime($elements['0']));
}
else {
} else {
self::$browse->set_filter('update_gt',strtotime($value));
}
break;
@ -109,8 +108,8 @@ class Api {
* This is the function that handles verifying a new handshake
* Takes a timestamp, auth key, and username.
*/
public static function handshake($input) {
public static function handshake($input)
{
$timestamp = preg_replace('/[^0-9]/', '', $input['timestamp']);
$passphrase = $input['auth'];
$ip = $_SERVER['REMOTE_ADDR'];
@ -138,8 +137,7 @@ class Api {
// FIXME: Does this if/else make sense with the new ACLs?
if (!trim($username)) {
$user_id = '-1';
}
else {
} else {
$client = User::get_from_username($username);
$user_id = $client->id;
}
@ -227,8 +225,8 @@ 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');
// Check and see if we should extend the api sessions (done if valid sess is passed)
@ -250,8 +248,8 @@ class Api {
* artist objects. This function is deprecated!
* //DEPRECATED
*/
public static function artists($input) {
public static function artists($input)
{
self::$browse->reset_filters();
self::$browse->set_type('artist');
self::$browse->set_sort('name','ASC');
@ -277,8 +275,8 @@ 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 XML_Data::artists(array($uid));
@ -288,8 +286,8 @@ 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']);
$albums = $artist->get_albums();
@ -306,8 +304,8 @@ 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();
@ -323,8 +321,8 @@ class Api {
* albums
* This returns albums based on the provided search filters
*/
public static function albums($input) {
public static function albums($input)
{
self::$browse->reset_filters();
self::$browse->set_type('album');
self::$browse->set_sort('name','ASC');
@ -347,8 +345,8 @@ 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 XML_Data::albums(array($uid));
@ -358,8 +356,8 @@ 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();
@ -376,8 +374,8 @@ class Api {
* tags
* This returns the tags based on the specified filter
*/
public static function tags($input) {
public static function tags($input)
{
self::$browse->reset_filters();
self::$browse->set_type('tag');
self::$browse->set_sort('name','ASC');
@ -399,8 +397,8 @@ 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();
echo XML_Data::tags(array($uid));
@ -411,8 +409,8 @@ class Api {
* tag_artists
* This returns the artists associated 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']);
XML_Data::set_offset($input['offset']);
@ -427,8 +425,8 @@ class Api {
* tag_albums
* This returns the albums associated 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']);
XML_Data::set_offset($input['offset']);
@ -443,8 +441,8 @@ 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']);
XML_Data::set_offset($input['offset']);
@ -459,8 +457,8 @@ class Api {
* songs
* Returns songs based on the specified filter
*/
public static function songs($input) {
public static function songs($input)
{
self::$browse->reset_filters();
self::$browse->set_type('song');
self::$browse->set_sort('title','ASC');
@ -485,8 +483,8 @@ class Api {
* song
* returns a single song
*/
public static function song($input) {
public static function song($input)
{
$uid = scrub_in($input['filter']);
ob_end_clean();
@ -499,7 +497,8 @@ class Api {
*
* 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, the function needs her raw and juicy
$data = Stream_URL::parse($input['url']);
ob_end_clean();
@ -510,8 +509,8 @@ class Api {
* playlists
* This returns playlists based on the specified filter
*/
public static function playlists($input) {
public static function playlists($input)
{
self::$browse->reset_filters();
self::$browse->set_type('playlist');
self::$browse->set_sort('name','ASC');
@ -533,8 +532,8 @@ class Api {
* playlist
* This returns a single playlist
*/
public static function playlist($input) {
public static function playlist($input)
{
$uid = scrub_in($input['filter']);
ob_end_clean();
@ -546,8 +545,8 @@ 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();
@ -568,7 +567,8 @@ class Api {
* search_songs
* This searches the songs and returns... songs
*/
public static function search_songs($input) {
public static function search_songs($input)
{
$array['type'] = 'song';
$array['rule_1'] = 'anywhere';
$array['rule_1_input'] = $input['filter'];
@ -589,8 +589,8 @@ class Api {
* videos
* This returns video objects!
*/
public static function videos($input) {
public static function videos($input)
{
self::$browse->reset_filters();
self::$browse->set_type('video');
self::$browse->set_sort('title','ASC');
@ -611,8 +611,8 @@ class Api {
* video
* This returns a single video
*/
public static function video($input) {
public static function video($input)
{
$video_id = scrub_in($input['filter']);
echo XML_Data::videos(array($video_id));
@ -624,8 +624,8 @@ 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'));
$localplay->connect();
@ -651,8 +651,8 @@ 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();
$democratic->set_parent();
@ -709,4 +709,3 @@ class Api {
} // democratic
} // API class
?>

View file

@ -27,8 +27,8 @@
* This was initially in the album class, but was pulled out
* to be more general and potentially apply to albums, artists, movies etc
*/
class Art extends database_object {
class Art extends database_object
{
public $type;
public $uid; // UID of the object not ID because it's not the ART.ID
public $raw; // Raw art data
@ -44,8 +44,8 @@ class Art extends database_object {
* Art constructor, takes the UID of the object and the
* object type.
*/
public function __construct($uid, $type = 'album') {
public function __construct($uid, $type = 'album')
{
$this->type = Art::validate_type($type);
$this->uid = $uid;
@ -57,8 +57,8 @@ class Art extends database_object {
* browse all at once and storing it in the cache, this can help if the
* db connection is the slow point
*/
public static function build_cache($object_ids) {
public static function build_cache($object_ids)
{
if (!is_array($object_ids) || !count($object_ids)) { return false; }
$uidlist = '(' . implode(',', $object_ids) . ')';
$sql = "SELECT `object_type`, `object_id`, `mime`, `size` FROM `image` WHERE `object_id` IN $uidlist";
@ -77,7 +77,8 @@ class Art extends database_object {
* _auto_init
* Called on creation of the class
*/
public static function _auto_init() {
public static function _auto_init()
{
if (!isset($_SESSION['art_enabled'])) {
$_SESSION['art_enabled'] = (Config::get('bandwidth') > 25);
}
@ -88,7 +89,8 @@ class Art extends database_object {
* is_enabled
* Checks whether the user currently wants art
*/
public static function is_enabled() {
public static function is_enabled()
{
if (self::$enabled) {
return true;
}
@ -100,11 +102,11 @@ class Art extends database_object {
* set_enabled
* Changes the value of enabled
*/
public static function set_enabled($value = null) {
public static function set_enabled($value = null)
{
if (is_null($value)) {
self::$enabled = self::$enabled ? false : true;
}
else {
} else {
self::$enabled = make_bool($value);
}
@ -115,8 +117,8 @@ class Art extends database_object {
* validate_type
* This validates the type
*/
public static function validate_type($type) {
public static function validate_type($type)
{
switch ($type) {
case 'album':
case 'artist':
@ -134,8 +136,8 @@ class Art extends database_object {
* extension
* This returns the file extension for the currently loaded art
*/
public static function extension($mime) {
public static function extension($mime)
{
$data = explode("/", $mime);
$extension = $data['1'];
@ -149,7 +151,8 @@ class Art extends database_object {
* test_image
* Runs some sanity checks on the putative image
*/
public static function test_image($source) {
public static function test_image($source)
{
if (strlen($source) < 10) {
debug_event('Art', 'Invalid image passed', 1);
return false;
@ -175,8 +178,8 @@ class Art extends database_object {
* exists, if it doesn't depending on settings it will try
* to create it.
*/
public function get($raw=false) {
public function get($raw=false)
{
// Get the data either way
if (!$this->get_db()) {
return false;
@ -184,8 +187,7 @@ class Art extends database_object {
if ($raw || !$this->thumb) {
return $this->raw;
}
else {
} else {
return $this->thumb;
}
@ -198,8 +200,8 @@ class Art extends database_object {
* on if we want to resize and if there is not a thumbnail go
* ahead and try to resize
*/
public function get_db() {
public function get_db()
{
$type = Dba::escape($this->type);
$id = Dba::escape($this->uid);
@ -210,8 +212,7 @@ class Art extends database_object {
if ($results['size'] == 'original') {
$this->raw = $results['image'];
$this->raw_mime = $results['mime'];
}
else if (Config::get('resize_images') &&
} else if (Config::get('resize_images') &&
$results['size'] == '275x275') {
$this->thumb = $results['image'];
$this->raw_mime = $results['mime'];
@ -228,8 +229,7 @@ class Art extends database_object {
$this->save_thumb($data['thumb'], $data['thumb_mime'], '275x275');
$this->thumb = $data['thumb'];
$this->thumb_mime = $data['thumb_mime'];
}
else {
} else {
debug_event('Art','Unable to retrieve or generate thumbnail for ' . $type . '::' . $id,1);
}
} // if no thumb, but art and we want to resize
@ -243,8 +243,8 @@ class Art extends database_object {
* This takes the string representation of an image and inserts it into
* the database. You must also pass the mime type.
*/
public function insert($source, $mime) {
public function insert($source, $mime)
{
// Disabled in demo mode cause people suck and upload porn
if (Config::get('demo_mode')) { return false; }
@ -277,8 +277,8 @@ class Art extends database_object {
* reset
* This resets the art in the database
*/
public function reset() {
public function reset()
{
$type = Dba::escape($this->type);
$uid = Dba::escape($this->uid);
@ -291,8 +291,8 @@ class Art extends database_object {
* save_thumb
* This saves the thumbnail that we're passed
*/
public function save_thumb($source, $mime, $size) {
public function save_thumb($source, $mime, $size)
{
// Quick sanity check
if (!self::test_image($source)) {
debug_event('Art', 'Not inserting thumbnail, invalid data passed', 1);
@ -318,7 +318,8 @@ class Art extends database_object {
* Returns the specified resized image. If the requested size doesn't
* already exist, create and cache it.
*/
public function get_thumb($size) {
public function get_thumb($size)
{
$sizetext = $size['width'] . 'x' . $size['height'];
$sizetext = Dba::escape($sizetext);
$type = Dba::escape($this->type);
@ -348,8 +349,8 @@ class Art extends database_object {
* Only works on gif/jpg/png/bmp. Fails if PHP-GD isn't available
* or lacks support for the requested image type.
*/
public function generate_thumb($image,$size,$mime) {
public function generate_thumb($image,$size,$mime)
{
$data = explode("/",$mime);
$type = strtolower($data['1']);
@ -442,8 +443,8 @@ class Art extends database_object {
* ['file'] = FILENAME *** OPTIONAL ***
* ['raw'] = Actual Image data, already captured
*/
public static function get_from_source($data, $type = 'album') {
public static function get_from_source($data, $type = 'album')
{
// Already have the data, this often comes from id3tags
if (isset($data['raw'])) {
return $data['raw'];
@ -490,8 +491,7 @@ class Art extends database_object {
if ($id3['format_name'] == "WMA") {
return $id3['asf']['extended_content_description_object']['content_descriptors']['13']['data'];
}
elseif (isset($id3['id3v2']['APIC'])) {
} elseif (isset($id3['id3v2']['APIC'])) {
// Foreach in case they have more then one
foreach ($id3['id3v2']['APIC'] as $image) {
return $image['data'];
@ -507,8 +507,8 @@ class Art extends database_object {
* url
* This returns the constructed URL for the art in question
*/
public static function url($uid,$type,$sid=false) {
public static function url($uid,$type,$sid=false)
{
$sid = $sid ? scrub_out($sid) : scrub_out(session_id());
$type = self::validate_type($type);
@ -533,8 +533,7 @@ class Art extends database_object {
parent::add_to_cache('art', $key . $row['size'], $row);
if ($row['size'] == 'original') {
$mime = $row['mime'];
}
else if ($row['size'] == '275x275' && Config::get('resize_images')) {
} else if ($row['size'] == '275x275' && Config::get('resize_images')) {
$thumb_mime = $row['mime'];
}
}
@ -555,7 +554,8 @@ class Art extends database_object {
* gc
* This cleans up art that no longer has a corresponding object
*/
public static function gc() {
public static function gc()
{
// iterate over our types and delete the images
foreach (array('album', 'artist') as $type) {
$sql = "DELETE FROM `image` USING `image` LEFT JOIN `" .
@ -570,8 +570,8 @@ class Art extends database_object {
* gather
* This tries to get the art in question
*/
public function gather($options = array(), $limit = false) {
public function gather($options = array(), $limit = false)
{
// Define vars
$results = array();
@ -595,8 +595,7 @@ class Art extends database_object {
// They don't want art!
debug_event('Art', 'art_order is empty, skipping art gathering', 3);
return array();
}
elseif (!is_array($config)) {
} elseif (!is_array($config)) {
$config = array($config);
}
@ -655,7 +654,8 @@ class Art extends database_object {
* gather_db
* This function retrieves art that's already in the database
*/
public function gather_db($limit = null) {
public function gather_db($limit = null)
{
if ($this->get_db()) {
return array('db' => true);
}
@ -667,21 +667,20 @@ class Art extends database_object {
* This function retrieves art based on MusicBrainz' Advanced
* Relationships
*/
public function gather_musicbrainz($limit = 5) {
public function gather_musicbrainz($limit = 5)
{
$images = array();
$num_found = 0;
if ($this->type == 'album') {
$album = new Album($this->uid);
}
else {
} else {
return $images;
}
if ($album->mbid) {
debug_event('mbz-gatherart', "Album MBID: " . $album->mbid, '5');
}
else {
} else {
return $images;
}
@ -819,8 +818,8 @@ class Art extends database_object {
* This takes keywords and performs a search of the Amazon website
* for the art. It returns an array of found objects with mime/url keys
*/
public function gather_amazon($limit = 5, $keywords = '') {
public function gather_amazon($limit = 5, $keywords = '')
{
$images = array();
$final_results = array();
$possible_keys = array(
@ -917,14 +916,11 @@ class Art extends database_object {
// 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 {
} else {
/* Just go to the next result */
continue;
}
@ -952,8 +948,8 @@ class Art extends database_object {
* If a limit is passed or the preferred filename is found the current
* results set is returned
*/
public function gather_folder($limit = 5) {
public function gather_folder($limit = 5)
{
$media = new Album($this->uid);
$songs = $media->get_songs();
$results = array();
@ -1065,8 +1061,8 @@ class Art extends database_object {
* This looks for the art in the meta-tags of the file
* itself
*/
public function gather_tags($limit = 5) {
public function gather_tags($limit = 5)
{
// We need the filenames
$album = new Album($this->uid);
@ -1079,8 +1075,7 @@ class Art extends database_object {
$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) {
try { $id3 = $getID3->analyze($song->file); } catch (Exception $error) {
debug_event('getid3', $error->message, 1);
}
@ -1116,8 +1111,8 @@ class Art extends database_object {
* gather_google
* Raw google search to retrieve the art, not very reliable
*/
public function gather_google($limit = 5) {
public function gather_google($limit = 5)
{
$images = array();
$media = new $this->type($this->uid);
$media->format();
@ -1152,8 +1147,8 @@ class Art extends database_object {
* This returns the art from lastfm. It doesn't currently require an
* account but may in the future.
*/
public function gather_lastfm($limit, $options = false) {
public function gather_lastfm($limit, $options = false)
{
// Create the parser object
$lastfm = new LastFMSearch();
@ -1162,8 +1157,7 @@ class Art extends database_object {
if (is_array($options)) {
$artist = $options['artist'];
$album = $options['album_name'];
}
else {
} else {
$media = new Album($this->uid);
$media->format();
$artist = $media->artist_name;

View file

@ -20,8 +20,8 @@
*
*/
class Artist extends database_object {
class Artist extends database_object
{
/* Variables from DB */
public $id;
public $name;
@ -40,8 +40,8 @@ class Artist extends database_object {
* Artist class, for modifing a artist
* Takes the ID of the artist and pulls the info from the db
*/
public function __construct($id='',$catalog_init=0) {
public function __construct($id='',$catalog_init=0)
{
/* If they failed to pass in an id, just run for it */
if (!$id) { return false; }
@ -62,8 +62,8 @@ 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;
@ -81,14 +81,16 @@ class Artist extends database_object {
*
* This cleans out unused artists
*/
public static function gc() {
public static function gc()
{
Dba::write('DELETE FROM `artist` USING `artist` LEFT JOIN `song` ON `song`.`artist` = `artist`.`id` WHERE `song`.`id` IS NULL');
}
/**
* this attempts to build a cache of the data from the passed albums all in one query
*/
public static function build_cache($ids,$extra=false) {
public static function build_cache($ids,$extra=false)
{
if (!is_array($ids) OR !count($ids)) { return false; }
$idlist = '(' . implode(',', $ids) . ')';
@ -124,8 +126,8 @@ 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);
@ -143,8 +145,8 @@ class Artist extends database_object {
* gets the album ids that this artist is a part
* of
*/
public function get_albums($catalog = null) {
public function get_albums($catalog = null)
{
if ($catalog) {
$catalog_join = "LEFT JOIN `catalog` ON `catalog`.`id` = `song`.`catalog`";
$catalog_where = "AND `catalog`.`id` = '$catalog'";
@ -155,10 +157,7 @@ class Artist extends database_object {
$sql_sort = 'ORDER BY `album`.`name`,`album`.`disk`,`album`.`year`';
$sort_type = Config::get('album_sort');
if ($sort_type == 'year_asc') { $sql_sort = 'ORDER BY `album`.`year` ASC'; }
elseif ($sort_type == 'year_desc') { $sql_sort = 'ORDER BY `album`.`year` DESC'; }
elseif ($sort_type == 'name_asc') { $sql_sort = 'ORDER BY `album`.`name` ASC'; }
elseif ($sort_type == 'name_desc') { $sql_sort = 'ORDER BY `album`.`name` DESC'; }
if ($sort_type == 'year_asc') { $sql_sort = 'ORDER BY `album`.`year` ASC'; } elseif ($sort_type == 'year_desc') { $sql_sort = 'ORDER BY `album`.`year` DESC'; } elseif ($sort_type == 'name_asc') { $sql_sort = 'ORDER BY `album`.`name` ASC'; } elseif ($sort_type == 'name_desc') { $sql_sort = 'ORDER BY `album`.`name` DESC'; }
$sql = "SELECT `album`.`id` FROM album LEFT JOIN `song` ON `song`.`album`=`album`.`id` $catalog_join " .
"WHERE `song`.`artist`='$this->id' $catalog_where GROUP BY `album`.`id` $sql_sort";
@ -178,8 +177,8 @@ class Artist extends database_object {
* 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);
@ -195,8 +194,8 @@ class Artist extends database_object {
* get_random_songs
* Gets the songs from this artist in a random order
*/
public function get_random_songs() {
public function get_random_songs()
{
$results = array();
$sql = "SELECT `id` FROM `song` WHERE `artist`='$this->id' ORDER BY RAND()";
@ -214,13 +213,12 @@ 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($catalog=FALSE) {
private function _get_extra_info($catalog=FALSE)
{
// 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 {
} 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' ";
if ($catalog) {
@ -253,8 +251,8 @@ class Artist extends database_object {
* so they can be displayed in a table for example
* it changes the title into a full link.
*/
public function format() {
public function format()
{
/* Combine prefix and name, trim then add ... if needed */
$name = UI::truncate(trim($this->prefix . " " . $this->name),Config::get('ellipse_threshold_artist'));
$this->f_name = $name;
@ -295,11 +293,14 @@ class Artist extends database_object {
*
* Checks for an existing artist; if none exists, insert one.
*/
public static function check($name, $mbid = null, $readonly = false) {
public static function check($name, $mbid = null, $readonly = false)
{
$trimmed = Catalog::trim_prefix(trim($name));
$name = $trimmed['string'];
$prefix = $trimmed['prefix'];
if ($mbid == '') $mbid = null;
if (!$name) {
$name = T_('Unknown (Orphaned)');
$prefix = null;
@ -340,8 +341,7 @@ class Artist extends database_object {
$id = $id_array['null'];
$exists = true;
}
}
else {
} else {
// Pick one at random
$id = array_shift($id_array);
$exists = true;
@ -377,8 +377,8 @@ 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;
@ -410,4 +410,3 @@ class Artist extends database_object {
} // update
} // end of artist class
?>

View file

@ -26,14 +26,15 @@
* it takes over for the vauth libs, and takes some stuff out of other
* classes where it didn't belong.
*/
class Auth {
class Auth
{
/**
* Constructor
*
* This should never be called
*/
private function __construct() {
private function __construct()
{
// Rien a faire
}
@ -44,8 +45,8 @@ class Auth {
* This is the function used for the Ajax logouts, if no id is passed
* it tries to find one from the session,
*/
public static function logout($key='', $relogin = true) {
public static function logout($key='', $relogin = true)
{
// If no key is passed try to find the session id
$key = $key ? $key : session_id();
@ -53,8 +54,7 @@ class Auth {
Session::destroy($key);
if ((!$relogin) && Config::get('logout_redirect')) {
$target = Config::get('logout_redirect');
}
else {
} else {
$target = Config::get('web_path') . '/login.php';
}
@ -74,8 +74,7 @@ class Auth {
$results['rfc3514'] = '<script type="text/javascript">reloadRedirect("' . $target . '")</script>';
echo xml_from_array($results);
}
else {
} else {
/* Redirect them to the login page */
header('Location: ' . $target);
}
@ -89,7 +88,8 @@ class Auth {
* This takes a username and password and then returns the results
* based on what happens when we try to do the auth.
*/
public static function login($username, $password) {
public static function login($username, $password)
{
foreach (Config::get('auth_methods') as $method) {
$function_name = $method . '_auth';
@ -109,8 +109,8 @@ class Auth {
*
* This is the core function of our built-in authentication.
*/
private static function mysql_auth($username, $password) {
private static function mysql_auth($username, $password)
{
if (strlen($password) && strlen($username)) {
$sql = 'SELECT `password` FROM `user` WHERE `username` = ?';
$db_results = Dba::read($sql, array($username));
@ -154,7 +154,8 @@ class Auth {
* Check to make sure the pam_auth function is implemented (module is
* installed), then check the credentials.
*/
private static function pam_auth($username, $password) {
private static function pam_auth($username, $password)
{
if (!function_exists('pam_auth')) {
$results['success'] = false;
$results['error'] = 'The PAM PHP module is not installed';
@ -167,8 +168,7 @@ class Auth {
$results['success'] = true;
$results['type'] = 'pam';
$results['username'] = $username;
}
else {
} else {
$results['success'] = false;
$results['error'] = 'PAM login attempt failed';
}
@ -182,7 +182,8 @@ class Auth {
* Calls an external program compatible with mod_authnz_external
* such as pwauth.
*/
private static function external_auth($username, $password) {
private static function external_auth($username, $password)
{
$authenticator = Config::get('external_authenticator');
if (!$authenticator) {
return array(
@ -207,8 +208,7 @@ class Auth {
debug_event('external_auth', $stderr, 5);
}
fclose($pipes[2]);
}
else {
} else {
return array(
'success' => false,
'error' => 'Failed to run external authenticator'
@ -242,8 +242,8 @@ class Auth {
* * require-attribute "an attribute fetched from the LDAP
* directory matches the given value"
*/
private static function ldap_auth($username, $password) {
private static function ldap_auth($username, $password)
{
$ldap_username = Config::get('ldap_username');
$ldap_password = Config::get('ldap_password');
@ -351,7 +351,8 @@ class Auth {
* http_auth
* This auth method relies on HTTP auth from the webserver
*/
private static function http_auth($username, $password) {
private static function http_auth($username, $password)
{
if (($_SERVER['REMOTE_USER'] == $username) ||
($_SERVER['HTTP_REMOTE_USER'] == $username)) {
$results['success'] = true;
@ -359,8 +360,7 @@ class Auth {
$results['username'] = $username;
$results['name'] = $username;
$results['email'] = '';
}
else {
} else {
$results['success'] = false;
$results['error'] = 'HTTP auth login attempt failed';
}
@ -368,4 +368,3 @@ class Auth {
} // http_auth
}
?>

View file

@ -29,15 +29,15 @@
* calling the correct template for the object we are displaying
*
*/
class Browse extends Query {
class Browse extends Query
{
/**
* set_simple_browse
* This sets the current browse object to a 'simple' browse method
* which means use the base query provided and expand from there
*/
public function set_simple_browse($value) {
public function set_simple_browse($value)
{
$this->set_is_simple($value);
} // set_simple_browse
@ -46,8 +46,8 @@ class Browse extends Query {
* add_supplemental_object
* Legacy function, need to find a better way to do that
*/
public function add_supplemental_object($class, $uid) {
public function add_supplemental_object($class, $uid)
{
$_SESSION['browse']['supplemental'][$this->id][$class] = intval($uid);
return true;
@ -59,8 +59,8 @@ 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 function get_supplemental_objects() {
public function get_supplemental_objects()
{
$objects = $_SESSION['browse']['supplemental'][$this->id];
if (!is_array($objects)) { $objects = array(); }
@ -75,12 +75,11 @@ class Browse extends Query {
* and requires the correct template based on the
* type that we are currently browsing
*/
public function show_objects($object_ids = null) {
public function show_objects($object_ids = null)
{
if ($this->is_simple() || ! is_array($object_ids)) {
$object_ids = $this->get_saved();
}
else {
} else {
$this->save_objects($object_ids);
}
@ -109,12 +108,11 @@ class Browse extends Query {
// Format any matches we have so we can show them to the masses
if ($filter_value = $this->get_filter('alpha_match')) {
$match = ' (' . $filter_value . ')';
}
elseif ($filter_value = $this->get_filter('starts_with')) {
} elseif ($filter_value = $this->get_filter('starts_with')) {
$match = ' (' . $filter_value . ')';
} elseif ($filter_value = $this->get_filter('catalog')) {
// Get the catalog title
$catalog = new Catalog($filter_value);
$catalog = Catalog::create_from_id($filter_value);
$match = ' (' . $catalog->name . ')';
}
@ -223,7 +221,8 @@ class Browse extends Query {
* set_filter_from_request
* //FIXME
*/
public function set_filter_from_request($request) {
public function set_filter_from_request($request)
{
foreach ($request as $key => $value) {
//reinterpret v as a list of int
$list = explode(',', $value);
@ -238,8 +237,7 @@ class Browse extends Query {
if (sizeof($list) == 1) {
$this->set_filter($key, $list[0]);
}
}
else {
} else {
$this->set_filter($key, $list);
}
}

File diff suppressed because it is too large Load diff

View file

@ -33,12 +33,13 @@
* The class should be a static var in the other classes
*
*/
class Config {
class Config
{
private $_local = array();
private static $_global = array();
public function __construct() {
public function __construct()
{
// Rien a faire
}
@ -47,7 +48,8 @@ class Config {
*
* This returns a config value.
*/
public static function get($name) {
public static function get($name)
{
if (isset(self::$_global[$name])) {
return self::$_global[$name];
}
@ -60,7 +62,8 @@ class Config {
*
* This returns all of the current config variables as an array.
*/
public static function get_all() {
public static function get_all()
{
return self::$_global;
}
@ -69,7 +72,8 @@ class Config {
*
* This sets config values.
*/
public static function set($name, $value, $clobber = false) {
public static function set($name, $value, $clobber = false)
{
if (isset(self::$_global[$name]) && !$clobber) {
debug_event('Config', "Tried to overwrite existing key $name without setting clobber", 5);
Error::add('Config Global', sprintf(T_('Trying to clobber \'%s\' without setting clobber'), $name));
@ -85,10 +89,10 @@ 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 = false) {
public static function set_by_array($array, $clobber = false)
{
foreach ($array as $name => $value) {
self::set($name, $value, $clobber);
}
}
}
?>

View file

@ -27,14 +27,14 @@
* would be replaced by a namespace library once that exists in php
*
*/
class Core {
class Core
{
/**
* constructor
* This doesn't do anything
*/
private function __construct() {
private function __construct()
{
return false;
} // construction
@ -46,7 +46,10 @@ class Core {
* needed so that we don't use a million include statements which load
* more than we need.
*/
public static function autoload($class) {
public static function autoload($class)
{
// Ignore class with namespace, not used by Ampache
if (strpos($class, '\\') === false) {
$file = Config::get('prefix') . '/lib/class/' .
strtolower($class) . '.class.php';
@ -58,19 +61,19 @@ class Core {
if (is_callable($autocall)) {
call_user_func($autocall);
}
}
else {
} else {
debug_event('autoload', "'$class' not found!", 1);
}
}
}
/**
* form_register
* 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));
$window = Config::get('session_length');
@ -101,7 +104,8 @@ class Core {
* they don't match then it returns false and doesn't let the person
* continue
*/
public static function form_verify($name, $type = 'post') {
public static function form_verify($name, $type = 'post')
{
switch ($type) {
case 'post':
$sid = $_POST['form_validation'];
@ -147,8 +151,8 @@ class Core {
* 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; }
$image = ImageCreateFromString($image_data);
@ -170,7 +174,8 @@ class Core {
* Replacement function because PHP's is_readable is buggy:
* https://bugs.php.net/bug.php?id=49620
*/
public static function is_readable($path) {
public static function is_readable($path)
{
if (is_dir($path)) {
$handle = opendir($path);
if ($handle === false) {
@ -189,4 +194,3 @@ class Core {
}
} // Core
?>

View file

@ -28,8 +28,8 @@
* caching for all of the objects to cut down on the database calls
*
*/
abstract class database_object {
abstract class database_object
{
private static $object_cache = array();
// Statistics for debugging
@ -40,8 +40,8 @@ abstract class database_object {
* get_info
* retrieves the info from the database and puts it in the cache
*/
public function get_info($id,$table_name='') {
public function get_info($id,$table_name='')
{
$table_name = $table_name ? Dba::escape($table_name) : Dba::escape(strtolower(get_class($this)));
// Make sure we've got a real id
@ -67,7 +67,8 @@ abstract class database_object {
/**
* clear_cache
*/
public static function clear_cache() {
public static function clear_cache()
{
self::$object_cache = array();
}
@ -75,8 +76,8 @@ abstract class database_object {
* is_cached
* this checks the cache to see if the specified object is there
*/
public static function is_cached($index,$id) {
public static function is_cached($index,$id)
{
// Make sure we've got some parents here before we dive below
if (!isset(self::$object_cache[$index])) { return false; }
@ -88,8 +89,8 @@ abstract class database_object {
* get_from_cache
* This attempts to retrive the specified object from the cache we've got here
*/
public static function get_from_cache($index,$id) {
public static function get_from_cache($index,$id)
{
// Check if the object is set
if (isset(self::$object_cache[$index])
&& isset(self::$object_cache[$index][$id])
@ -107,8 +108,8 @@ abstract class database_object {
* add_to_cache
* This adds the specified object to the specified index in the cache
*/
public static function add_to_cache($index,$id,$data) {
public static function add_to_cache($index,$id,$data)
{
if (!self::$_enabled) { return false; }
$value = is_null($data) ? false : $data;
@ -121,8 +122,8 @@ abstract class database_object {
* This function clears something from the cache, there are a few places we need to do this
* in order to have things display correctly
*/
public static function remove_from_cache($index,$id) {
public static function remove_from_cache($index,$id)
{
if (isset(self::$object_cache[$index]) && isset(self::$object_cache[$index][$id])) {
unset(self::$object_cache[$index][$id]);
}
@ -133,8 +134,8 @@ abstract class database_object {
* _auto_init
* Load in the cache settings once so we can avoid function calls
*/
public static function _auto_init() {
public static function _auto_init()
{
self::$_enabled = Config::get('memory_cache');
} // _auto_init

View file

@ -34,8 +34,8 @@ if (!defined('INIT_LOADED') || INIT_LOADED != '1') { exit; }
* database simplifying queries in most cases.
*
*/
class Dba {
class Dba
{
public static $stats = array('query'=>0);
private static $_sql;
@ -46,8 +46,8 @@ class Dba {
* constructor
* This does nothing with the DBA class
*/
private function __construct() {
private function __construct()
{
// Rien a faire
} // construct
@ -55,7 +55,8 @@ class Dba {
/**
* query
*/
public static function query($sql, $params) {
public static function query($sql, $params = array())
{
// json_encode throws errors about UTF-8 cleanliness, which we don't
// care about here.
debug_event('Query', $sql . ' ' . @json_encode($params), 6);
@ -69,7 +70,8 @@ class Dba {
return $stmt;
}
private static function _query($sql, $params) {
private static function _query($sql, $params)
{
$dbh = self::dbh();
if (!$dbh) {
debug_event('Dba', 'Error: failed to get database handle', 1);
@ -80,8 +82,7 @@ class Dba {
if ($params) {
$stmt = $dbh->prepare($sql);
$stmt->execute($params);
}
else {
} else {
$stmt = $dbh->query($sql);
}
@ -93,8 +94,7 @@ class Dba {
self::$_error = json_encode($dbh->errorInfo());
debug_event('Dba', 'Error: ' . json_encode($dbh->errorInfo()), 1);
self::disconnect();
}
else if ($stmt->errorCode() && $stmt->errorCode() != '00000') {
} else if ($stmt->errorCode() && $stmt->errorCode() != '00000') {
self::$_error = json_encode($stmt->errorInfo());
debug_event('Dba', 'Error: ' . json_encode($stmt->errorInfo()), 1);
self::disconnect();
@ -107,14 +107,16 @@ class Dba {
/**
* read
*/
public static function read($sql, $params = null) {
public static function read($sql, $params = null)
{
return self::query($sql, $params);
}
/**
* write
*/
public static function write($sql, $params = null) {
public static function write($sql, $params = null)
{
return self::query($sql, $params);
}
@ -124,7 +126,8 @@ class Dba {
* This runs a escape on a variable so that it can be safely inserted
* into the sql
*/
public static function escape($var) {
public static function escape($var)
{
$var = self::dbh()->quote($var);
// This is slightly less ugly than it was, but still ugly
return substr($var, 1, -1);
@ -138,7 +141,8 @@ class Dba {
* The optional finish parameter affects whether we automatically clean
* up the result set after the last row is read.
*/
public static function fetch_assoc($resource, $finish = true) {
public static function fetch_assoc($resource, $finish = true)
{
if (!$resource) {
return array();
}
@ -163,7 +167,8 @@ class Dba {
* The optional finish parameter affects whether we automatically clean
* up the result set after the last row is read.
*/
public static function fetch_row($resource, $finish = true) {
public static function fetch_row($resource, $finish = true)
{
if (!$resource) {
return array();
}
@ -187,7 +192,8 @@ class Dba {
* just a count of rows returned by our select statement, this
* doesn't work for updates or inserts.
*/
public static function num_rows($resource) {
public static function num_rows($resource)
{
if ($resource) {
$result = $resource->rowCount();
if ($result) {
@ -203,7 +209,8 @@ class Dba {
*
* This closes a result handle and clears the memory associated with it
*/
public static function finish($resource) {
public static function finish($resource)
{
if ($resource) {
$resource->closeCursor();
}
@ -214,7 +221,8 @@ class Dba {
*
* This emulates the mysql_affected_rows function
*/
public static function affected_rows($resource) {
public static function affected_rows($resource)
{
if ($resource) {
$result = $resource->rowCount();
if ($result) {
@ -230,7 +238,8 @@ class Dba {
*
* This connects to the database, used by the DBH function
*/
private static function _connect() {
private static function _connect()
{
$username = Config::get('database_username');
$hostname = Config::get('database_hostname');
$password = Config::get('database_password');
@ -239,8 +248,7 @@ class Dba {
// Build the data source name
if (strpos($hostname, '/') === 0) {
$dsn = 'mysql:unix_socket=' . $hostname;
}
else {
} else {
$dsn = 'mysql:host=' . $hostname ?: 'localhost';
}
if ($port) {
@ -249,8 +257,7 @@ class Dba {
try {
$dbh = new PDO($dsn, $username, $password);
}
catch (PDOException $e) {
} catch (PDOException $e) {
self::$_error = $e->getMessage();
debug_event('Dba', 'Connection failed: ' . $e->getMessage(), 1);
return null;
@ -259,7 +266,8 @@ class Dba {
return $dbh;
}
private static function _setup_dbh($dbh, $database) {
private static function _setup_dbh($dbh, $database)
{
if (!$dbh) {
return false;
}
@ -287,7 +295,8 @@ class Dba {
*
* Make sure that we can connect to the database
*/
public static function check_database() {
public static function check_database()
{
$dbh = self::_connect();
if (!$dbh || $dbh->errorCode()) {
@ -306,7 +315,8 @@ class Dba {
* Checks to make sure that you have inserted the database
* and that the user you are using has access to it.
*/
public static function check_database_inserted() {
public static function check_database_inserted()
{
$sql = "DESCRIBE session";
$db_results = Dba::read($sql);
@ -327,7 +337,8 @@ class Dba {
*
* This function is used for debug, helps with profiling
*/
public static function show_profile() {
public static function show_profile()
{
if (Config::get('sql_profiling')) {
print '<br/>Profiling data: <br/>';
$res = Dba::read('SHOW PROFILES');
@ -345,7 +356,8 @@ class Dba {
* This is called by the class to return the database handle
* for the specified database, if none is found it connects
*/
public static function dbh($database='') {
public static function dbh($database='')
{
if (!$database) {
$database = Config::get('database_name');
}
@ -358,8 +370,7 @@ class Dba {
self::_setup_dbh($dbh, $database);
Config::set($handle, $dbh, true);
return $dbh;
}
else {
} else {
return Config::get($handle);
}
}
@ -369,7 +380,8 @@ class Dba {
*
* This nukes the dbh connection, this isn't used very often...
*/
public static function disconnect($database = '') {
public static function disconnect($database = '')
{
if (!$database) {
$database = Config::get('database_name');
}
@ -385,7 +397,8 @@ class Dba {
/**
* insert_id
*/
public static function insert_id() {
public static function insert_id()
{
$dbh = self::dbh();
if ($dbh) {
return $dbh->lastInsertId();
@ -397,7 +410,8 @@ class Dba {
* error
* this returns the error of the db
*/
public static function error() {
public static function error()
{
return self::$_error;
}
@ -406,7 +420,8 @@ class Dba {
*
* This translates the specified charset to a mysql charset.
*/
public static function translate_to_mysqlcharset($charset) {
public static function translate_to_mysqlcharset($charset)
{
// Translate real charset names into fancy MySQL land names
switch (strtoupper($charset)) {
case 'CP1250':
@ -462,7 +477,8 @@ class Dba {
* administrator only. This can mess up data if you switch between charsets
* that are not overlapping.
*/
public static function reset_db_charset() {
public static function reset_db_charset()
{
$translated_charset = self::translate_to_mysqlcharset(Config::get('site_charset'));
$target_charset = $translated_charset['charset'];
$target_collation = $translated_charset['collation'];
@ -508,7 +524,8 @@ class Dba {
* it in case the dba isn't doing it... which we're going to assume they
* aren't.
*/
public static function optimize_tables() {
public static function optimize_tables()
{
$sql = "SHOW TABLES";
$db_results = Dba::read($sql);
@ -521,4 +538,3 @@ class Dba {
}
}
}
?>

View file

@ -27,8 +27,8 @@
* name for voting based playback.
*
*/
class Democratic extends Tmp_Playlist {
class Democratic extends Tmp_Playlist
{
public $name;
public $cooldown;
public $level;
@ -46,8 +46,8 @@ class Democratic extends Tmp_Playlist {
* 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; }
$info = $this->get_info($id);
@ -62,8 +62,8 @@ class Democratic extends Tmp_Playlist {
* 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) || !count($ids)) { return false; }
$idlist = '(' . implode(',', $ids) . ')';
@ -87,8 +87,8 @@ class Democratic extends Tmp_Playlist {
* This function just returns true / false if the current democratic
* playlist is currently enabled / configured
*/
public function is_enabled() {
public function is_enabled()
{
if ($this->tmp_playlist) { return true; }
return false;
@ -99,8 +99,8 @@ class Democratic extends Tmp_Playlist {
* set_parent
* This returns the Tmp_Playlist for this democratic play instance
*/
public function set_parent() {
public function set_parent()
{
$demo_id = Dba::escape($this->id);
$sql = "SELECT * FROM `tmp_playlist` WHERE `session`='$demo_id'";
@ -120,8 +120,8 @@ class Democratic extends Tmp_Playlist {
* 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');
@ -142,8 +142,8 @@ class Democratic extends Tmp_Playlist {
* format
* This makes the variables all purrty so that they can be displayed
*/
public function format() {
public function format()
{
$this->f_cooldown = $this->cooldown . ' ' . T_('minutes');
$this->f_primary = $this->primary ? T_('Primary') : '';
@ -172,8 +172,8 @@ class Democratic extends Tmp_Playlist {
* This returns all of the current valid 'Democratic' Playlists
* that have been created.
*/
public static function get_playlists() {
public static function get_playlists()
{
$sql = "SELECT `id` FROM `democratic` ORDER BY `name`";
$db_results = Dba::read($sql);
@ -192,8 +192,8 @@ class Democratic extends Tmp_Playlist {
* 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');
if (!$democratic_id) {
@ -220,8 +220,8 @@ class Democratic extends Tmp_Playlist {
* Sorting is highest to lowest vote count, then by oldest to newest
* vote activity.
*/
public function get_items($limit = null) {
public function get_items($limit = null)
{
$sql = 'SELECT `tmp_playlist_data`.`object_type`, ' .
'`tmp_playlist_data`.`object_id`, ' .
'`tmp_playlist_data`.`id` ' .
@ -254,8 +254,8 @@ class Democratic extends Tmp_Playlist {
* play_url
* This returns the special play URL for democratic play, only open to ADMINs
*/
public function play_url() {
public function play_url()
{
$link = Stream::get_base_url() . 'uid=' . scrub_out($GLOBALS['user']->id) . '&demo_id=' . scrub_out($this->id);
return $link;
@ -269,8 +269,8 @@ class Democratic extends Tmp_Playlist {
* base_playlist and no items in the playlist then it returns a random
* entry from the base_playlist
*/
public function get_next_object($offset = 0) {
public function get_next_object($offset = 0)
{
// FIXME: Shouldn't this return object_type?
$offset = intval($offset);
@ -288,8 +288,7 @@ class Democratic extends Tmp_Playlist {
$base_playlist = new Playlist($this->base_playlist);
$data = $base_playlist->get_random_items(1);
return $data[0]['object_id'];
}
else {
} else {
$sql = "SELECT `id` FROM `song` WHERE `enabled`='1' ORDER BY RAND() LIMIT 1";
$db_results = Dba::read($sql);
$results = Dba::fetch_assoc($db_results);
@ -304,8 +303,8 @@ class Democratic extends Tmp_Playlist {
* 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 = 'song') {
public function get_uid_from_object_id($object_id, $object_type = 'song')
{
$object_id = Dba::escape($object_id);
$object_type = Dba::escape($object_type);
$tmp_id = Dba::escape($this->tmp_playlist);
@ -326,8 +325,8 @@ class Democratic extends Tmp_Playlist {
* This returns all of the song_ids for songs that have happened within
* the last 'cooldown' 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);
@ -344,7 +343,8 @@ class Democratic extends Tmp_Playlist {
* by this user, naturally it checks to make sure that the user hasn't
* already voted on any of these objects
*/
public function add_vote($items) {
public function add_vote($items)
{
/* Iterate through the objects if no vote, add to playlist and vote */
foreach ($items as $element) {
$type = array_shift($element);
@ -360,8 +360,8 @@ class Democratic extends Tmp_Playlist {
* has_vote
* This checks to see if the current user has already voted on this object
*/
public function has_vote($object_id, $type = 'song') {
public function has_vote($object_id, $type = 'song')
{
$tmp_id = Dba::escape($this->tmp_playlist);
$object_id = Dba::escape($object_id);
$type = Dba::escape($type);
@ -390,8 +390,8 @@ class Democratic extends Tmp_Playlist {
* _add_vote
* This takes a object id and user and actually inserts the row
*/
private function _add_vote($object_id, $object_type = 'song') {
private function _add_vote($object_id, $object_type = 'song')
{
$object_id = Dba::escape($object_id);
$tmp_playlist = Dba::escape($this->tmp_playlist);
$object_type = Dba::escape($object_type);
@ -426,8 +426,8 @@ class Democratic extends Tmp_Playlist {
* As that's what we'll have most the time, no need to check if they've got an existing
* vote for this, just remove anything that is there
*/
public function remove_vote($row_id) {
public function remove_vote($row_id)
{
$object_id = Dba::escape($row_id);
$user_id = Dba::escape($GLOBALS['user']->id);
@ -445,8 +445,8 @@ class Democratic extends Tmp_Playlist {
* 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);
$sql = "DELETE FROM `user_vote` WHERE `object_id`='$row_id'";
@ -463,14 +463,13 @@ class Democratic extends Tmp_Playlist {
* delete_from_oid
* This takes an OID and type and removes the object from the democratic playlist
*/
public function delete_from_oid($oid,$object_type) {
public function delete_from_oid($oid,$object_type)
{
$row_id = $this->get_uid_from_object_id($oid,$object_type);
if ($row_id) {
debug_event('Democratic','Removing Votes for ' . $oid . ' of type ' . $object_type,'5');
$this->delete_votes($row_id);
}
else { debug_event('Democratic','Unable to find Votes for ' . $oid . ' of type ' . $object_type,'3'); }
} else { debug_event('Democratic','Unable to find Votes for ' . $oid . ' of type ' . $object_type,'3'); }
return true;
@ -480,8 +479,8 @@ class Democratic extends Tmp_Playlist {
* delete
* This deletes a democratic playlist
*/
public static function delete($democratic_id) {
public static function delete($democratic_id)
{
$democratic_id = Dba::escape($democratic_id);
$sql = "DELETE FROM `democratic` WHERE `id`='$democratic_id'";
@ -500,8 +499,8 @@ class Democratic extends Tmp_Playlist {
* 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']);
@ -518,8 +517,8 @@ class Democratic extends Tmp_Playlist {
* 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']);
@ -550,8 +549,8 @@ class Democratic extends Tmp_Playlist {
* 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` " .
"LEFT JOIN `user_vote` ON `tmp_playlist_data`.`id`=`user_vote`.`object_id` " .
@ -568,8 +567,8 @@ class Democratic extends Tmp_Playlist {
* This is really just a wrapper function, it clears the entire playlist
* including all votes etc.
*/
public function clear() {
public function clear()
{
$tmp_id = Dba::escape($this->tmp_playlist);
/* Clear all votes then prune */
@ -592,8 +591,8 @@ class Democratic extends Tmp_Playlist {
* 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";
@ -607,8 +606,8 @@ class Democratic extends Tmp_Playlist {
* get_vote
* This returns the current count for a specific song
*/
public function get_vote($id) {
public function get_vote($id)
{
if (parent::is_cached('democratic_vote', $id)) {
return parent::get_from_cache('democratic_vote', $id);
}
@ -628,12 +627,11 @@ class Democratic extends Tmp_Playlist {
* 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);
} // get_voters
} // Democratic class
?>

View file

@ -27,8 +27,8 @@
* 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
@ -36,8 +36,8 @@ class Error {
* __constructor
* This does nothing... amazing isn't it!
*/
private function __construct() {
private function __construct()
{
// Rien a faire
} // __construct
@ -46,9 +46,8 @@ class Error {
* __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;
}
@ -60,8 +59,8 @@ class Error {
* 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;
@ -87,8 +86,8 @@ class Error {
* 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; }
return false;
@ -99,8 +98,8 @@ 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 ''; }
return Error::$errors[$name];
@ -112,8 +111,8 @@ 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 ''; }
@ -125,8 +124,8 @@ class Error {
* 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; }
// Re-insert them

View file

@ -27,8 +27,8 @@
* This handles flagging of songs, albums and artists
*
*/
class Flag extends database_object {
class Flag extends database_object
{
public $id;
public $user;
public $object_id;
@ -46,8 +46,8 @@ 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) {
@ -63,7 +63,8 @@ class Flag extends database_object {
*
* This cleans out unused flagged items
*/
public static function gc() {
public static function gc()
{
Dba::write("DELETE FROM `flagged` USING `flagged` LEFT JOIN `song` ON `song`.`id` = `flagged`.`object_id` WHERE `song`.`id` IS NULL AND `object_type` = 'song'");
}
@ -72,8 +73,8 @@ 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; }
$idlist = '(' . implode(',',$ids) . ')';
@ -92,8 +93,8 @@ 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; }
$idlist = '(' . implode(',',$ids) . ')';
@ -120,8 +121,8 @@ 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'];
@ -145,8 +146,8 @@ 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); }
$results = array();
@ -167,8 +168,8 @@ 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);
@ -187,8 +188,8 @@ 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); }
$sql = "SELECT `id` FROM `flagged` $limit_clause";
@ -210,8 +211,8 @@ 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);
@ -233,8 +234,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);
@ -260,8 +261,8 @@ 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);
@ -282,8 +283,8 @@ 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);
@ -298,8 +299,8 @@ class Flag extends database_object {
* 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':
$song = new Song($this->object_id);
@ -319,10 +320,9 @@ class Flag extends database_object {
* This prints out a userfriendly version of the current status for this flagged
* object
*/
public function print_status() {
if ($this->approved) { echo T_('Approved'); }
else { echo T_('Pending'); }
public function print_status()
{
if ($this->approved) { echo T_('Approved'); } else { echo T_('Pending'); }
} // print_status
@ -330,8 +330,8 @@ 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) {
case 'delete':
$name = T_('Delete');
@ -359,8 +359,8 @@ 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':
@ -379,8 +379,8 @@ class Flag extends database_object {
* fill_tags
* This is used by the write_tags script.
*/
public static function fill_tags( $tagWriter, $song, $type = 'comment' ) {
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) {
@ -422,5 +422,3 @@ class Flag extends database_object {
} //end of flag class
?>

View file

@ -20,8 +20,8 @@
*
*/
class Localplay {
class Localplay
{
/* Base Variables */
public $type;
@ -36,8 +36,8 @@ 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;
$this->_get_info();
@ -51,8 +51,8 @@ class Localplay {
* any failures, fatal errors will actually return something to the
* gui
*/
private function _get_info() {
private function _get_info()
{
$this->_load_player();
} // _get_info
@ -62,12 +62,11 @@ 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 {
} else {
return false;
}
@ -78,8 +77,8 @@ class Localplay {
* This makes the localplay/plugin information
* human readable
*/
public function format() {
public function format()
{
if (!is_object($this->_player)) { return false; }
$this->f_name = ucfirst($this->type);
@ -95,8 +94,8 @@ class Localplay {
* Will interface with in order to make all this magical stuf work
* all LocalPlay modules should be located in /modules/<name>/<name>.class.php
*/
private function _load_player() {
private function _load_player()
{
if (!$this->type) { return false; }
$filename = Config::get('prefix') . '/modules/localplay/' . $this->type . '.controller.php';
@ -125,8 +124,8 @@ class Localplay {
* 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);
return $name;
@ -137,8 +136,8 @@ 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');
@ -170,8 +169,8 @@ 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
@ -186,8 +185,8 @@ 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();
@ -200,8 +199,8 @@ class Localplay {
* 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();
@ -219,8 +218,8 @@ class Localplay {
* This function attempts to connect to the localplay
* player that we are using
*/
public function connect() {
public function connect()
{
if (!$this->_player->connect()) {
debug_event('localplay','Error Unable to connect, check ' . $this->type . ' controller','1');
return false;
@ -235,8 +234,8 @@ class Localplay {
* This function passes NULL and calls the play function of the player
* object
*/
public function play() {
public function play()
{
if (!$this->_player->play()) {
debug_event('localplay','Error Unable to start playback, check ' . $this->type . ' controller','1');
return false;
@ -251,8 +250,8 @@ 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()) {
debug_event('localplay','Error Unable to stop playback, check ' . $this->type . ' controller','1');
return false;
@ -265,8 +264,8 @@ class Localplay {
/**
* add
*/
public function add($object) {
public function add($object)
{
debug_event('localplay', 'Deprecated add method called: ' . json_encode($object), 5);
return false;
@ -276,8 +275,8 @@ class Localplay {
* add_url
* This directly adds an URL to the localplay module. Is more betterer.
*/
public function add_url(Stream_URL $url) {
public function add_url(Stream_URL $url)
{
if (!$this->_player->add_url($url)) {
debug_event('localplay', 'Unable to add url ' . $url . ', check ' . $this->type . ' controller', 1);
return false;
@ -292,8 +291,8 @@ class Localplay {
* 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) {
@ -309,8 +308,8 @@ class Localplay {
* This turns on the random feature of a localplay method
* It takes a 0/1 value
*/
public function random($state) {
public function random($state)
{
$data = $this->_player->random($state);
if (!$data) {
@ -326,8 +325,8 @@ 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)) {
@ -345,8 +344,8 @@ 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)) {
@ -364,8 +363,8 @@ class Localplay {
* 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);
@ -386,8 +385,8 @@ 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()) {
debug_event('localplay','Error: Unable to increase volume, check ' . $this->type . ' controller','1');
return false;
@ -402,8 +401,8 @@ 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()) {
debug_event('localplay','Error: Unable to decrese volume, check ' . $this->type . ' controller','1');
return false;
@ -418,8 +417,8 @@ 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)) {
debug_event('localplay','Error: Unable to mute volume, check ' . $this->type . ' controller','1');
return false;
@ -433,8 +432,8 @@ 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)) {
debug_event('localplay','Error: Unable to skip to next song, check ' . $this->type . ' controller','1');
return false;
@ -449,8 +448,8 @@ class Localplay {
* 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()) {
debug_event('localplay','Error: Unable to skip to next song, check ' . $this->type . ' controller','1');
return false;
@ -465,9 +464,8 @@ 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()) {
debug_event('localplay','Error: Unable to skip to previous song, check ' . $this->type . ' controller','1');
return false;
@ -482,8 +480,8 @@ class Localplay {
* This isn't a required function, it tells the daemon to pause the
* song
*/
public function pause() {
public function pause()
{
if (!$this->_player->pause()) {
debug_event('localplay','Error: Unable to pause song, check ' . $this->type . ' controller','1');
return false;
@ -497,8 +495,8 @@ 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();
return $instances;
@ -509,8 +507,8 @@ 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();
return $data['id'];
@ -521,8 +519,8 @@ 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;
@ -533,8 +531,8 @@ 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);
return $data;
@ -545,8 +543,8 @@ 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);
} // add_instance
@ -555,8 +553,8 @@ 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);
} // delete_instance
@ -565,8 +563,8 @@ 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);
} // set_active_instance
@ -576,8 +574,8 @@ 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)) {
debug_event('localplay','Error: Unable to remove songs, check ' . $this->type . ' controller','1');
return false;
@ -593,8 +591,8 @@ 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()) {
debug_event('localplay','Error: Unable to delete entire playlist, check ' . $this->type . ' controller','1');
return false;
@ -609,8 +607,8 @@ class Localplay {
* 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();
return $fields;
@ -622,8 +620,8 @@ class Localplay {
* This function returns a user friendly version
* of the current player state
*/
public function get_user_state($state) {
public function get_user_state($state)
{
switch ($state) {
case 'play':
return T_('Now Playing');
@ -646,8 +644,8 @@ 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 */
@ -666,4 +664,3 @@ class Localplay {
} // end localplay class
?>

View file

@ -26,8 +26,8 @@
* This is the abstract class for any localplay controller
*
*/
abstract class localplay_controller {
abstract class localplay_controller
{
// Required Functions
abstract public function add_url(Stream_URL $url); // Takes an array of song_ids
abstract public function delete_track($object_id); // Takes a single object_id and removes it from the playlist
@ -55,8 +55,8 @@ abstract class localplay_controller {
* 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)) {
// Stupiidly we'll just blindly add it for now
@ -76,9 +76,8 @@ abstract class localplay_controller {
* This returns the Filename for the passed object, not
* always possible
*/
public function get_file($object) {
public function get_file($object)
{
} // get_file
/**
@ -86,8 +85,8 @@ abstract class localplay_controller {
* 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();

View file

@ -26,8 +26,8 @@
* This class handles the Mail
*
*/
class Mailer {
class Mailer
{
// The message, recipient and from
public $message;
public $subject;
@ -41,8 +41,8 @@ class Mailer {
*
* This does nothing. Much like goggles.
*/
public function __construct() {
public function __construct()
{
// Eh bien.
} // Constructor
@ -52,7 +52,8 @@ class Mailer {
*
* Checks whether what we have looks like a valid address.
*/
public static function validate_address($address) {
public static function validate_address($address)
{
return PHPMailer::ValidateAddress($address);
}
@ -62,7 +63,8 @@ class Mailer {
* Does the config magic to figure out the "system" email sender and
* sets it as the sender.
*/
public function set_default_sender() {
public function set_default_sender()
{
$user = Config::get('mail_user');
if (!$user) {
$user = 'info';
@ -87,8 +89,8 @@ class Mailer {
* This returns an array of userids for people who have e-mail
* addresses based on the passed filter
*/
public static function get_users($filter) {
public static function get_users($filter)
{
switch ($filter) {
default:
case 'all':
@ -123,18 +125,16 @@ class Mailer {
* This should be run if we want to add some statistics to this e-mail,
* appends to self::$message
*/
public function add_statistics($methods) {
public function add_statistics($methods)
{
} // add_statistics
/**
* send
* This actually sends the mail, how amazing
*/
public function send($phpmailer = null) {
public function send($phpmailer = null)
{
$mailtype = Config::get('mail_type');
if ($phpmailer == null) {
@ -145,8 +145,7 @@ class Mailer {
$recipient_name = mb_encode_mimeheader($recipient_name);
}
$mail->AddAddress($this->recipient, $recipient_name);
}
else {
} else {
$mail = $phpmailer;
}
@ -206,7 +205,8 @@ class Mailer {
}
} // send
public function send_to_group($group_name) {
public function send_to_group($group_name)
{
$mail = new PHPMailer();
foreach (self::get_users($group_name) as $member) {
@ -220,4 +220,3 @@ class Mailer {
}
} // Mailer class
?>

View file

@ -26,8 +26,8 @@
* work, this lists all required functions and the expected
* input
*/
interface media {
interface media
{
/**
* format
*
@ -68,4 +68,3 @@ interface media {
public function has_flag();
} // end interface
?>

View file

@ -23,13 +23,13 @@
// A magical class filled with ponies
class memory_object {
class memory_object
{
private $_data = array();
public $properties;
public function __construct($data) {
public function __construct($data)
{
foreach ($data as $key => $value) {
if (in_array($key, $this->properties)) {
$this->_data[$key] = $value;
@ -38,14 +38,16 @@ class memory_object {
}
public function __set($name, $value) {
public function __set($name, $value)
{
if (!in_array($name, $this->properties)) {
return false;
}
$this->_data[$name] = $value;
}
public function __get($name) {
public function __get($name)
{
if (!in_array($name, $this->properties)) {
return false;
}

View file

@ -27,8 +27,8 @@
* This class handles playlists in ampache. it references the playlist* tables
*
*/
class Playlist extends playlist_object {
class Playlist extends playlist_object
{
/* Variables from the database */
public $genre;
public $date;
@ -41,8 +41,8 @@ class Playlist extends playlist_object {
* 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
*/
public function __construct($id) {
public function __construct($id)
{
$info = $this->get_info($id);
foreach ($info as $key=>$value) {
@ -56,7 +56,8 @@ class Playlist extends playlist_object {
*
* Clean dead items out of playlists
*/
public static function gc() {
public static function gc()
{
Dba::write("DELETE FROM `playlist_data` USING `playlist_data` LEFT JOIN `song` ON `song`.`id` = `playlist_data`.`object_id` WHERE `song`.`file` IS NULL AND `playlist_data`.`object_type`='song'");
}
@ -64,8 +65,8 @@ class Playlist extends playlist_object {
* build_cache
* This is what builds the cache from the objects
*/
public static function build_cache($ids) {
public static function build_cache($ids)
{
if (!count($ids)) { return false; }
$idlist = '(' . implode(',',$ids) . ')';
@ -83,7 +84,8 @@ class Playlist extends playlist_object {
* get_playlists
* Returns a list of playlists accessible by the current user.
*/
public static function get_playlists() {
public static function get_playlists()
{
$sql = "SELECT `id` from `playlist` WHERE `type`='public' OR " .
"`user`='" . $GLOBALS['user']->id . "' ORDER BY `name`";
$db_results = Dba::read($sql);
@ -102,7 +104,8 @@ class Playlist extends playlist_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()
{
parent::format();
$this->f_link = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&amp;playlist_id=' . $this->id . '">' . $this->f_name . '</a>';
@ -113,8 +116,8 @@ class Playlist extends playlist_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)
{
$sql = "SELECT * FROM `playlist_data` WHERE `id` = ? AND `playlist` = ?";
$db_results = Dba::read($sql, array($track_id, $playlist_id));
@ -130,8 +133,8 @@ class Playlist extends playlist_object {
* Because the same song can be on the same playlist twice they are
* keyed by the uid from playlist_data
*/
public function get_items() {
public function get_items()
{
$results = array();
$sql = "SELECT `id`,`object_id`,`object_type`,`track` FROM `playlist_data` WHERE `playlist`= ? ORDER BY `track`";
@ -154,8 +157,8 @@ class Playlist extends playlist_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();
$limit_sql = $limit ? 'LIMIT ' . intval($limit) : '';
@ -181,8 +184,8 @@ class Playlist extends playlist_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() {
public function get_songs()
{
$results = array();
$sql = "SELECT * FROM `playlist_data` WHERE `playlist` = ? ORDER BY `track`";
@ -192,8 +195,7 @@ class Playlist extends playlist_object {
if ($r['dyn_song']) {
$array = $this->get_dyn_songs($r['dyn_song']);
$results = array_merge($array,$results);
}
else {
} else {
$results[] = $r['object_id'];
}
@ -208,8 +210,8 @@ class Playlist extends playlist_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` = ?";
$db_results = Dba::read($sql, array($this->id));
@ -223,8 +225,8 @@ class Playlist extends playlist_object {
* get_total_duration
* Get the total duration of all songs.
*/
public function get_total_duration() {
public function get_total_duration()
{
$songs = self::get_songs();
$idlist = '(' . implode(',', $songs) . ')';
@ -242,8 +244,8 @@ class Playlist extends playlist_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)
{
$results = array();
$sql = "SELECT `id` FROM `playlist` WHERE `user` = ? ORDER BY `name`";
@ -261,8 +263,8 @@ class Playlist extends playlist_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']);
}
@ -276,8 +278,8 @@ class Playlist extends playlist_object {
* update_type
* 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')) {
$this->type = $new_type;
}
@ -288,8 +290,8 @@ class Playlist extends playlist_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')) {
$this->name = $new_name;
}
@ -300,8 +302,8 @@ class Playlist extends playlist_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;
}
@ -317,8 +319,8 @@ class Playlist extends playlist_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)
{
$sql = "UPDATE `playlist_data` SET `track` = ? WHERE `id` = ? AND `playlist` = ?";
$db_results = Dba::write($sql, array($track, $track_id, $this->id));
@ -330,8 +332,8 @@ class Playlist extends playlist_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
* $song->track add one to make sure it really is 'next'
@ -349,8 +351,7 @@ class Playlist extends playlist_object {
// Based on the ordered prop we use track + base or just $i++
if (!$ordered) {
$track = $song->track + $base_track;
}
else {
} else {
$i++;
$track = $base_track + $i;
}
@ -371,8 +372,8 @@ class Playlist extends playlist_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)
{
$sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`date`) VALUES (?, ?, ?, ?)";
$db_results = Dba::write($sql, array($name, $GLOBALS['user']->id, $type, time()));
@ -386,8 +387,8 @@ class Playlist extends playlist_object {
* set_items
* This calls the get_items function and sets it to $this->items which is an array in this object
*/
function set_items() {
public function set_items()
{
$this->items = $this->get_items();
} // set_items
@ -398,8 +399,8 @@ class Playlist extends playlist_object {
* and numbers them in a liner fashion, not allowing for
* the same track # twice, this is an optional function
*/
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` = ? ORDER BY `track` ASC";
$db_results = Dba::read($sql, array($this->id));
@ -428,8 +429,8 @@ class Playlist extends playlist_object {
* delete_track
* this deletes a single track, you specify the playlist_data.id here
*/
public function delete_track($id) {
public function delete_track($id)
{
$sql = "DELETE FROM `playlist_data` WHERE `playlist_data`.`playlist` = ? AND `playlist_data`.`id` = ? LIMIT 1";
$db_results = Dba::write($sql, array($this->id, $id));
@ -441,8 +442,8 @@ class Playlist extends playlist_object {
* delete_track_number
* this deletes a single track by it's track #, you specify the playlist_data.track here
*/
public function delete_track_number($track) {
public function delete_track_number($track)
{
$sql = "DELETE FROM `playlist_data` WHERE `playlist_data`.`playlist` = ? AND `playlist_data`.`track` = ? LIMIT 1";
$db_results = Dba::write($sql, array($this->id, $track));
@ -454,8 +455,8 @@ class Playlist extends playlist_object {
* delete
* This deletes the current playlist and all associated data
*/
public function delete() {
public function delete()
{
$sql = "DELETE FROM `playlist_data` WHERE `playlist` = ?";
$db_results = Dba::write($sql, array($this->id));

View file

@ -24,8 +24,8 @@
* playlist_object
* Abstracting out functionality needed by both normal and smart playlists
*/
abstract class playlist_object extends database_object {
abstract class playlist_object extends database_object
{
// Database variables
public $id;
public $name;
@ -37,8 +37,8 @@ abstract class playlist_object 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 = UI::truncate($this->name,Config::get('ellipse_threshold_title'));
$this->f_type = ($this->type == 'private') ? UI::get_icon('lock', T_('Private')) : '';
@ -53,15 +53,14 @@ abstract class playlist_object 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;
}
else {
} else {
return Access::check('interface','100');
}

View file

@ -20,8 +20,8 @@
*
*/
class Plugin {
class Plugin
{
/* Base Variables */
public $name;
@ -33,8 +33,8 @@ class Plugin {
* 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;
@ -50,8 +50,8 @@ 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';
@ -71,8 +71,8 @@ class Plugin {
* get_plugins
* This returns an array of plugin names
*/
public static function get_plugins($type='') {
public static function get_plugins($type='')
{
$results = array();
// Open up the plugin dir
@ -122,8 +122,8 @@ class Plugin {
* also check that Ampache's database version falls within the min/max
* version specified by the plugin.
*/
function is_valid() {
public function is_valid()
{
/* Check the plugin to make sure it's got the needed vars */
if (!strlen($this->_plugin->name)) {
return false;
@ -169,8 +169,8 @@ 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);
@ -181,7 +181,8 @@ class Plugin {
* This runs the install function of the plugin and inserts a row into
* the update_info table to indicate that it's installed.
*/
public function install() {
public function install()
{
if ($this->_plugin->install() &&
$this->set_plugin_version($this->_plugin->version)) {
return true;
@ -195,8 +196,8 @@ class Plugin {
* This runs the uninstall function of the plugin and 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->remove_plugin_version();
@ -208,7 +209,8 @@ class Plugin {
* This runs the upgrade function of the plugin (if it exists) and
* updates the database to indicate our new version.
*/
public function upgrade() {
public function upgrade()
{
if (method_exists($this->_plugin, 'upgrade')) {
if ($this->_plugin->upgrade()) {
$this->set_plugin_version($this->_plugin->version);
@ -220,7 +222,8 @@ class Plugin {
* load
* This calls the plugin's load function
*/
public function load() {
public function load()
{
$GLOBALS['user']->set_preferences();
return $this->_plugin->load();
}
@ -229,8 +232,8 @@ 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);
$sql = "SELECT * FROM `update_info` WHERE `key`='$name'";
@ -248,8 +251,8 @@ class Plugin {
* get_ampache_db_version
* This function returns the Ampache database version
*/
function get_ampache_db_version() {
public function get_ampache_db_version()
{
$sql = "SELECT * FROM `update_info` WHERE `key`='db_version'";
$db_results = Dba::read($sql);
@ -263,8 +266,8 @@ 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);
@ -279,8 +282,8 @@ class Plugin {
* remove_plugin_version
* This removes the version row from the db done on uninstall
*/
public function remove_plugin_version() {
public function remove_plugin_version()
{
$name = Dba::escape('Plugin_' . $this->_plugin->name);
$sql = "DELETE FROM `update_info` WHERE `key`='$name'";
@ -291,4 +294,3 @@ class Plugin {
} // remove_plugin_version
} //end plugin class
?>

View file

@ -27,14 +27,14 @@
* This handles all of the preference stuff for Ampache
*
*/
class Preference {
class Preference
{
/**
* __constructor
* This does nothing... amazing isn't it!
*/
private function __construct() {
private function __construct()
{
// Rien a faire
} // __construct
@ -43,21 +43,19 @@ class Preference {
* update
* This updates a single preference from the given name or id
*/
public static function update($preference,$user_id,$value,$applytoall='') {
public static function update($preference,$user_id,$value,$applytoall='')
{
// First prepare
if (!is_numeric($preference)) {
$id = self::id_from_name($preference);
$name = $preference;
}
else {
} else {
$name = self::name_from_id($preference);
$id = $preference;
}
if ($applytoall AND Access::check('interface','100')) {
$user_check = "";
}
else {
} else {
$user_check = " AND `user`='$user_id'";
}
@ -70,8 +68,7 @@ class Preference {
$db_results = Dba::write($sql);
Preference::clear_from_session();
return true;
}
else {
} else {
debug_event('denied',$GLOBALS['user']->username . ' attempted to update ' . $name . ' but does not have sufficient permissions','3');
}
@ -82,13 +79,12 @@ class Preference {
* 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)) {
$preference_id = self::id_from_name($preference);
}
else {
} else {
$preference_id = $preference;
}
@ -106,8 +102,8 @@ 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);
@ -122,8 +118,8 @@ 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'";
@ -138,8 +134,8 @@ 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; }
@ -161,8 +157,8 @@ 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);
$sql = "SELECT `id` FROM `preference` WHERE `name`='$name'";
@ -179,8 +175,8 @@ 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);
$sql = "SELECT `name` FROM `preference` WHERE `id`='$id'";
@ -197,8 +193,8 @@ 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);
@ -218,8 +214,8 @@ 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);
if ($user_id != '-1') {
@ -247,8 +243,8 @@ class Preference {
* 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);
@ -271,14 +267,13 @@ 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'";
}
else {
} else {
$id = Dba::escape($preference);
$sql = "DELETE FROM `preference` WHERE `id`='$id'";
}
@ -293,7 +288,8 @@ class Preference {
* rename
* This renames a preference in the database
*/
public static function rename($old, $new) {
public static function rename($old, $new)
{
$old = Dba::escape($old);
$new = Dba::escape($new);
@ -305,8 +301,8 @@ 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";
@ -323,7 +319,8 @@ class Preference {
* This takes the preferences, explodes what needs to
* become an array and boolean everythings
*/
public static function fix_preferences($results) {
public static function fix_preferences($results)
{
$arrays = array('auth_methods', 'getid3_tag_order',
'metadata_order', 'art_order', 'amazon_base_urls');
@ -348,8 +345,8 @@ 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'], true);
return true;
@ -364,8 +361,8 @@ 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']);
} // clear_from_session
@ -376,8 +373,8 @@ 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',
'downsample_remote','track_user_ip',
@ -405,8 +402,8 @@ 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';
// First go ahead and try to load it from the preferences

View file

@ -28,8 +28,8 @@
* for newsearch, and they should be merged if possible.
*
*/
class Query {
class Query
{
public $id;
public $catalog;
@ -43,7 +43,8 @@ class Query {
* constructor
* This should be called
*/
public function __construct($id = null, $cached = true) {
public function __construct($id = null, $cached = true)
{
$sid = session_id();
if (is_null($id)) {
@ -56,8 +57,7 @@ class Query {
$db_results = Dba::write($sql, array($sid, $data));
$this->id = Dba::insert_id();
}
else {
} else {
$this->id = 'nocache';
}
return true;
@ -84,7 +84,8 @@ class Query {
* Automatically called when the class is loaded.
* Populate static arrays if necessary
*/
public static function _auto_init() {
public static function _auto_init()
{
if (is_array(self::$allowed_filters)) {
return true;
}
@ -218,7 +219,8 @@ class Query {
* gc
* This cleans old data out of the table
*/
public static function gc() {
public static function gc()
{
$sql = 'DELETE FROM `tmp_browse` USING `tmp_browse` LEFT JOIN ' .
'`session` ON `session`.`id` = `tmp_browse`.`sid` ' .
'WHERE `session`.`id` IS NULL';
@ -231,7 +233,8 @@ class Query {
* Attempts to produce a more compact representation for large result
* sets by collapsing ranges.
*/
private static function _serialize($data) {
private static function _serialize($data)
{
if (count($data) > 1000) {
$last = -17;
$in_range = false;
@ -241,13 +244,11 @@ class Query {
if ($id == ($last + 1)) {
if ($in_range) {
$cooked[$idx][1] = $id;
}
else {
} else {
$in_range = true;
$cooked[$idx] = array($last, $id);
}
}
else {
} else {
$in_range = false;
$idx++;
$cooked[$idx] = $id;
@ -256,8 +257,7 @@ class Query {
}
$data = json_encode($cooked);
debug_event('Query', 'cooked serialize length: ' . strlen($data), 5);
}
else {
} else {
$data = json_encode($data);
}
@ -269,7 +269,8 @@ class Query {
*
* Reverses serialization.
*/
private static function _unserialize($data) {
private static function _unserialize($data)
{
$raw = array();
$cooked = json_decode($data);
foreach ($cooked as $grain) {
@ -277,8 +278,7 @@ class Query {
foreach (range($grain[0], $grain[1]) as $id) {
$raw[] = $id;
}
}
else {
} else {
$raw[] = $grain;
}
}
@ -289,17 +289,15 @@ class Query {
* set_filter
* This saves the filter data we pass it.
*/
public function set_filter($key, $value) {
public function set_filter($key, $value)
{
switch ($key) {
case 'tag':
if (is_array($value)) {
$this->_state['filter'][$key] = $value;
}
elseif (is_numeric($value)) {
} elseif (is_numeric($value)) {
$this->_state['filter'][$key] = array($value);
}
else {
} else {
$this->_state['filter'][$key] = array();
}
break;
@ -327,8 +325,7 @@ class Query {
break;
case 'playlist_type':
// Must be a content manager to turn this off
if ($this->_state['filter'][$key] AND Access::check('interface','50')) { unset($this->_state['filter'][$key]); }
else { $this->_state['filter'][$key] = '1'; }
if ($this->_state['filter'][$key] AND Access::check('interface','50')) { unset($this->_state['filter'][$key]); } else { $this->_state['filter'][$key] = '1'; }
break;
default:
// Rien a faire
@ -349,8 +346,8 @@ class Query {
* Reset everything, this should only be called when we are starting
* fresh
*/
public function reset() {
public function reset()
{
$this->reset_base();
$this->reset_filters();
$this->reset_total();
@ -368,8 +365,8 @@ class Query {
* reset_base
* this resets the base string
*/
public function reset_base() {
public function reset_base()
{
$this->_state['base'] = NULL;
} // reset_base
@ -378,8 +375,8 @@ class Query {
* reset_select
* This resets the select fields that we've added so far
*/
public function reset_select() {
public function reset_select()
{
$this->_state['select'] = array();
} // reset_select
@ -388,8 +385,8 @@ class Query {
* reset_having
* Null out the having clause
*/
public function reset_having() {
public function reset_having()
{
unset($this->_state['having']);
} // reset_having
@ -398,8 +395,8 @@ class Query {
* reset_join
* clears the joins if there are any
*/
public function reset_join() {
public function reset_join()
{
unset($this->_state['join']);
} // reset_join
@ -408,8 +405,8 @@ class Query {
* reset_filter
* This is a wrapper function that resets the filters
*/
public function reset_filters() {
public function reset_filters()
{
$this->_state['filter'] = array();
} // reset_filters
@ -418,8 +415,8 @@ class Query {
* reset_total
* This resets the total for the browse type
*/
public function reset_total() {
public function reset_total()
{
unset($this->_state['total']);
} // reset_total
@ -428,8 +425,8 @@ class Query {
* get_filter
* returns the specified filter value
*/
public function get_filter($key) {
public function get_filter($key)
{
// Simple enough, but if we ever move this crap
// If we ever move this crap what?
return isset($this->_state['filter'][$key])
@ -442,8 +439,8 @@ class Query {
* get_start
* This returns the current value of the start
*/
public function get_start() {
public function get_start()
{
return $this->_state['start'];
} // get_start
@ -452,7 +449,8 @@ class Query {
* get_offset
* This returns the current offset
*/
public function get_offset() {
public function get_offset()
{
if ($this->is_static_content()) {
return $this->get_total();
}
@ -464,7 +462,8 @@ class Query {
* set_total
* This sets the total number of objects
*/
public function set_total($total) {
public function set_total($total)
{
$this->_state['total'] = $total;
}
@ -474,8 +473,8 @@ class Query {
* If it's already cached used it. if they pass us an array then use
* that.
*/
public function get_total($objects = null) {
public function get_total($objects = null)
{
// If they pass something then just return that
if (is_array($objects) and !$this->is_simple()) {
return count($objects);
@ -501,7 +500,8 @@ class Query {
* object we are working with, this is used to display the 'filter'
* sidebar stuff.
*/
public static function get_allowed_filters($type) {
public static function get_allowed_filters($type)
{
return isset(self::$allowed_filters[$type])
? self::$allowed_filters[$type]
: array();
@ -513,8 +513,8 @@ class Query {
* we do this here so we only have to maintain a single whitelist
* and if I want to change the location I only have to do it here
*/
public function set_type($type) {
public function set_type($type)
{
switch ($type) {
case 'user':
case 'video':
@ -545,8 +545,8 @@ class Query {
* get_type
* This returns the type of the browse we currently are using
*/
public function get_type() {
public function get_type()
{
return $this->_state['type'];
} // get_type
@ -555,8 +555,8 @@ class Query {
* set_sort
* This sets the current sort(s)
*/
public function set_sort($sort,$order='') {
public function set_sort($sort,$order='')
{
// If it's not in our list, smeg off!
if (!in_array($sort, self::$allowed_sorts[$this->get_type()])) {
return false;
@ -566,13 +566,11 @@ class Query {
$order = ($order == 'DESC') ? 'DESC' : 'ASC';
$this->_state['sort'] = array();
$this->_state['sort'][$sort] = $order;
}
elseif ($this->_state['sort'][$sort] == 'DESC') {
} elseif ($this->_state['sort'][$sort] == 'DESC') {
// Reset it till I can figure out how to interface the hotness
$this->_state['sort'] = array();
$this->_state['sort'][$sort] = 'ASC';
}
else {
} else {
// Reset it till I can figure out how to interface the hotness
$this->_state['sort'] = array();
$this->_state['sort'][$sort] = 'DESC';
@ -586,13 +584,14 @@ class Query {
* set_offset
* This sets the current offset of this query
*/
public function set_offset($offset) {
public function set_offset($offset)
{
$this->_state['offset'] = abs($offset);
} // set_offset
public function set_catalog( $catalog_number ) {
public function set_catalog( $catalog_number )
{
$this->catalog = $catalog_number;
debug_event("Catalog", "set catalog id: " . $this->catalog, "5");
}
@ -603,8 +602,8 @@ class Query {
* statement, we're going to move to the %%SELECT%% style queries, as I
* think it's the only way to do this...
*/
public function set_select($field) {
public function set_select($field)
{
$this->_state['select'][] = $field;
} // set_select
@ -613,8 +612,8 @@ class Query {
* set_join
* This sets the joins for the current browse object
*/
public function set_join($type, $table, $source, $dest, $priority) {
public function set_join($type, $table, $source, $dest, $priority)
{
$this->_state['join'][$priority][$table] = strtoupper($type) . ' JOIN ' . $table . ' ON ' . $source . '=' . $dest;
} // set_join
@ -624,8 +623,8 @@ class Query {
* This sets the "HAVING" part of the query, we can only have one..
* god this is ugly
*/
public function set_having($condition) {
public function set_having($condition)
{
$this->_state['having'] = $condition;
} // set_having
@ -636,9 +635,8 @@ class Query {
* We need to store this in the session so that it can be pulled
* back, if they hit the back button
*/
public function set_start($start) {
public function set_start($start)
{
$start = intval($start);
if (!$this->is_static_content()) {
@ -652,8 +650,8 @@ class Query {
* This sets the current browse object to a 'simple' browse method
* which means use the base query provided and expand from there
*/
public function set_is_simple($value) {
public function set_is_simple($value)
{
$value = make_bool($value);
$this->_state['simple'] = $value;
@ -665,8 +663,8 @@ class Query {
* should be static, if they are then content filtering/altering
* methods will be skipped
*/
public function set_static_content($value) {
public function set_static_content($value)
{
$value = make_bool($value);
// We want to start at 0 if it's static
@ -678,7 +676,8 @@ class Query {
} // set_static_content
public function is_static_content() {
public function is_static_content()
{
return $this->_state['static'];
}
@ -686,8 +685,8 @@ class Query {
* is_simple
* This returns whether or not the current browse type is set to static.
*/
public function is_simple() {
public function is_simple()
{
return $this->_state['simple'];
} // is_simple
@ -697,8 +696,8 @@ class Query {
* This looks in the session for the saved stuff and returns what it
* finds.
*/
public function get_saved() {
public function get_saved()
{
// See if we have it in the local cache first
if (is_array($this->_cache)) {
return $this->_cache;
@ -713,8 +712,7 @@ class Query {
$this->_cache = self::_unserialize($row['object_data']);
return $this->_cache;
}
else {
} else {
$objects = $this->get_objects();
}
@ -728,8 +726,8 @@ class Query {
* currently browsing by it applies the sql and logic based
* filters
*/
public function get_objects() {
public function get_objects()
{
// First we need to get the SQL statement we are going to run
// This has to run against any possible filters (dependent on type)
$sql = $this->get_sql(true);
@ -760,8 +758,8 @@ class Query {
* set_base_sql
* This saves the base sql statement we are going to use.
*/
private function set_base_sql($force = false) {
private function set_base_sql($force = false)
{
// Only allow it to be set once
if (strlen($this->_state['base']) && !$force) { return true; }
@ -828,8 +826,8 @@ class Query {
* This returns the selects in a format that is friendly for a sql
* statement.
*/
private function get_select() {
private function get_select()
{
$select_string = implode($this->_state['select'], ", ");
return $select_string;
@ -840,8 +838,8 @@ class Query {
* This returns the base sql statement all parsed up, this should be
* called after all set operations.
*/
private function get_base_sql() {
private function get_base_sql()
{
$sql = str_replace("%%SELECT%%", $this->get_select(), $this->_state['base']);
return $sql;
@ -851,8 +849,8 @@ class Query {
* get_filter_sql
* This returns the filter part of the sql statement
*/
private function get_filter_sql() {
private function get_filter_sql()
{
if (!is_array($this->_state['filter'])) {
return '';
}
@ -875,8 +873,8 @@ class Query {
* get_sort_sql
* Returns the sort sql part
*/
private function get_sort_sql() {
private function get_sort_sql()
{
if (!is_array($this->_state['sort'])) {
return '';
}
@ -899,8 +897,8 @@ class Query {
* get_limit_sql
* This returns the limit part of the sql statement
*/
private function get_limit_sql() {
private function get_limit_sql()
{
if (!$this->is_simple()) { return ''; }
$sql = ' LIMIT ' . intval($this->get_start()) . ',' . intval($this->get_offset());
@ -913,8 +911,8 @@ class Query {
* get_join_sql
* This returns the joins that this browse may need to work correctly
*/
private function get_join_sql() {
private function get_join_sql()
{
if (!is_array($this->_state['join'])) {
return '';
}
@ -935,8 +933,8 @@ class Query {
* get_having_sql
* this returns the having sql stuff, if we've got anything
*/
public function get_having_sql() {
public function get_having_sql()
{
$sql = $this->_state['having'];
return $sql;
@ -949,8 +947,8 @@ class Query {
* every time we get the objects because it depends on the filters and
* the type of object we are currently browsing.
*/
public function get_sql($limit = true) {
public function get_sql($limit = true)
{
$sql = $this->get_base_sql();
$filter_sql = $this->get_filter_sql();
@ -974,8 +972,8 @@ class Query {
* This does some additional work on the results that we've received
* before returning them.
*/
private function post_process($data) {
private function post_process($data)
{
$tags = $this->_state['filter']['tag'];
if (!is_array($tags) || sizeof($tags) < 2) {
@ -1007,8 +1005,8 @@ class Query {
* to filter by this name on this type returns the appropriate sql
* if not returns nothing
*/
private function sql_filter($filter, $value) {
private function sql_filter($filter, $value)
{
$filter_sql = '';
switch ($this->get_type()) {
@ -1242,8 +1240,8 @@ class Query {
* these should be limited as they are often intensive and
* require additional queries per object... :(
*/
private function logic_filter($object_id) {
private function logic_filter($object_id)
{
return true;
} // logic_filter
@ -1255,8 +1253,8 @@ class Query {
* a logic based sort that will come later as that's
* a lot more complicated
*/
private function sql_sort($field, $order) {
private function sql_sort($field, $order)
{
if ($order != 'DESC') { $order == 'ASC'; }
// Depending on the type of browsing we are doing we can apply
@ -1406,15 +1404,14 @@ class Query {
* sort method and then re-sorts them This is internally
* called by the set_sort() function
*/
private function resort_objects() {
private function resort_objects()
{
// There are two ways to do this.. the easy way...
// and the vollmer way, hopefully we don't have to
// do it the vollmer way
if ($this->is_simple()) {
$sql = $this->get_sql(true);
}
else {
} else {
// FIXME: this is fragile for large browses
// First pull the objects
$objects = $this->get_saved();
@ -1464,7 +1461,8 @@ class Query {
* store
* This saves the current state to the database
*/
public function store() {
public function store()
{
$id = $this->id;
if ($id != 'nocache') {
$data = serialize($this->_state);
@ -1481,8 +1479,8 @@ class Query {
* This takes the full array of object ids, often passed into show and
* if necessary it saves them
*/
public function save_objects($object_ids) {
public function save_objects($object_ids)
{
// Saving these objects has two operations, one holds it in
// a local variable and then second holds it in a row in the
// tmp_browse table
@ -1510,8 +1508,8 @@ class Query {
* get_state
* This is a debug only function
*/
public function get_state() {
public function get_state()
{
return $this->_state;
} // get_state

View file

@ -28,8 +28,8 @@
* this can include podcasts or what-have-you
*
*/
class Radio extends database_object implements media {
class Radio extends database_object implements media
{
/* DB based variables */
public $id;
public $name;
@ -43,8 +43,8 @@ class Radio extends database_object implements media {
* 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
@ -59,8 +59,8 @@ 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 = "<a href=\"$this->url\">$this->name</a>";
@ -78,8 +78,8 @@ class Radio extends database_object implements media {
* 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']) {
Error::add('general', T_('Missing ID'));
@ -122,8 +122,8 @@ class Radio extends database_object implements media {
* This is a static function that takes a key'd array for input
* 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'])) {
Error::add('name', T_('Name Required'));
@ -138,7 +138,7 @@ class Radio extends database_object implements media {
}
// Make sure it's a real catalog
$catalog = new Catalog($data['catalog']);
$catalog = Catalog::create_from_id($data['catalog']);
if (!$catalog->name) {
Error::add('catalog', T_('Invalid Catalog'));
}
@ -166,8 +166,8 @@ 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);
$sql = "DELETE FROM `live_stream` WHERE `id`='$id'";
@ -181,7 +181,8 @@ class Radio extends database_object implements media {
* get_stream_types
* This is needed by the media interface
*/
public function get_stream_types() {
public function get_stream_types()
{
return array('foreign');
} // native_stream
@ -189,8 +190,8 @@ class Radio extends database_object implements media {
* 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;
@ -201,10 +202,8 @@ class Radio extends database_object implements media {
* has_flag
* This is needed by the media interface
*/
public function has_flag() {
public function has_flag()
{
} // has_flag
/**
@ -212,10 +211,9 @@ class Radio extends database_object implements media {
*
* This will probably never be implemented
*/
public function get_transcode_settings($target = null) {
public function get_transcode_settings($target = null)
{
return false;
}
} //end of radio class
?>

View file

@ -28,8 +28,8 @@
* by this class. There isn't a table for this class so most of its functions
* are static.
*/
class Random implements media {
class Random implements media
{
public $type;
public $id;
@ -37,8 +37,8 @@ class Random implements media {
* 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);
@ -48,8 +48,8 @@ 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);
@ -64,8 +64,8 @@ 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()";
@ -83,7 +83,8 @@ class Random implements media {
* This generates a random play url based on the passed type
* and returns it
*/
public static function play_url($id) {
public static function play_url($id)
{
if (!$type = self::get_id_type($id)) {
return false;
}
@ -100,8 +101,8 @@ class Random implements media {
* 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;
}
@ -122,8 +123,8 @@ class Random implements media {
* 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();
$sql = "SELECT `id` FROM `song` ORDER BY RAND() LIMIT $limit";
@ -142,8 +143,8 @@ 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();
// Get the last album playbed by us
@ -168,8 +169,8 @@ 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();
$data = $GLOBALS['user']->get_recently_played('1','artist');
@ -193,16 +194,15 @@ class Random implements media {
* 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($type, $data) {
public static function advanced($type, $data)
{
/* Figure out our object limit */
$limit = intval($data['random']);
// Generate our matchlist
/* If they've passed -1 as limit then get everything */
if ($data['random'] == "-1") { unset($data['random']); }
else { $limit_sql = "LIMIT " . Dba::escape($limit); }
if ($data['random'] == "-1") { unset($data['random']); } else { $limit_sql = "LIMIT " . Dba::escape($limit); }
$search_data = Search::clean_request($data);
@ -338,8 +338,8 @@ class Random implements media {
* get_type_name
* This returns a 'purrty' name for the different random types
*/
public static function get_type_name($type) {
public static function get_type_name($type)
{
switch ($type) {
case 'album':
return T_('Related Album');
@ -363,8 +363,8 @@ 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';
@ -388,8 +388,8 @@ class Random implements media {
* HACK HACK HACK HACK HACK HACK HACK
* 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':
return 'album';
@ -411,8 +411,8 @@ class Random implements media {
* validate_type
* this validates the random type
*/
public static function validate_type($type) {
public static function validate_type($type)
{
switch ($type) {
case 'default':
case 'genre':
@ -433,5 +433,3 @@ class Random implements media {
public function format() { }
} //end of random class
?>

View file

@ -26,8 +26,8 @@
* This tracks ratings for songs, albums and artists.
*
*/
class Rating extends database_object {
class Rating extends database_object
{
// Public variables
public $id; // The ID of the object rated
public $type; // The type of object we want
@ -37,8 +37,8 @@ class Rating extends database_object {
* This is run every time a new object is created, and requires
* the id and type of object that we need to pull the rating for
*/
public function __construct($id, $type) {
public function __construct($id, $type)
{
$this->id = intval($id);
$this->type = $type;
@ -51,7 +51,8 @@ class Rating extends database_object {
*
* Remove ratings for items that no longer exist.
*/
public static function gc() {
public static function gc()
{
foreach (array('song', 'album', 'artist', 'video') as $object_type) {
Dba::write("DELETE FROM `rating` USING `rating` LEFT JOIN `$object_type` ON `$object_type`.`id` = `rating`.`object_id` WHERE `object_type` = '$object_type' AND `$object_type`.`id` IS NULL");
}
@ -62,8 +63,8 @@ class Rating extends database_object {
* This attempts to get everything we'll need for this page load in a
* single query, saving on connection overhead
*/
public static function build_cache($type, $ids) {
public static function build_cache($type, $ids)
{
if (!is_array($ids) OR !count($ids)) { return false; }
$ratings = array();
@ -92,8 +93,7 @@ class Rating extends database_object {
// First store the user-specific rating
if (!isset($user_ratings[$id])) {
$rating = 0;
}
else {
} else {
$rating = intval($user_ratings[$id]);
}
parent::add_to_cache('rating_' . $type . '_user' . $GLOBALS['user']->id, $id, $rating);
@ -101,8 +101,7 @@ class Rating extends database_object {
// Then store the average
if (!isset($ratings[$id])) {
$rating = 0;
}
else {
} else {
$rating = round($ratings[$id], 1);
}
parent::add_to_cache('rating_' . $type . '_all', $id, $rating);
@ -117,8 +116,8 @@ class Rating extends database_object {
* Get a user's rating. If no userid is passed in, we use the currently
* logged in user.
*/
public function get_user_rating($user_id = null) {
public function get_user_rating($user_id = null)
{
if (is_null($user_id)) {
$user_id = $GLOBALS['user']->id;
}
@ -148,8 +147,8 @@ class Rating extends database_object {
* Get the floored average rating of what everyone has rated this object
* as. This is shown if there is no personal rating.
*/
public function get_average_rating() {
public function get_average_rating()
{
if (parent::is_cached('rating_' . $type . '_all', $id)) {
return parent::get_from_cache('rating_' . $type . '_user', $id);
}
@ -169,8 +168,8 @@ class Rating extends database_object {
* get_highest
* Get objects with the highest average rating.
*/
public static function get_highest($type, $count='', $offset='') {
public static function get_highest($type, $count='', $offset='')
{
if (!$count) {
$count = Config::get('popular_threshold');
}
@ -202,8 +201,8 @@ class Rating extends database_object {
* This function sets the rating for the current object.
* If no userid is passed in, we use the currently logged in user.
*/
public function set_rating($rating, $user_id = null) {
public function set_rating($rating, $user_id = null)
{
if (is_null($user_id)) {
$user_id = $GLOBALS['user']->id;
}
@ -218,8 +217,7 @@ class Rating extends database_object {
"`object_type` = ? AND " .
"`user` = ?";
$params = array($this->id, $this->type, $user_id);
}
else {
} else {
$sql = "REPLACE INTO `rating` " .
"(`object_id`, `object_type`, `rating`, `user`) " .
"VALUES (?, ?, ?, ?)";
@ -245,8 +243,8 @@ class Rating extends database_object {
* This takes an id and a type and displays the rating if ratings are
* enabled. If $static is true, the rating won't be editable.
*/
public static function show($object_id, $type, $static=false) {
public static function show($object_id, $type, $static=false)
{
// If ratings aren't enabled don't do anything
if (!Config::get('ratings')) { return false; }
@ -254,12 +252,10 @@ class Rating extends database_object {
if ($static) {
require Config::get('prefix') . '/templates/show_static_object_rating.inc.php';
}
else {
} else {
require Config::get('prefix') . '/templates/show_object_rating.inc.php';
}
} // show
} //end rating class
?>

View file

@ -20,13 +20,14 @@
*
*/
class Recommendation {
class Recommendation
{
/**
* Constructor
* Not on my watch, boyo.
*/
private function __construct() {
private function __construct()
{
return false;
} //constructor
@ -34,7 +35,8 @@ class Recommendation {
* get_lastfm_results
* Runs a last.fm query and returns the parsed results
*/
private static function get_lastfm_results($method, $query) {
private static function get_lastfm_results($method, $query)
{
$api_key = Config::get('lastfm_api_key');
$api_base = "http://ws.audioscrobbler.com/2.0/?method=";
$url = $api_base . $method . '&api_key=' . $api_key . '&' . $query;
@ -57,13 +59,13 @@ class Recommendation {
* get_songs_like
* Returns a list of similar songs
*/
public static function get_songs_like($song_id, $limit = 5, $local_only = true) {
public static function get_songs_like($song_id, $limit = 5, $local_only = true)
{
$song = new Song($song_id);
if (isset($song->mbid)) {
$query = 'mbid=' . rawurlencode($song->mbid);
}
else {
} else {
$query = 'track=' . rawurlencode($song->title);
}
@ -102,8 +104,7 @@ class Recommendation {
'artist' => $artist_name
);
}
}
else {
} else {
debug_event('Recommendation', "$name matched local song $local_id", 5);
$results[] = array(
'id' => $local_id,
@ -127,7 +128,8 @@ class Recommendation {
* get_artists_like
* Returns a list of similar artists
*/
public static function get_artists_like($artist_id, $limit = 5, $local_only = true) {
public static function get_artists_like($artist_id, $limit = 5, $local_only = true)
{
$artist = new Artist($artist_id);
$query = 'artist=' . rawurlencode($artist->name);
@ -172,8 +174,7 @@ class Recommendation {
'name' => $name
);
}
}
else {
} else {
debug_event('Recommendation', "$name matched local artist " . $local_id, 5);
$results[] = array(
'id' => $local_id,
@ -195,4 +196,3 @@ class Recommendation {
} // get_artists_like
} // end of recommendation class
?>

View file

@ -26,14 +26,14 @@
* This class handles all the doodlys for the registration
* stuff in Ampache
*/
class Registration {
class Registration
{
/**
* constructor
* This is what is called when the class is loaded
*/
public function __construct() {
public function __construct()
{
// Rien a faire
} // constructor
@ -42,7 +42,8 @@ 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)
{
$mailer = new Mailer();
// We are the system
@ -91,8 +92,8 @@ 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; }
@ -110,4 +111,3 @@ E-mail: %s
} // show_agreement
} // end registration class
?>

View file

@ -20,8 +20,8 @@
*
*/
class scrobbler {
class scrobbler
{
public $error_msg;
public $username;
public $password;
@ -37,8 +37,8 @@ class scrobbler {
* Constructor
* This is the constructer it takes a username and password
*/
public function __construct($username, $password,$host='',$port='',$url='',$challenge='',$scrobble_host='') {
public function __construct($username, $password,$host='',$port='',$url='',$challenge='',$scrobble_host='')
{
$this->error_msg = '';
$this->username = trim($username);
$this->password = trim($password);
@ -54,8 +54,8 @@ class scrobbler {
/**
* get_error_msg
*/
public function get_error_msg() {
public function get_error_msg()
{
return $this->error_msg;
} // get_error_msg
@ -63,8 +63,8 @@ class scrobbler {
/**
* get_queue_count
*/
public function get_queue_count() {
public function get_queue_count()
{
return count($this->queued_tracks);
} // get_queue_count
@ -74,8 +74,8 @@ class scrobbler {
* 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() {
public function handshake()
{
$as_socket = fsockopen($this->scrobble_host, 80, $errno, $errstr, 2);
if (!$as_socket) {
$this->error_msg = $errstr;
@ -149,8 +149,8 @@ class scrobbler {
* submit the track or talk to LastFM in anyway, kind of useless for our uses but its
* here, and that's how it is.
*/
public function queue_track($artist, $album, $title, $timestamp, $length,$track) {
public function queue_track($artist, $album, $title, $timestamp, $length,$track)
{
if ($length < 30) {
debug_event('Scrobbler',"Not queuing track, too short",'5');
return false;
@ -174,8 +174,8 @@ class scrobbler {
* 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() {
public function submit_tracks()
{
// Check and make sure that we've got some queued tracks
if (!count($this->queued_tracks)) {
$this->error_msg = "No tracks to submit";
@ -267,4 +267,3 @@ class scrobbler {
} // submit_tracks
} // end audioscrobbler class
?>

View file

@ -25,8 +25,8 @@
* Search-related voodoo. Beware tentacles.
*/
class Search extends playlist_object {
class Search extends playlist_object
{
public $searchtype;
public $rules;
public $logic_operator = 'AND';
@ -38,7 +38,8 @@ class Search extends playlist_object {
/**
* constructor
*/
public function __construct($searchtype = 'song', $id = '') {
public function __construct($searchtype = 'song', $id = '')
{
$this->searchtype = $searchtype;
if ($id) {
$info = $this->get_info($id);
@ -320,7 +321,7 @@ class Search extends playlist_object {
$catalogs = array();
foreach (Catalog::get_catalogs() as $catid) {
$catalog = new Catalog($catid);
$catalog = Catalog::create_from_id($catid);
$catalog->format();
$catalogs[$catid] = $catalog->f_name;
}
@ -392,7 +393,7 @@ class Search extends playlist_object {
$catalogs = array();
foreach (Catalog::get_catalogs() as $catid) {
$catalog = new Catalog($catid);
$catalog = Catalog::create_from_id($catid);
$catalog->format();
$catalogs[$catid] = $catalog->f_name;
}
@ -442,7 +443,8 @@ class Search extends playlist_object {
*
* Sanitizes raw search data
*/
public static function clean_request($data) {
public static function clean_request($data)
{
foreach ($data as $key => $value) {
$prefix = substr($key, 0, 4);
$value = trim($value);
@ -483,7 +485,8 @@ class Search extends playlist_object {
*
* Returns the name of the saved search corresponding to the given ID
*/
public static function get_name_byid($id) {
public static function get_name_byid($id)
{
$sql = "SELECT `name` FROM `search` WHERE `id` = '$id'";
$db_results = Dba::read($sql);
$r = Dba::fetch_assoc($db_results);
@ -495,7 +498,8 @@ class Search extends playlist_object {
*
* Return the IDs of all saved searches accessible by the current user.
*/
public static function get_searches() {
public static function get_searches()
{
$sql = "SELECT `id` from `search` WHERE `type`='public' OR " .
"`user`='" . $GLOBALS['user']->id . "' ORDER BY `name`";
$db_results = Dba::read($sql);
@ -515,7 +519,8 @@ class Search extends playlist_object {
* This function actually runs the search and returns an array of the
* results.
*/
public static function run($data) {
public static function run($data)
{
$limit = intval($data['limit']);
$data = Search::clean_request($data);
@ -552,7 +557,8 @@ class Search extends playlist_object {
*
* Does what it says on the tin.
*/
public function delete() {
public function delete()
{
$id = Dba::escape($this->id);
$sql = "DELETE FROM `search` WHERE `id` = ?";
$db_results = Dba::write($sql, array($id));
@ -564,7 +570,8 @@ class Search extends playlist_object {
* format
* Gussy up the data
*/
public function format() {
public function format()
{
parent::format();
$this->f_link = '<a href="' . Config::get('web_path') .
'/smartplaylist.php?action=show_playlist&amp;playlist_id=' .
@ -577,7 +584,8 @@ class Search extends playlist_object {
* Return an array of the items output by our search (part of the
* playlist interface).
*/
public function get_items() {
public function get_items()
{
$results = array();
$sql = $this->to_sql();
@ -602,7 +610,8 @@ class Search extends playlist_object {
* Returns a randomly sorted array (with an optional limit) of the items
* output by our search (part of the playlist interface)
*/
public function get_random_items($limit = null) {
public function get_random_items($limit = null)
{
$results = array();
$sql = $this->to_sql();
@ -630,7 +639,8 @@ class Search extends playlist_object {
* Iterates over our array of types to find out the basetype for
* the passed string.
*/
public function name_to_basetype($name) {
public function name_to_basetype($name)
{
foreach ($this->types as $type) {
if ($type['name'] == $name) {
return $type['type'];
@ -645,7 +655,8 @@ class Search extends playlist_object {
* Takes an array of sanitized search data from the form and generates
* our real array from it.
*/
public function parse_rules($data) {
public function parse_rules($data)
{
$this->rules = array();
foreach ($data as $rule => $value) {
if (preg_match('/^rule_(\d+)$/', $rule, $ruleID)) {
@ -667,7 +678,8 @@ class Search extends playlist_object {
*
* Save this search to the database for use as a smart playlist
*/
public function save() {
public function save()
{
// Make sure we have a unique name
if (! $this->name) {
$this->name = $GLOBALS['user']->username . ' - ' . date('Y-m-d H:i:s', time());
@ -691,7 +703,8 @@ class Search extends playlist_object {
*
* Outputs the javascript necessary to re-show the current set of rules.
*/
public function to_js() {
public function to_js()
{
foreach ($this->rules as $rule) {
$js .= '<script type="text/javascript">' .
'SearchRow.add("' . $rule[0] . '","' .
@ -705,7 +718,8 @@ class Search extends playlist_object {
*
* Call the appropriate real function.
*/
public function to_sql() {
public function to_sql()
{
return call_user_func(array($this, $this->searchtype . "_to_sql"));
}
@ -714,7 +728,8 @@ class Search extends playlist_object {
*
* This function updates the saved version with the current settings.
*/
public function update() {
public function update()
{
if (!$this->id) {
return false;
}
@ -731,7 +746,8 @@ class Search extends playlist_object {
* of predefined rules so that we don't have to include this logic in
* foo_to_sql.
*/
private function _mangle_data($data, $type, $operator) {
private function _mangle_data($data, $type, $operator)
{
if ($operator['preg_match']) {
$data = preg_replace(
$operator['preg_match'],
@ -756,7 +772,8 @@ class Search extends playlist_object {
*
* Handles the generation of the SQL for album searches.
*/
private function album_to_sql() {
private function album_to_sql()
{
$sql_logic_operator = $this->logic_operator;
$where = array();
@ -841,7 +858,8 @@ class Search extends playlist_object {
*
* Handles the generation of the SQL for artist searches.
*/
private function artist_to_sql() {
private function artist_to_sql()
{
$sql_logic_operator = $this->logic_operator;
$where = array();
$table = array();
@ -903,7 +921,8 @@ class Search extends playlist_object {
* song_to_sql
* Handles the generation of the SQL for song searches.
*/
private function song_to_sql() {
private function song_to_sql()
{
$sql_logic_operator = $this->logic_operator;
$where = array();
@ -1051,7 +1070,8 @@ class Search extends playlist_object {
*
* Handles the generation of the SQL for video searches.
*/
private function video_to_sql() {
private function video_to_sql()
{
$sql_logic_operator = $this->logic_operator;
$where = array();
@ -1085,4 +1105,3 @@ class Search extends playlist_object {
}
}
?>

View file

@ -25,13 +25,14 @@
* This class handles all of the session related stuff in Ampache
*
*/
class Session {
class Session
{
/**
* Constructor
* This should never be called
*/
private function __construct() {
private function __construct()
{
// Rien a faire
} // __construct
@ -41,7 +42,8 @@ class Session {
* This function is for opening a new session so we just verify that we
* have a database connection, nothing more is needed.
*/
public static function open($save_path, $session_name) {
public static function open($save_path, $session_name)
{
if (!Dba::dbh()) {
debug_event('session', 'Could not start session, no database connection', 1);
return false;
@ -55,7 +57,8 @@ class Session {
*
* This is run on the end of a session, nothing to do here for now.
*/
public static function close() {
public static function close()
{
return true;
}
@ -64,7 +67,8 @@ class Session {
*
* This saves the session information into the database.
*/
public static function write($key, $value) {
public static function write($key, $value)
{
if (defined('NO_SESSION_UPDATE')) {
return true;
}
@ -90,8 +94,8 @@ class Session {
*
* This removes the specified session from the database.
*/
public static function destroy($key) {
public static function destroy($key)
{
if (!strlen($key)) { return false; }
// Remove anything and EVERYTHING
@ -111,7 +115,8 @@ class Session {
*
* This function is randomly called and it cleans up the spoo
*/
public static function gc($maxlifetime) {
public static function gc($maxlifetime)
{
$sql = 'DELETE FROM `session` WHERE `expire` < ?';
$db_results = Dba::write($sql, array(time()));
@ -128,7 +133,8 @@ class Session {
*
* This takes a key and returns the data from the database.
*/
public static function read($key) {
public static function read($key)
{
return self::_read($key, 'value');
}
@ -137,7 +143,8 @@ class Session {
*
* This returns the specified column from the session row.
*/
private static function _read($key, $column) {
private static function _read($key, $column)
{
$sql = 'SELECT * FROM `session` WHERE `id` = ? AND `expire` > ?';
$db_results = Dba::read($sql, array($key, time()));
@ -155,7 +162,8 @@ class Session {
*
* This returns the username associated with a session ID, if any
*/
public static function username($key) {
public static function username($key)
{
return self::_read($key, 'username');
}
@ -165,8 +173,8 @@ class Session {
* it takes care of setting the initial cookie, and inserting the first
* chunk of data, nifty ain't it!
*/
public static function create($data) {
public static function create($data)
{
// Regenerate the session ID to prevent fixation
switch ($data['type']) {
case 'api':
@ -193,8 +201,7 @@ class Session {
if ($type == 'stream') {
$expire = time() + Config::get('stream_length');
}
else {
} else {
$expire = time() + Config::get('session_length');
}
@ -221,8 +228,8 @@ class Session {
* This checks for an existing session. If it's still valid we go ahead
* and start it and return true.
*/
public static function check() {
public static function check()
{
$session_name = Config::get('session_name');
// No cookie no go!
@ -258,7 +265,8 @@ class Session {
* exists, it also provides an array of keyed data that may be required
* based on the type.
*/
public static function exists($type, $key, $data=array()) {
public static function exists($type, $key, $data=array())
{
// Switch on the type they pass
switch ($type) {
case 'api':
@ -299,7 +307,8 @@ class Session {
*
* This takes a SID and extends its expiration.
*/
public static function extend($sid, $type = null) {
public static function extend($sid, $type = null)
{
$time = time();
$expire = isset($_COOKIE[Config::get('session_name') . '_remember'])
? $time + Config::get('remember_length')
@ -323,7 +332,8 @@ class Session {
* This function is called when the object is included, this sets up the
* session_save_handler
*/
public static function _auto_init() {
public static function _auto_init()
{
if (!function_exists('session_start')) {
header("Location:" . Config::get('web_path') . "/test.php");
exit;
@ -350,7 +360,8 @@ class Session {
* a cookie at the same time as a header redirect. As such on view of a
* login a cookie is set with the proper name.
*/
public static function create_cookie() {
public static function create_cookie()
{
// Set up the cookie prefs before we throw down, this is very important
$cookie_life = Config::get('cookie_life');
$cookie_path = Config::get('cookie_path');
@ -371,7 +382,8 @@ class Session {
*
* This function just creates the remember me cookie, nothing special.
*/
public static function create_remember_cookie() {
public static function create_remember_cookie()
{
$remember_length = Config::get('remember_length');
$session_name = Config::get('session_name');
@ -385,7 +397,8 @@ class Session {
* This function sets the cache limiting to public if you are running
* some flavor of IE and not using HTTPS.
*/
public static function ungimp_ie() {
public static function ungimp_ie()
{
// If no https, no ungimpage required
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'on') {
return true;
@ -400,4 +413,3 @@ class Session {
}
}
?>

View file

@ -20,8 +20,8 @@
*
*/
class Shoutbox {
class Shoutbox
{
public $id;
/**
@ -29,8 +29,8 @@ class Shoutbox {
* 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);
@ -42,8 +42,8 @@ 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);
$sql = "SELECT * FROM `user_shout` WHERE `id`='$shout_id'";
@ -64,7 +64,8 @@ class Shoutbox {
*
* Cleans out orphaned shoutbox items
*/
public static function gc() {
public static function gc()
{
foreach (array('song', 'album', 'artist') as $object_type) {
Dba::write("DELETE FROM `user_shout` USING `user_shout` LEFT JOIN `$object_type` ON `$object_type`.`id` = `user_shout`.`object_id` WHERE `$object_type`.`id` IS NULL AND `user_shout`.`object_type` = '$object_type'");
}
@ -75,8 +76,8 @@ class Shoutbox {
* 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();
// If we've already got too many stop here
@ -102,8 +103,8 @@ 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";
$db_results = Dba::read($sql);
@ -121,8 +122,8 @@ 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');
if (!in_array($type,$allowed_objects)) {
@ -140,8 +141,8 @@ class Shoutbox {
* This returns an image tag if the type of object we're currently rolling with
* has an image associated with it
*/
public function get_image() {
public function get_image()
{
switch ($this->object_type) {
case 'album':
$image_string = "<img class=\"shoutboximage\" height=\"75\" width=\"75\" src=\"" . Config::get('web_path') . "/image.php?id=" . $this->object_id . "&amp;thumb=1\" />";
@ -166,8 +167,8 @@ class Shoutbox {
* create
* 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();
@ -189,8 +190,8 @@ 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']);
@ -207,7 +208,8 @@ class Shoutbox {
* this function takes the object and reformats some values
*/
public function format() {
public function format()
{
$this->sticky = ($this->sticky == "0") ? 'No' : 'Yes';
$this->date = date("m\/d\/Y - H:i", $this->date);
return true;
@ -219,8 +221,8 @@ class Shoutbox {
* this function deletes a specific shoutbox entry
*/
public function delete($shout_id) {
public function delete($shout_id)
{
// Delete the shoutbox post
$shout_id = Dba::escape($shout_id);
$sql = "DELETE FROM `user_shout` WHERE `id`='$shout_id'";
@ -229,4 +231,3 @@ class Shoutbox {
} // delete
} // Shoutbox class
?>

View file

@ -20,8 +20,8 @@
*
*/
class Song extends database_object implements media {
class Song extends database_object implements media
{
/* Variables from DB */
public $id;
public $file;
@ -53,8 +53,8 @@ class Song extends database_object implements media {
*
* Song class, for modifing a song.
*/
public function __construct($id = null) {
public function __construct($id = null)
{
if (!$id) { return false; }
$this->id = intval($id);
@ -66,8 +66,7 @@ class Song extends database_object implements media {
$data = pathinfo($this->file);
$this->type = strtolower($data['extension']);
$this->mime = self::type_to_mime($this->type);
}
else {
} else {
$this->id = null;
return false;
}
@ -81,19 +80,21 @@ class Song extends database_object implements media {
*
* This inserts the song described by the passed array
*/
public static function insert($results) {
public static function insert($results)
{
$catalog = $results['catalog'];
$file = $results['file'];
$title = trim($results['title']) ?: $file;
$artist = $results['artist'];
$album = $results['album'];
$bitrate = $results['bitrate'];
$bitrate = $results['bitrate'] ?: 0;
$rate = $results['rate'] ?: 0;
$mode = $results['mode'];
$size = $results['size'] ?: 0;
$time = $results['time'] ?: 0;
$track = $results['track'];
$track_mbid = $results['mb_trackid'];
$track_mbid = $results['mb_trackid'] ?: $results['mbid'];
if ($track_mbid == '') $track_mbid = null;
$album_mbid = $results['mb_albumid'];
$artist_mbid = $results['mb_artistid'];
$disk = $results['disk'] ?: 0;
@ -125,11 +126,13 @@ class Song extends database_object implements media {
if (is_array($tags)) {
foreach ($tags as $tag) {
$tag = trim($tag);
if (!empty($tag)) {
Tag::add('song', $song_id, $tag, false);
Tag::add('album', $album_id, $tag, false);
Tag::add('artist', $artist_id, $tag, false);
}
}
}
$sql = 'INSERT INTO `song_data` (`song_id`, `comment`, `lyrics`) ' .
'VALUES(?, ?, ?)';
@ -143,7 +146,8 @@ class Song extends database_object implements media {
*
* Cleans up the song_data table
*/
public static function gc() {
public static function gc()
{
Dba::write('DELETE FROM `song_data` USING `song_data` LEFT JOIN `song` ON `song`.`id` = `song_data`.`song_id` WHERE `song`.`id` IS NULL');
}
@ -154,8 +158,8 @@ class Song extends database_object implements media {
* browse all at once and storing it in the cache, this can help if the
* db connection is the slow point.
*/
public static function build_cache($song_ids) {
public static function build_cache($song_ids)
{
if (!is_array($song_ids) || !count($song_ids)) { return false; }
$idlist = '(' . implode(',', $song_ids) . ')';
@ -216,8 +220,8 @@ class Song extends database_object implements media {
/**
* _get_info
*/
private function _get_info() {
private function _get_info()
{
$id = $this->id;
if (parent::is_cached('song', $id)) {
@ -235,6 +239,19 @@ class Song extends database_object implements media {
if (Config::get('show_played_times')) {
$results['object_cnt'] = Stats::get_object_count('song', $results['id']);
}
$sql = 'SELECT `mbid` FROM `album` WHERE `id` = ?';
$db_results = Dba::read($sql, array($results['album']));
if ($album_res = Dba::fetch_assoc($db_results)) {
$results['album_mbid'] = $album_res['mbid'];
}
$sql = 'SELECT `mbid` FROM `artist` WHERE `id` = ?';
$db_results = Dba::read($sql, array($results['artist']));
if ($artist_res = Dba::fetch_assoc($db_results)) {
$results['artist_mbid'] = $artist_res['mbid'];
}
parent::add_to_cache('song', $id, $results);
return $results;
}
@ -247,8 +264,8 @@ 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);
if (parent::is_cached('song_data',$id)) {
@ -270,8 +287,8 @@ 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();
foreach ($info as $key=>$value) {
@ -287,7 +304,8 @@ class Song extends database_object implements media {
*
* Returns the mime type for the specified file extension/type
*/
public static function type_to_mime($type) {
public static function type_to_mime($type)
{
// FIXME: This should really be done the other way around.
// Store the mime type in the database, and provide a function
// to make it a human-friendly type.
@ -339,8 +357,8 @@ class Song extends database_object implements media {
*
* Gets a list of the disabled songs for and returns an array of Songs
*/
public static function get_disabled($count = 0) {
public static function get_disabled($count = 0)
{
$results = array();
$sql = "SELECT `id` FROM `song` WHERE `enabled`='0'";
@ -361,7 +379,8 @@ class Song extends database_object implements media {
* This function takes a search type and returns a list of probable
* duplicates
*/
public static function find_duplicates($search_type) {
public static function find_duplicates($search_type)
{
$where_sql = $_REQUEST['search_disabled'] ? '' : "WHERE `enabled` != '0'";
$sql = 'SELECT `id`, `artist`, `album`, `title`, ' .
'COUNT(`title`) FROM `song` ' . $where_sql .
@ -388,7 +407,8 @@ class Song extends database_object implements media {
return $results;
}
public static function get_duplicate_info($dupe, $search_type) {
public static function get_duplicate_info($dupe, $search_type)
{
$sql = 'SELECT `id` FROM `song` ' .
"WHERE `title`='" . Dba::escape($item['title']) . "' ";
@ -416,7 +436,8 @@ class Song extends database_object implements media {
* get_album_name
* gets the name of $this->album, allows passing of id
*/
public function get_album_name($album_id=0) {
public function get_album_name($album_id=0)
{
if (!$album_id) { $album_id = $this->album; }
$album = new Album($album_id);
if ($album->prefix)
@ -429,8 +450,8 @@ class Song extends database_object implements media {
* get_artist_name
* gets the name of $this->artist, allows passing of id
*/
public function get_artist_name($artist_id=0) {
public function get_artist_name($artist_id=0)
{
if (!$artist_id) { $artist_id = $this->artist; }
$artist = new Artist($artist_id);
if ($artist->prefix)
@ -445,8 +466,8 @@ 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);
@ -463,8 +484,8 @@ 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) {
return true;
}
@ -483,8 +504,8 @@ class Song extends database_object implements media {
* 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) {
public static function compare_song_information($song,$new_song)
{
// Remove some stuff we don't care about
unset($song->catalog,$song->played,$song->enabled,$song->addition_time,$song->update_time,$song->type);
@ -528,8 +549,8 @@ class Song extends database_object implements media {
* 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) {
case 'artist':
@ -573,8 +594,8 @@ class Song extends database_object implements media {
* each little part of the song... lastly it updates
* the "update_time" of the song
*/
public static function update_song($song_id, $new_song) {
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);
@ -612,8 +633,8 @@ class Song extends database_object implements media {
* update_year
* update the year tag
*/
public static function update_year($new_year,$song_id) {
public static function update_year($new_year,$song_id)
{
self::_update_item('year',$new_year,$song_id,'50');
} // update_year
@ -622,8 +643,8 @@ class Song extends database_object implements media {
* 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');
} // update_language
@ -632,8 +653,8 @@ 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
@ -642,8 +663,8 @@ class Song extends database_object implements media {
* update_lyrics
* updates the lyrics field
*/
public static function update_lyrics($new_lyrics,$song_id) {
public static function update_lyrics($new_lyrics,$song_id)
{
self::_update_ext_item('lyrics',$new_lyrics,$song_id,'50');
} // update_lyrics
@ -652,8 +673,8 @@ class Song extends database_object implements media {
* update_title
* updates the title field
*/
public static function update_title($new_title,$song_id) {
public static function update_title($new_title,$song_id)
{
self::_update_item('title',$new_title,$song_id,'50');
} // update_title
@ -662,8 +683,8 @@ class Song extends database_object implements media {
* update_bitrate
* updates the bitrate field
*/
public static function update_bitrate($new_bitrate,$song_id) {
public static function update_bitrate($new_bitrate,$song_id)
{
self::_update_item('bitrate',$new_bitrate,$song_id,'50');
} // update_bitrate
@ -672,8 +693,8 @@ class Song extends database_object implements media {
* update_rate
* updates the rate field
*/
public static function update_rate($new_rate,$song_id) {
public static function update_rate($new_rate,$song_id)
{
self::_update_item('rate',$new_rate,$song_id,'50');
} // update_rate
@ -682,8 +703,8 @@ class Song extends database_object implements media {
* update_mode
* updates the mode field
*/
public static function update_mode($new_mode,$song_id) {
public static function update_mode($new_mode,$song_id)
{
self::_update_item('mode',$new_mode,$song_id,'50');
} // update_mode
@ -692,8 +713,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
@ -702,8 +723,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
@ -712,14 +733,14 @@ 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');
} // update_track
public static function update_mbid($new_mbid,$song_id) {
public static function update_mbid($new_mbid,$song_id)
{
self::_update_item('mbid',$new_mbid,$song_id,'50');
} // update_mbid
@ -728,8 +749,8 @@ class Song extends database_object implements media {
* update_artist
* updates the artist field
*/
public static function update_artist($new_artist,$song_id) {
public static function update_artist($new_artist,$song_id)
{
self::_update_item('artist',$new_artist,$song_id,'50');
} // update_artist
@ -738,8 +759,8 @@ 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');
} // update_album
@ -748,8 +769,8 @@ class Song extends database_object implements media {
* update_utime
* sets a new update time
*/
public static function update_utime($song_id,$time=0) {
public static function update_utime($song_id,$time=0)
{
if (!$time) { $time = time(); }
self::_update_item('update_time',$time,$song_id,'75');
@ -760,8 +781,8 @@ 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');
} // update_played
@ -770,8 +791,8 @@ class Song extends database_object implements media {
* update_enabled
* sets the enabled flag
*/
public static function update_enabled($new_enabled,$song_id) {
public static function update_enabled($new_enabled,$song_id)
{
self::_update_item('enabled',$new_enabled,$song_id,'75');
} // update_enabled
@ -783,8 +804,8 @@ class Song extends database_object implements media {
* 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
*/
private static function _update_item($field,$value,$song_id,$level) {
private static function _update_item($field,$value,$song_id,$level)
{
/* Check them Rights! */
if (!Access::check('interface',$level)) { return false; }
@ -805,8 +826,8 @@ 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; }
@ -825,8 +846,8 @@ 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();
// Format the filename
@ -880,11 +901,11 @@ class Song extends database_object implements media {
* This reformats 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 = Catalog::create_from_id($this->catalog);
// If we don't have a rename pattern then just return it
if (!trim($catalog->rename_pattern)) {
@ -918,8 +939,8 @@ 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');
unset($fields['id'],$fields['_transcoded'],$fields['_fake'],$fields['cache_hit'],$fields['mime'],$fields['type']);
@ -939,8 +960,8 @@ 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);
$sql = "SELECT * FROM `song` WHERE `file` LIKE '$path%'";
@ -961,8 +982,8 @@ class Song extends database_object implements media {
* @discussion returns the path of the song file stripped of the catalog path
* used for mpd playback
*/
public function get_rel_path($file_path=0,$catalog_id=0) {
public function get_rel_path($file_path=0,$catalog_id=0)
{
if (!$file_path) {
$info = $this->_get_info();
$file_path = $info->file;
@ -970,11 +991,8 @@ class Song extends database_object implements media {
if (!$catalog_id) {
$catalog_id = $info->catalog;
}
$catalog = new Catalog( $catalog_id );
$info = $catalog->_get_info();
$catalog_path = $info->path;
$catalog_path = rtrim($catalog_path, "/");
return( str_replace( $catalog_path . "/", "", $file_path ) );
$catalog = Catalog::create_from_id( $catalog_id );
return $catalog->get_rel_path($file_path);
} // get_rel_path
@ -984,8 +1002,8 @@ 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';
$type = $song->type;
@ -1009,8 +1027,8 @@ 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='')
{
$user_id = Dba::escape($user_id);
$sql = "SELECT `object_id`, `user`, `object_type`, `date` " .
@ -1033,11 +1051,13 @@ class Song extends database_object implements media {
} // get_recently_played
public function get_stream_types() {
public function get_stream_types()
{
return Song::get_stream_types_for_type($this->type);
} // end stream_types
public static function get_stream_types_for_type($type) {
public static function get_stream_types_for_type($type)
{
$types = array();
$transcode = Config::get('transcode_' . $type);
@ -1051,19 +1071,17 @@ class Song extends database_object implements media {
return $types;
} // end stream_types
public function get_transcode_settings($target = null) {
public function get_transcode_settings($target = null)
{
$source = $this->type;
if ($target) {
debug_event('transcode', 'Explicit format request', 5);
}
else if ($target = Config::get('encode_target_' . $source)) {
} else if ($target = Config::get('encode_target_' . $source)) {
debug_event('transcode', 'Defaulting to configured target format for ' . $source, 5);
}
else if ($target = Config::get('encode_target')) {
} else if ($target = Config::get('encode_target')) {
debug_event('transcode', 'Using default target format', 5);
}
else {
} else {
$target = $source;
debug_event('transcode', 'No default target for ' . $source . ', choosing to resample', 5);
}
@ -1084,4 +1102,3 @@ class Song extends database_object implements media {
}
} // end of song class
?>

View file

@ -28,22 +28,22 @@
* but that's not good, all done through here.
*
*/
class Stats {
class Stats
{
/* Base vars */
var $id;
var $object_type;
var $object_id;
var $date;
var $user;
public $id;
public $object_type;
public $object_id;
public $date;
public $user;
/**
* Constructor
* This doesn't do anything currently
*/
public function __construct() {
public function __construct()
{
return true;
} // Constructor
@ -53,7 +53,8 @@ class Stats {
*
* This clears all stats for _everything_.
*/
public static function clear() {
public static function clear()
{
Dba::write('TRUNCATE `object_count`');
Dba::write('UPDATE `song` SET `played` = 0');
}
@ -63,7 +64,8 @@ class Stats {
*
* This removes stats for things that no longer exist.
*/
public static function gc() {
public static function gc()
{
foreach (array('song', 'album', 'artist', 'live_stream', 'video') as $object_type) {
Dba::write("DELETE FROM `object_count` USING `object_count` LEFT JOIN `$object_type` ON `$object_type`.`id` = `object_count`.`object_id` WHERE `object_type` = '$object_type' AND `$object_type`.`id` IS NULL");
}
@ -74,8 +76,8 @@ class Stats {
* This inserts a new record for the specified object
* with the specified information, amazing!
*/
public static function insert($type,$oid,$user) {
public static function insert($type,$oid,$user)
{
$type = self::validate_type($type);
$sql = "INSERT INTO `object_count` (`object_type`,`object_id`,`date`,`user`) " .
@ -92,8 +94,8 @@ class Stats {
* get_object_count
* Get count for an object
*/
public static function get_object_count($object_type, $object_id) {
public static function get_object_count($object_type, $object_id)
{
$sql = "SELECT COUNT(*) AS `object_cnt` FROM `object_count` WHERE `object_type`= ? AND `object_id` = ?";
$db_results = Dba::read($sql, array($object_type, $object_id));
@ -109,8 +111,8 @@ 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;
$sql = "SELECT * FROM `object_count` WHERE `user` = ? AND `object_type`='song' ORDER BY `date` DESC LIMIT 1";
@ -127,8 +129,8 @@ 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;
$sql = "SELECT * FROM `object_count` WHERE `user` = ? AND `object_type`='song' AND `date` >= ? " .
@ -150,8 +152,8 @@ class Stats {
* This returns the top X for type Y from the
* last stats_threshold days
*/
public static function get_top($type,$count='',$threshold = '',$offset='') {
public static function get_top($type,$count='',$threshold = '',$offset='')
{
/* If they don't pass one, then use the preference */
if (!$threshold) {
$threshold = Config::get('stats_threshold');
@ -191,8 +193,8 @@ class Stats {
* This returns the recent X for type Y from the
* last stats_threshold days
*/
public static function get_recent($type,$count='',$threshold = '',$offset='') {
public static function get_recent($type,$count='',$threshold = '',$offset='')
{
/* If they don't pass one, then use the preference */
if (!$threshold) {
$threshold = Config::get('stats_threshold');
@ -230,16 +232,15 @@ class Stats {
* This gets all stats for atype based on user with thresholds and all
* 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);
/* If full then don't limit on date */
if ($full) {
$date = '0';
}
else {
} else {
$date = time() - (86400*Config::get('stats_threshold'));
}
@ -265,8 +266,8 @@ 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) {
case 'artist':
case 'album':
@ -286,8 +287,8 @@ class Stats {
* This returns an array of the newest artists/albums/whatever
* in this ampache instance
*/
public static function get_newest($type,$limit='',$offset='') {
public static function get_newest($type,$limit='',$offset='')
{
if (!$count) { $count = Config::get('popular_threshold'); }
if (!$offset) {
$limit = $count;
@ -312,4 +313,3 @@ class Stats {
} // get_newest
} // Stats class
?>

View file

@ -21,11 +21,12 @@
*/
class Stream {
class Stream
{
public static $session;
private function __construct() {
private function __construct()
{
// Static class, do nothing.
}
@ -36,12 +37,13 @@ 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=$sid;
} // set_session
public static function get_allowed_bitrate($song) {
public static function get_allowed_bitrate($song)
{
$max_bitrate = Config::get('max_bit_rate');
$min_bitrate = Config::get('min_bit_rate');
// FIXME: This should be configurable for each output type
@ -100,7 +102,8 @@ class Stream {
* This is a rather complex function that starts the transcoding or
* resampling of a song and returns the opened file handle.
*/
public static function start_transcode($song, $type = null) {
public static function start_transcode($song, $type = null)
{
$transcode_settings = $song->get_transcode_settings($type);
// Bail out early if we're unutterably broken
if ($transcode_settings == false) {
@ -162,8 +165,8 @@ class Stream {
* validate_bitrate
* this function takes a bitrate and returns a valid one
*/
public static function validate_bitrate($bitrate) {
public static function validate_bitrate($bitrate)
{
/* Round to standard bitrates */
$sample_rate = 16*(floor($bitrate/16));
@ -178,8 +181,8 @@ class Stream {
* 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 sessions that have been GC'd
$sql = "DELETE FROM `now_playing` USING `now_playing` " .
"LEFT JOIN `session` ON `session`.`id` = `now_playing`.`id` " .
@ -193,15 +196,16 @@ class Stream {
*
* This will insert the now playing data.
*/
public static function insert_now_playing($oid, $uid, $length, $sid, $type) {
public static function insert_now_playing($oid, $uid, $length, $sid, $type)
{
$time = intval(time() + $length);
$type = strtolower($type);
// Ensure that this client only has a single row
$sql = 'REPLACE INTO `now_playing` ' .
'(`id`,`object_id`,`object_type`, `user`, `expire`) ' .
'VALUES (?, ?, ?, ?, ?)';
$db_result = Dba::write($sql, array($sid, $oid, $type, $uid, $time));
'(`id`,`object_id`,`object_type`, `user`, `expire`, `insertion`) ' .
'VALUES (?, ?, ?, ?, ?, ?)';
$db_result = Dba::write($sql, array($sid, $oid, $type, $uid, $time, time()));
}
/**
@ -210,7 +214,8 @@ class Stream {
* There really isn't anywhere else for this function, shouldn't have
* deleted it in the first place.
*/
public static function clear_now_playing() {
public static function clear_now_playing()
{
$sql = 'TRUNCATE `now_playing`';
$db_results = Dba::write($sql);
@ -222,14 +227,16 @@ class Stream {
*
* 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`.`agent`, `now_playing`.* FROM `now_playing` ' .
'LEFT JOIN `session` ON `session`.`id` = `now_playing`.`id` ';
if (Config::get('now_playing_per_user')) {
$sql .= 'GROUP BY `now_playing`.`user` ';
}
$sql .= 'ORDER BY `now_playing`.`insertion` DESC';
} else {
$sql .= 'ORDER BY `now_playing`.`expire` DESC';
}
$db_results = Dba::read($sql);
$results = array();
@ -256,7 +263,8 @@ class Stream {
*
* This checks to see if the media is already being played.
*/
public static function check_lock_media($media_id, $type) {
public static function check_lock_media($media_id, $type)
{
$sql = 'SELECT `object_id` FROM `now_playing` WHERE ' .
'`object_id` = ? AND `object_type` = ?';
$db_results = Dba::read($sql, array($media_id, $type));
@ -273,7 +281,8 @@ 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. This is slightly wasteful.
self::$session = Session::create(array('type' => 'stream'));
}
@ -286,8 +295,8 @@ class Stream {
* playlist mojo. If something needs to happen 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 (!defined('AJAX_INCLUDE')) { return false; }
@ -316,8 +325,8 @@ class Stream {
* get_base_url
* This returns the base requirements for a stream URL this does not include anything after the index.php?sid=????
*/
public static function get_base_url() {
public static function get_base_url()
{
if (Config::get('require_session')) {
$session_string = 'ssid=' . self::$session . '&';
}
@ -330,8 +339,7 @@ class Stream {
if (Config::get('http_port') != '80') {
if (preg_match("/:(\d+)/",$web_path,$matches)) {
$web_path = str_replace(':' . $matches['1'],':' . Config::get('http_port'),$web_path);
}
else {
} else {
$web_path = str_replace($_SERVER['HTTP_HOST'],$_SERVER['HTTP_HOST'] . ':' . Config::get('http_port'),$web_path);
}
}
@ -343,5 +351,3 @@ class Stream {
} // get_base_url
} //end of stream class
?>

View file

@ -28,8 +28,8 @@
* module in question.
*/
class Stream_Playlist {
class Stream_Playlist
{
public $id;
public $urls = array();
public $user;
@ -38,8 +38,8 @@ class Stream_Playlist {
* Stream_Playlist constructor
* If an ID is passed, it should be a stream session ID.
*/
public function __construct($id = null) {
public function __construct($id = null)
{
if ($id) {
Stream::set_session($id);
}
@ -63,7 +63,8 @@ class Stream_Playlist {
return true;
}
private function _add_url($url) {
private function _add_url($url)
{
$this->urls[] = $url;
$sql = 'INSERT INTO `stream_playlist` ';
@ -85,7 +86,8 @@ class Stream_Playlist {
return Dba::write($sql, $values);
}
public static function gc() {
public static function gc()
{
$sql = 'DELETE FROM `stream_playlist` USING `stream_playlist` ' .
'LEFT JOIN `session` ON `session`.`id`=`stream_playlist`.`sid` ' .
'WHERE `session`.`id` IS NULL';
@ -96,7 +98,8 @@ class Stream_Playlist {
* _media_to_urlarray
* Formats the URL and media information and adds it to the object
*/
private static function _media_to_urlarray($media) {
private static function _media_to_urlarray($media)
{
$urls = array();
foreach ($media as $medium) {
debug_event('stream_playlist', 'Adding ' . json_encode($medium), 5);
@ -145,8 +148,8 @@ class Stream_Playlist {
return $urls;
}
public function generate_playlist($type, $redirect = false) {
public function generate_playlist($type, $redirect = false)
{
if (!count($this->urls)) {
debug_event('stream_playlist', 'Error: Empty URL array for ' . $this->id, 2);
return false;
@ -208,7 +211,8 @@ class Stream_Playlist {
* add
* Adds an array of media
*/
public function add($media = array()) {
public function add($media = array())
{
$urls = $this->_media_to_urlarray($media);
foreach ($urls as $url) {
$this->_add_url($url);
@ -220,8 +224,8 @@ class Stream_Playlist {
* Add an array of urls. 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; }
foreach ($urls as $url) {
@ -238,8 +242,8 @@ class Stream_Playlist {
* create_simplem3u
* this creates a simple m3u without any of the extended information
*/
public function create_simple_m3u() {
public function create_simple_m3u()
{
foreach ($this->urls as $url) {
echo $url->url . "\n";
}
@ -251,8 +255,8 @@ class Stream_Playlist {
* 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()
{
echo "#EXTM3U\n";
foreach ($this->urls as $url) {
@ -266,8 +270,8 @@ class Stream_Playlist {
/**
* create_pls
*/
public function create_pls() {
public function create_pls()
{
echo "[playlist]\n";
echo 'NumberOfEntries=' . count($this->urls) . "\n";
foreach ($this->urls as $url) {
@ -285,8 +289,8 @@ class Stream_Playlist {
* create_asx
* This should really only be used if all of the content is ASF files.
*/
public function create_asx() {
public function create_asx()
{
echo '<ASX VERSION="3.0" BANNERBAR="auto">' . "\n";
echo "<TITLE>Ampache ASX Playlist</TITLE>\n";
echo '<PARAM NAME="Encoding" VALUE="utf-8" />' . "\n";
@ -311,8 +315,8 @@ class Stream_Playlist {
/**
* create_xspf
*/
public function create_xspf() {
public function create_xspf()
{
foreach ($this->urls as $url) {
$xml = array();
@ -356,8 +360,8 @@ class Stream_Playlist {
*
* Creates an html5 player.
*/
public function create_html5_player() {
public function create_html5_player()
{
if (Config::get("iframes")) {
require Config::get('prefix') . '/templates/create_html5_player_embedded.inc.php';
} else {
@ -370,8 +374,8 @@ class Stream_Playlist {
* create_localplay
* This calls the Localplay API to add the URLs and then start playback
*/
public function create_localplay() {
public function create_localplay()
{
$localplay = new Localplay(Config::get('localplay_controller'));
$localplay->connect();
foreach ($this->urls as $url) {
@ -388,7 +392,8 @@ class Stream_Playlist {
* This 'votes' on the songs; it inserts them into a tmp_playlist with user
* set to -1.
*/
public function create_democratic() {
public function create_democratic()
{
$democratic = Democratic::get_current_playlist();
$democratic->set_parent();
$items = array();
@ -405,8 +410,8 @@ class Stream_Playlist {
* create_download
* This prompts for a download of the song
*/
private function create_download() {
private function create_download()
{
// There should only be one here...
if (count($this->urls) != 1) {
debug_event('stream_playlist', 'Download called, but $urls contains ' . json_encode($this->urls), 2);
@ -422,10 +427,10 @@ class Stream_Playlist {
* create_ram
*this functions creates a RAM file for use by Real Player
*/
public function create_ram() {
public function create_ram()
{
foreach ($this->urls as $url) {
echo $url->url . "\n";
}
} // create_ram
}
?>

View file

@ -23,8 +23,8 @@
// A class for passing around an URL and associated data
class Stream_URL extends memory_object {
class Stream_URL extends memory_object
{
public $properties = array('url', 'title', 'author', 'time', 'info_url', 'image_url', 'album', 'type');
/**
@ -32,7 +32,8 @@ class Stream_URL extends memory_object {
*
* Takes an url and parses out all the chewy goodness.
*/
public static function parse($url) {
public static function parse($url)
{
$query = parse_url($url, PHP_URL_QUERY);
$elements = explode('&', $query);
$results = array();

View file

@ -28,17 +28,18 @@
* These are all static calls.
*
*/
class Subsonic_Api {
class Subsonic_Api
{
/**
* constructor
* This really isn't anything to do here, so it's private
*/
private function __construct() {
private function __construct()
{
}
public static function check_version($input, $version = "1.0.0", $addheader = false) {
public static function check_version($input, $version = "1.0.0", $addheader = false)
{
// We cannot check client version unfortunately. Most Subsonic client sent a dummy client version...
/*if (version_compare($input['v'], $version) < 0) {
ob_end_clean();
@ -48,7 +49,8 @@ class Subsonic_Api {
}*/
}
public static function check_parameter($input, $parameter, $addheader = false) {
public static function check_parameter($input, $parameter, $addheader = false)
{
if (empty($input[$parameter])) {
ob_end_clean();
if ($addheader) self::setHeader($input['f']);
@ -59,8 +61,8 @@ class Subsonic_Api {
return $input[$parameter];
}
public static function follow_stream($url) {
public static function follow_stream($url)
{
if (function_exists('curl_version')) {
// Curl support, we stream transparently to avoid redirect. Redirect can fail on few clients
$ch = curl_init($url);
@ -80,7 +82,8 @@ class Subsonic_Api {
}
}
public static function setHeader($f) {
public static function setHeader($f)
{
if (strtolower($f) == "json") {
header("Content-type: application/json; charset=" . Config::get('site_charset'));
} else if (strtolower($f) == "jsonp") {
@ -90,14 +93,14 @@ class Subsonic_Api {
}
}
public static function apiOutput($input, $xml) {
public static function apiOutput($input, $xml)
{
$f = $input['f'];
self::apiOutput2(strtolower($f), $xml);
}
public static function apiOutput2($f, $xml) {
public static function apiOutput2($f, $xml)
{
if ($f == "json") {
echo json_encode(self::xml2json($xml), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
} else if ($f == "jsonp") {
@ -113,7 +116,8 @@ class Subsonic_Api {
* xml2json based from http://outlandish.com/blog/xml-to-json/
* Because we cannot use only json_encode to respect JSON Subsonic API
*/
private static function xml2json($xml, $options = array()) {
private static function xml2json($xml, $options = array())
{
$defaults = array(
'namespaceSeparator' => ':',//you may want this to be something other than a colon
'attributePrefix' => '', //to distinguish between attributes and nodes with the same name
@ -203,7 +207,8 @@ class Subsonic_Api {
* Simple server ping to test connectivity with the server.
* Takes no parameter.
*/
public static function ping($input) {
public static function ping($input)
{
// Don't check client API version here. Some client give version 0.0.0 for ping command
self::apiOutput($input, Subsonic_XML_Data::createSuccessResponse());
@ -214,7 +219,8 @@ class Subsonic_Api {
* Get details about the software license. Always return a valid default license.
* Takes no parameter.
*/
public static function getlicense($input) {
public static function getlicense($input)
{
self::check_version($input);
$r = Subsonic_XML_Data::createSuccessResponse();
@ -227,7 +233,8 @@ class Subsonic_Api {
* Get all configured top-level music folders (= ampache catalogs).
* Takes no parameter.
*/
public static function getmusicfolders($input) {
public static function getmusicfolders($input)
{
self::check_version($input);
$r = Subsonic_XML_Data::createSuccessResponse();
@ -240,7 +247,8 @@ class Subsonic_Api {
* Get an indexed structure of all artists.
* Takes optional musicFolderId and optional ifModifiedSince in parameters.
*/
public static function getindexes($input) {
public static function getindexes($input)
{
self::check_version($input);
$musicFolderId = $input['musicFolderId'];
@ -258,7 +266,7 @@ class Subsonic_Api {
foreach ($catalogs as $id) {
$clastmodified = 0;
$catalog = new Catalog($id);
$catalog = Catalog::create_from_id($id);
if ($catalog->last_update > $clastmodified) $clastmodified = $catalog->last_update;
if ($catalog->last_add > $clastmodified) $clastmodified = $catalog->last_add;
@ -282,7 +290,8 @@ class Subsonic_Api {
* Get a list of all files in a music directory.
* Takes the directory id in parameters.
*/
public static function getmusicdirectory($input) {
public static function getmusicdirectory($input)
{
self::check_version($input);
$id = self::check_parameter($input, 'id');
@ -291,8 +300,7 @@ class Subsonic_Api {
if (Subsonic_XML_Data::isArtist($id)) {
$artist = new Artist(Subsonic_XML_Data::getAmpacheId($id));
Subsonic_XML_Data::addArtistDirectory($r, $artist);
}
else if(Subsonic_XML_Data::isAlbum($id)) {
} else if (Subsonic_XML_Data::isAlbum($id)) {
$album = new Album(Subsonic_XML_Data::getAmpacheId($id));
Subsonic_XML_Data::addAlbumDirectory($r, $album);
}
@ -304,7 +312,8 @@ class Subsonic_Api {
* Get all genres.
* Takes no parameter.
*/
public static function getgenres($input) {
public static function getgenres($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createSuccessResponse();
@ -317,7 +326,8 @@ class Subsonic_Api {
* Get all artists.
* Takes no parameter.
*/
public static function getartists($input) {
public static function getartists($input)
{
self::check_version($input, "1.7.0");
$r = Subsonic_XML_Data::createSuccessResponse();
@ -331,7 +341,8 @@ class Subsonic_Api {
* Get details fro an artist, including a list of albums.
* Takes the artist id in parameter.
*/
public static function getartist($input) {
public static function getartist($input)
{
self::check_version($input, "1.7.0");
$artistid = self::check_parameter($input, 'id');
@ -351,7 +362,8 @@ class Subsonic_Api {
* Get details for an album, including a list of songs.
* Takes the album id in parameter.
*/
public static function getalbum($input) {
public static function getalbum($input)
{
self::check_version($input, "1.7.0");
$albumid = self::check_parameter($input, 'id');
@ -373,7 +385,8 @@ class Subsonic_Api {
* Takes no parameter.
* Not supported yet.
*/
public static function getvideos($input) {
public static function getvideos($input)
{
self::check_version($input, "1.7.0");
$r = Subsonic_XML_Data::createSuccessResponse();
@ -386,7 +399,8 @@ class Subsonic_Api {
* Get a list of random, newest, highest rated etc. albums.
* Takes the list type with optional size and offset in parameters.
*/
public static function getalbumlist($input, $elementName="albumList") {
public static function getalbumlist($input, $elementName="albumList")
{
self::check_version($input, "1.2.0");
$type = self::check_parameter($input, 'type');
@ -423,7 +437,8 @@ class Subsonic_Api {
* getAlbumList2
* See getAlbumList.
*/
public static function getalbumlist2($input) {
public static function getalbumlist2($input)
{
self::check_version($input, "1.7.0");
self::getAlbumList($input, "albumList2");
}
@ -433,7 +448,8 @@ class Subsonic_Api {
* Get random songs matching the given criteria.
* Takes the optional size, genre, fromYear, toYear and music folder id in parameters.
*/
public static function getrandomsongs($input) {
public static function getrandomsongs($input)
{
self::check_version($input, "1.2.0");
$size = $input['size'];
@ -497,7 +513,8 @@ class Subsonic_Api {
* Get details for a song
* Takes the song id in parameter.
*/
public static function getsong($input) {
public static function getsong($input)
{
self::check_version($input, "1.7.0");
$songid = self::check_parameter($input, 'id');
@ -512,7 +529,8 @@ class Subsonic_Api {
* Get songs in a given genre.
* Takes the genre with optional count and offset in parameters.
*/
public static function getsongsbygenre($input) {
public static function getsongsbygenre($input)
{
self::check_version($input, "1.9.0");
$genre = self::check_parameter($input, 'genre');
@ -533,7 +551,8 @@ class Subsonic_Api {
* Get what is currently being played by all users.
* Takes no parameter.
*/
public static function getnowplaying($input) {
public static function getnowplaying($input)
{
self::check_version($input);
$data = Stream::get_now_playing();
@ -547,7 +566,8 @@ class Subsonic_Api {
* Get albums, artists and songs matching the given criteria.
* Takes query with optional artist count, artist offset, album count, album offset, song count and song offset in parameters.
*/
public static function search2($input, $elementName="searchResult2") {
public static function search2($input, $elementName="searchResult2")
{
self::check_version($input, "1.2.0");
$query = self::check_parameter($input, 'query');
@ -595,7 +615,8 @@ class Subsonic_Api {
* search3
* See search2.
*/
public static function search3($input) {
public static function search3($input)
{
self::check_version($input, "1.7.0");
self::search2($input, "searchResult3");
}
@ -605,7 +626,8 @@ class Subsonic_Api {
* Get all playlists a user is allowed to play.
* Takes optional user in parameter.
*/
public static function getplaylists($input) {
public static function getplaylists($input)
{
self::check_version($input);
$r = Subsonic_XML_Data::createSuccessResponse();
@ -630,7 +652,8 @@ class Subsonic_Api {
* Get the list of files in a saved playlist.
* Takes the playlist id in parameters.
*/
public static function getplaylist($input) {
public static function getplaylist($input)
{
self::check_version($input);
$playlistid = self::check_parameter($input, 'id');
@ -646,7 +669,8 @@ class Subsonic_Api {
* Create (or updates) a playlist.
* Takes playlist id in parameter if updating, name in parameter if creating and a list of song id for the playlist.
*/
public static function createplaylist($input) {
public static function createplaylist($input)
{
self::check_version($input, "1.2.0");
$playlistId = $input['playlistId'];
@ -668,7 +692,8 @@ class Subsonic_Api {
self::apiOutput($input, $r);
}
private static function _updatePlaylist($id, $name, $songsIdToAdd = array(), $songIndexToRemove = array(), $public = true) {
private static function _updatePlaylist($id, $name, $songsIdToAdd = array(), $songIndexToRemove = array(), $public = true)
{
$playlist = new Playlist($id);
$newdata = array();
@ -699,7 +724,8 @@ class Subsonic_Api {
* Update a playlist.
* Takes playlist id in parameter with optional name, comment, public level and a list of song id to add/remove.
*/
public static function updateplaylist($input) {
public static function updateplaylist($input)
{
self::check_version($input, "1.7.0");
$playlistId = self::check_parameter($input, 'playlistId');
@ -720,7 +746,8 @@ class Subsonic_Api {
* Delete a saved playlist.
* Takes playlist id in parameter.
*/
public static function deleteplaylist($input) {
public static function deleteplaylist($input)
{
self::check_version($input, "1.2.0");
$playlistId = self::check_parameter($input, 'playlistId');
@ -737,7 +764,8 @@ class Subsonic_Api {
* Streams a given media file.
* Takes the file id in parameter with optional max bit rate, file format, time offset, size and estimate content length option.
*/
public static function stream($input) {
public static function stream($input)
{
self::check_version($input, "1.0.0", true);
$fileid = self::check_parameter($input, 'id', true);
@ -758,7 +786,8 @@ class Subsonic_Api {
* Downloads a given media file.
* Takes the file id in parameter.
*/
public static function download($input) {
public static function download($input)
{
self::check_version($input, "1.0.0", true);
$fileid = self::check_parameter($input, 'id', true);
@ -772,7 +801,8 @@ class Subsonic_Api {
* Create an HLS playlist.
* Takes the file id in parameter with optional max bit rate.
*/
public static function hls($input) {
public static function hls($input)
{
self::check_version($input, "1.7.0", true);
$fileid = self::check_parameter($input, 'id', true);
@ -797,7 +827,8 @@ class Subsonic_Api {
* Get a cover art image.
* Takes the cover art id in parameter.
*/
public static function getcoverart($input) {
public static function getcoverart($input)
{
self::check_version($input, "1.0.0", true);
$id = self::check_parameter($input, 'id', true);
@ -831,7 +862,8 @@ class Subsonic_Api {
* Sets the rating for a music file.
* Takes the file id and rating in parameters.
*/
public static function setrating($input) {
public static function setrating($input)
{
self::check_version($input, "1.6.0");
$id = self::check_parameter($input, 'id');
@ -863,7 +895,8 @@ class Subsonic_Api {
* Takes no parameter.
* Not supported.
*/
public static function getstarred($input, $elementName="starred") {
public static function getstarred($input, $elementName="starred")
{
self::check_version($input, "1.7.0");
$r = Subsonic_XML_Data::createSuccessResponse();
@ -876,7 +909,8 @@ class Subsonic_Api {
* getStarred2
* See getStarred.
*/
public static function getstarred2($input) {
public static function getstarred2($input)
{
self::getStarred($input, "starred2");
}
@ -886,7 +920,8 @@ class Subsonic_Api {
* Takes the optional file id, album id or artist id in parameters.
* Not supported.
*/
public static function star($input) {
public static function star($input)
{
self::check_version($input, "1.7.0");
self::_setStar($input, true);
@ -898,14 +933,15 @@ class Subsonic_Api {
* Takes the optional file id, album id or artist id in parameters.
* Not supported.
*/
public static function unstar($input) {
public static function unstar($input)
{
self::check_version($input, "1.7.0");
self::_setStar($input, false);
}
private static function _setStar($input, $star) {
private static function _setStar($input, $star)
{
$id = $input['id'];
$albumId = $input['albumId'];
$artistId = $input['artistId'];
@ -963,7 +999,8 @@ class Subsonic_Api {
* Searches and returns lyrics for a given song.
* Takes the optional artist and title in parameters.
*/
public static function getlyrics($input) {
public static function getlyrics($input)
{
self::check_version($input, "1.2.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -976,7 +1013,8 @@ class Subsonic_Api {
* Takes the file id with optional time and submission parameters.
* Not supported.
*/
public static function scrobble($input) {
public static function scrobble($input)
{
self::check_version($input, "1.5.0");
// Ignore error to not break clients
@ -990,7 +1028,8 @@ class Subsonic_Api {
* Takes no parameter.
* Not supported.
*/
public static function getshares($input) {
public static function getshares($input)
{
self::check_version($input, "1.6.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1003,7 +1042,8 @@ class Subsonic_Api {
* Takes the file id with optional description and expires parameters.
* Not supported.
*/
public static function createshare($input) {
public static function createshare($input)
{
self::check_version($input, "1.6.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1016,7 +1056,8 @@ class Subsonic_Api {
* Takes the share id to update with optional description and expires parameters.
* Not supported.
*/
public static function updateshare($input) {
public static function updateshare($input)
{
self::check_version($input, "1.6.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1029,7 +1070,8 @@ class Subsonic_Api {
* Takes the share id to delete in parameters.
* Not supported.
*/
public static function deleteshare($input) {
public static function deleteshare($input)
{
self::check_version($input, "1.6.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1042,7 +1084,8 @@ class Subsonic_Api {
* Takes the optional includeEpisodes and channel id in parameters
* Not supported.
*/
public static function getpodcasts($input) {
public static function getpodcasts($input)
{
self::check_version($input, "1.6.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1055,7 +1098,8 @@ class Subsonic_Api {
* Takes no parameters.
* Not supported.
*/
public static function refreshpodcasts($input) {
public static function refreshpodcasts($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1068,7 +1112,8 @@ class Subsonic_Api {
* Takes the podcast url in parameter.
* Not supported.
*/
public static function createpodcastchannel($input) {
public static function createpodcastchannel($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1081,7 +1126,8 @@ class Subsonic_Api {
* Takes the podcast id in parameter.
* Not supported.
*/
public static function deletepodcastchannel($input) {
public static function deletepodcastchannel($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1094,7 +1140,8 @@ class Subsonic_Api {
* Takes the podcast episode id in parameter.
* Not supported.
*/
public static function deletepodcastepisode($input) {
public static function deletepodcastepisode($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1107,7 +1154,8 @@ class Subsonic_Api {
* Takes the podcast episode id in parameter.
* Not supported.
*/
public static function downloadpodcastepisode($input) {
public static function downloadpodcastepisode($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1120,7 +1168,8 @@ class Subsonic_Api {
* Takes the action with optional index, offset, song id and volume gain in parameters.
* Not supported.
*/
public static function jukeboxcontrol($input) {
public static function jukeboxcontrol($input)
{
self::check_version($input, "1.2.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1133,7 +1182,8 @@ class Subsonic_Api {
* Takes no parameter.
* Not supported.
*/
public static function getinternetradiostations($input) {
public static function getinternetradiostations($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1146,7 +1196,8 @@ class Subsonic_Api {
* Takes no parameter.
* Not supported.
*/
public static function getchatmessages($input) {
public static function getchatmessages($input)
{
self::check_version($input, "1.2.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1159,7 +1210,8 @@ class Subsonic_Api {
* Takes the message in parameter.
* Not supported.
*/
public static function addchatmessages($input) {
public static function addchatmessages($input)
{
self::check_version($input, "1.2.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1172,7 +1224,8 @@ class Subsonic_Api {
* Takes the username in parameter.
* Not supported.
*/
public static function getuser($input) {
public static function getuser($input)
{
self::check_version($input, "1.3.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1185,7 +1238,8 @@ class Subsonic_Api {
* Takes no parameter.
* Not supported.
*/
public static function getusers($input) {
public static function getusers($input)
{
self::check_version($input, "1.7.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1198,7 +1252,8 @@ class Subsonic_Api {
* Takes the username, password and email with optional roles in parameters.
* Not supported.
*/
public static function createuser($input) {
public static function createuser($input)
{
self::check_version($input, "1.1.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1211,7 +1266,8 @@ class Subsonic_Api {
* Takes the username in parameter.
* Not supported.
*/
public static function deleteuser($input) {
public static function deleteuser($input)
{
self::check_version($input, "1.3.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1224,7 +1280,8 @@ class Subsonic_Api {
* Takes the username with new password in parameters.
* Not supported.
*/
public static function changepassword($input) {
public static function changepassword($input)
{
self::check_version($input, "1.1.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1237,7 +1294,8 @@ class Subsonic_Api {
* Takes no parameter.
* Not supported.
*/
public static function getbookmarks($input) {
public static function getbookmarks($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1250,7 +1308,8 @@ class Subsonic_Api {
* Takes the file id and position with optional comment in parameters.
* Not supported.
*/
public static function createbookmark($input) {
public static function createbookmark($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
@ -1263,11 +1322,11 @@ class Subsonic_Api {
* Takes the file id in parameter.
* Not supported.
*/
public static function deletebookmark($input) {
public static function deletebookmark($input)
{
self::check_version($input, "1.9.0");
$r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
self::apiOutput($input, $r);
}
}
?>

View file

@ -28,8 +28,8 @@
* are all static calls
*
*/
class Subsonic_XML_Data {
class Subsonic_XML_Data
{
const API_VERSION = "1.10.1";
const SSERROR_GENERIC = 0;
@ -51,27 +51,32 @@ class Subsonic_XML_Data {
*
* We don't use this, as its really a static class
*/
private function __construct() {
private function __construct()
{
}
public static function getArtistId($id) {
public static function getArtistId($id)
{
return $id + Subsonic_XML_Data::AMPACHEID_ARTIST;
}
public static function getAlbumId($id) {
public static function getAlbumId($id)
{
return $id + Subsonic_XML_Data::AMPACHEID_ALBUM;
}
public static function getSongId($id) {
public static function getSongId($id)
{
return $id + Subsonic_XML_Data::AMPACHEID_SONG;
}
public static function getAmpacheId($id) {
public static function getAmpacheId($id)
{
return ($id % Subsonic_XML_Data::AMPACHEID_ARTIST);
}
public static function getAmpacheIds($ids) {
public static function getAmpacheIds($ids)
{
$ampids = array();
foreach ($ids as $id) {
$ampids[] = self::getAmpacheId($id);
@ -79,31 +84,37 @@ class Subsonic_XML_Data {
return $ampids;
}
public static function isArtist($id) {
public static function isArtist($id)
{
return ($id >= Subsonic_XML_Data::AMPACHEID_ARTIST && $id < Subsonic_XML_Data::AMPACHEID_ALBUM);
}
public static function isAlbum($id) {
public static function isAlbum($id)
{
return ($id >= Subsonic_XML_Data::AMPACHEID_ALBUM && $id < Subsonic_XML_Data::AMPACHEID_SONG);
}
public static function isSong($id) {
public static function isSong($id)
{
return ($id >= Subsonic_XML_Data::AMPACHEID_SONG);
}
public static function createFailedResponse($version = "") {
public static function createFailedResponse($version = "")
{
$response = self::createResponse($version);
$response->addAttribute('status', 'failed');
return $response;
}
public static function createSuccessResponse($version = "") {
public static function createSuccessResponse($version = "")
{
$response = self::createResponse($version);
$response->addAttribute('status', 'ok');
return $response;
}
public static function createResponse($version = "") {
public static function createResponse($version = "")
{
if (empty($version)) $version = Subsonic_XML_Data::API_VERSION;
$response = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><subsonic-response/>');
$response->addAttribute('xmlns', 'http://subsonic.org/restapi');
@ -111,7 +122,8 @@ class Subsonic_XML_Data {
return $response;
}
public static function createError($code, $message = "", $version = "") {
public static function createError($code, $message = "", $version = "")
{
if (empty($version)) $version = Subsonic_XML_Data::API_VERSION;
$response = self::createFailedResponse($version);
self::setError($response, $code, $message);
@ -125,8 +137,8 @@ class Subsonic_XML_Data {
* @param integer $code Error code
* @param string $string Error message
*/
public static function setError($xml, $code, $message = "") {
public static function setError($xml, $code, $message = "")
{
$xerr = $xml->addChild('error');
$xerr->addAttribute('code', $code);
@ -146,7 +158,8 @@ class Subsonic_XML_Data {
$xerr->addAttribute("message", $message);
}
public static function addLicense($xml) {
public static function addLicense($xml)
{
$xlic = $xml->addChild('license');
$xlic->addAttribute('valid', 'true');
$xlic->addAttribute('email', 'webmaster@ampache.org');
@ -154,28 +167,32 @@ class Subsonic_XML_Data {
$xlic->addAttribute('date', '2009-09-03T14:46:43');
}
public static function addMusicFolders($xml, $catalogs) {
public static function addMusicFolders($xml, $catalogs)
{
$xfolders = $xml->addChild('musicFolders');
foreach ($catalogs as $id) {
$catalog = new Catalog($id);
$catalog = Catalog::create_from_id($id);
$xfolder = $xfolders->addChild('musicFolder');
$xfolder->addAttribute('id', $id);
$xfolder->addAttribute('name', $catalog->name);
}
}
public static function addArtistsIndexes($xml, $artists, $lastModified) {
public static function addArtistsIndexes($xml, $artists, $lastModified)
{
$xindexes = $xml->addChild('indexes');
$xindexes->addAttribute('lastModified', $lastModified);
self::addArtists($xindexes, $artists);
}
public static function addArtistsRoot($xml, $artists) {
public static function addArtistsRoot($xml, $artists)
{
$xartists = $xml->addChild('artists');
self::addArtists($xartists, $artists, true);
}
public static function addArtists($xml, $artists, $extra=false) {
public static function addArtists($xml, $artists, $extra=false)
{
$xlastcat = null;
$xlastletter = '';
foreach ($artists as $artist) {
@ -195,7 +212,8 @@ class Subsonic_XML_Data {
}
}
public static function addArtist($xml, $artist, $extra=false, $albums=false) {
public static function addArtist($xml, $artist, $extra=false, $albums=false)
{
$xartist = $xml->addChild('artist');
$xartist->addAttribute('id', self::getArtistId($artist->id));
$xartist->addAttribute('name', $artist->name);
@ -212,7 +230,8 @@ class Subsonic_XML_Data {
}
}
public static function addAlbumList($xml, $albums, $elementName="albumList") {
public static function addAlbumList($xml, $albums, $elementName="albumList")
{
$xlist = $xml->addChild($elementName);
foreach ($albums as $id) {
$album = new Album($id);
@ -220,7 +239,8 @@ class Subsonic_XML_Data {
}
}
public static function addAlbum($xml, $album, $songs=false, $elementName="album") {
public static function addAlbum($xml, $album, $songs=false, $elementName="album")
{
$xalbum = $xml->addChild($elementName);
$xalbum->addAttribute('id', self::getAlbumId($album->id));
$xalbum->addAttribute('album', $album->name);
@ -248,11 +268,13 @@ class Subsonic_XML_Data {
}
}
public static function addSong($xml, $song, $elementName='song') {
public static function addSong($xml, $song, $elementName='song')
{
self::createSong($xml, $song, $elementName);
}
public static function createSong($xml, $song, $elementName='song') {
public static function createSong($xml, $song, $elementName='song')
{
$xsong = $xml->addChild($elementName);
$xsong->addAttribute('id', self::getSongId($song->id));
$xsong->addAttribute('parent', self::getAlbumId($song->album));
@ -285,11 +307,13 @@ class Subsonic_XML_Data {
return $xsong;
}
private static function formatAlbum($album) {
private static function formatAlbum($album)
{
return $album->name . " [" . $album->year . "]";
}
public static function addArtistDirectory($xml, $artist) {
public static function addArtistDirectory($xml, $artist)
{
$xdir = $xml->addChild('directory');
$xdir->addAttribute('id', self::getArtistId($artist->id));
$xdir->addAttribute('name', $artist->name);
@ -301,7 +325,8 @@ class Subsonic_XML_Data {
}
}
public static function addAlbumDirectory($xml, $album) {
public static function addAlbumDirectory($xml, $album)
{
$xdir = $xml->addChild('directory');
$xdir->addAttribute('id', self::getAlbumId($album->id));
$xdir->addAttribute('name', self::formatAlbum($album));
@ -315,7 +340,8 @@ class Subsonic_XML_Data {
}
}
public static function addGenres($xml, $tags) {
public static function addGenres($xml, $tags)
{
$xgenres = $xml->addChild('genres');
foreach ($tags as $tag) {
@ -324,12 +350,14 @@ class Subsonic_XML_Data {
}
}
public static function addVideos($xml) {
public static function addVideos($xml)
{
// Not supported yet
$xvideos = $xml->addChild('videos');
}
public static function addPlaylists($xml, $playlists) {
public static function addPlaylists($xml, $playlists)
{
$xplaylists = $xml->addChild('playlists');
foreach ($playlists as $id) {
$playlist = new Playlist($id);
@ -337,7 +365,8 @@ class Subsonic_XML_Data {
}
}
public static function addPlaylist($xml, $playlist, $songs=false) {
public static function addPlaylist($xml, $playlist, $songs=false)
{
$xplaylist = $xml->addChild('playlist');
$xplaylist->addAttribute('id', $playlist->id);
$xplaylist->addAttribute('name', $playlist->name);
@ -357,7 +386,8 @@ class Subsonic_XML_Data {
}
}
public static function addRandomSongs($xml, $songs) {
public static function addRandomSongs($xml, $songs)
{
$xsongs = $xml->addChild('randomSongs');
foreach ($songs as $id) {
$song = new Song($id);
@ -365,7 +395,8 @@ class Subsonic_XML_Data {
}
}
public static function addSongsByGenre($xml, $songs) {
public static function addSongsByGenre($xml, $songs)
{
$xsongs = $xml->addChild('songsByGenre');
foreach ($songs as $id) {
$song = new Song($id);
@ -373,7 +404,8 @@ class Subsonic_XML_Data {
}
}
public static function addNowPlaying($xml, $data) {
public static function addNowPlaying($xml, $data)
{
$xplaynow = $xml->addChild('nowPlaying');
foreach ($data as $d) {
$track = self::createSong($xplaynow, $d['media'], "entry");
@ -383,7 +415,8 @@ class Subsonic_XML_Data {
}
}
public static function addSearchResult($xml, $artists, $albums, $songs, $elementName = "searchResult2") {
public static function addSearchResult($xml, $artists, $albums, $songs, $elementName = "searchResult2")
{
$xresult = $xml->addChild($elementName);
foreach ($artists as $id) {
$artist = new Artist($id);
@ -399,7 +432,8 @@ class Subsonic_XML_Data {
}
}
public static function addStarred($xml, $artists, $albums, $songs, $elementName="starred") {
public static function addStarred($xml, $artists, $albums, $songs, $elementName="starred")
{
$xstarred = $xml->addChild($elementName);
foreach ($artists as $id) {
@ -418,5 +452,3 @@ class Subsonic_XML_Data {
}
}
}
?>

View file

@ -26,8 +26,8 @@
* This class hnadles all of the tag relation operations
*
*/
class Tag extends database_object {
class Tag extends database_object
{
public $id;
public $name;
@ -40,8 +40,8 @@ class Tag extends database_object {
* constructor
* This takes a tag id and returns all of the relevent information
*/
public function __construct($id) {
public function __construct($id)
{
if (!$id) { return false; }
$info = $this->get_info($id);
@ -56,8 +56,8 @@ class Tag extends database_object {
* construct_from_name
* This attempts to construct the tag from a name, rather then the ID
*/
public static function construct_from_name($name) {
public static function construct_from_name($name)
{
$tag_id = self::tag_exists($name);
$tag = new Tag($tag_id);
@ -71,8 +71,8 @@ class Tag extends database_object {
* This makes the tag presentable to the great humans that use this program, other life forms
* will just have to fend for themselves
*/
public function format($type=0,$object_id=0) {
public function format($type=0,$object_id=0)
{
if ($type AND !self::validate_type($type)) { return false; }
if ($type) {
@ -86,8 +86,7 @@ class Tag extends database_object {
if ($this->owner == $GLOBALS['user']->id) {
$action = '?page=tag&action=remove_tag&type=' . scrub_out($type) . '&tag_id=' . intval($this->id) . '&object_id=' . intval($object_id);
$class = "hover-remove ";
}
else {
} else {
$action = '?page=tag&action=add_tag&type=' . scrub_out($type) . '&tag_id=' . intval($this->id) . '&object_id=' . intval($object_id);
$class = "hover-add ";
}
@ -105,12 +104,11 @@ class Tag extends database_object {
* data from the map cache, otherwise I guess we'll just have to look it
* up.
*/
public function set_object($type,$object_id) {
public function set_object($type,$object_id)
{
if (parent::is_cached('tag_top_' . $type,$object_id)) {
$data = parent::get_from_cache('tag_top_' . $type,$object_id);
}
else {
} else {
$data = self::get_top_tags($type,$object_id);
}
@ -132,8 +130,8 @@ class Tag extends database_object {
* This takes an array of object ids and caches all of their information
* in a single query, cuts down on the connections
*/
public static function build_cache($ids) {
public static function build_cache($ids)
{
if (!is_array($ids) OR !count($ids)) { return false; }
$idlist = '(' . implode(',',$ids) . ')';
@ -152,8 +150,8 @@ class Tag extends database_object {
* build_map_cache
* This builds a cache of the mappings for the specified object, no limit is given
*/
public static function build_map_cache($type,$ids) {
public static function build_map_cache($type,$ids)
{
if (!is_array($ids) OR !count($ids)) { return false; }
$type = self::validate_type($type);
@ -190,8 +188,8 @@ class Tag extends database_object {
* This is a wrapper function, it figures out what we need to add, be it a tag
* and map, or just the mapping
*/
public static function add($type,$id,$value,$user=false) {
public static function add($type,$id,$value,$user=false)
{
// Validate the tag type
if (!self::validate_type($type)) { return false; }
@ -226,8 +224,8 @@ class Tag extends database_object {
* add_tag
* This function adds a new tag, for now we're going to limit the tagging a bit
*/
public static function add_tag($value) {
public static function add_tag($value)
{
// Clean it up and make it tagish
$value = self::clean_tag($value);
@ -249,8 +247,8 @@ class Tag extends database_object {
* add_tag_map
* This adds a specific tag to the map for specified object
*/
public static function add_tag_map($type,$object_id,$tag_id,$user='') {
public static function add_tag_map($type,$object_id,$tag_id,$user='')
{
$uid = ($user == '') ? intval($GLOBALS['user']->id) : intval($user);
$tag_id = intval($tag_id);
if (!self::validate_type($type)) { return false; }
@ -275,7 +273,8 @@ class Tag extends database_object {
* This cleans out tag_maps that are obsolete and then removes tags that
* have no maps.
*/
public static function gc() {
public static function gc()
{
$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";
$db_results = Dba::write($sql);
@ -302,8 +301,8 @@ class Tag extends database_object {
* tag_exists
* This checks to see if a tag exists, this has nothing to do with objects or maps
*/
public static function tag_exists($value) {
public static function tag_exists($value)
{
if (parent::is_cached('tag_name',$value)) {
return parent::get_from_cache('tag_name',$value);
}
@ -325,8 +324,8 @@ class Tag extends database_object {
* This looks to see if the current mapping of the current object of the current tag of the current
* user exists, lots of currents... taste good in scones.
*/
public static function tag_map_exists($type,$object_id,$tag_id,$user) {
public static function tag_map_exists($type,$object_id,$tag_id,$user)
{
if (!self::validate_type($type)) { return false; }
if (parent::is_cached('tag_map_' . $type,$object_id)) {
@ -354,8 +353,8 @@ class Tag extends database_object {
* get_top_tags
* This gets the top tags for the specified object using limit
*/
public static function get_top_tags($type, $object_id, $limit = 10) {
public static function get_top_tags($type, $object_id, $limit = 10)
{
if (!self::validate_type($type)) { return false; }
if (parent::is_cached('tag_top_' . $type,$object_id)) {
@ -387,8 +386,8 @@ class Tag extends database_object {
* Display all tags that apply to maching target type of the specified id
* UNUSED
*/
public static function get_object_tags($type, $id) {
public static function get_object_tags($type, $id)
{
if (!self::validate_type($type)) { return array(); }
$id = Dba::escape($id);
@ -412,8 +411,8 @@ class Tag extends database_object {
* get_tag_objects
* This gets the objects from a specified tag and returns an array of object ids, nothing more
*/
public static function get_tag_objects($type,$tag_id,$count='',$offset='') {
public static function get_tag_objects($type,$tag_id,$count='',$offset='')
{
if (!self::validate_type($type)) { return array(); }
if ($count) {
@ -442,8 +441,8 @@ class Tag extends database_object {
* This is a non-object non type depedent function that just returns tags
* we've got, it can take filters (this is used by the tag cloud)
*/
public static function get_tags($limit = 0,$filters=array()) {
public static function get_tags($limit = 0,$filters=array())
{
$sql = "SELECT `tag_map`.`tag_id`,COUNT(`tag_map`.`object_id`) AS `count` " .
"FROM `tag_map` " .
"LEFT JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " .
@ -474,8 +473,8 @@ class Tag extends database_object {
* it also takes a type so that it knows how to return it, this is used
* by the formating functions of the different objects
*/
public static function get_display($tags,$element_id,$type='song') {
public static function get_display($tags,$element_id,$type='song')
{
if (!is_array($tags)) { return ''; }
$results = '';
@ -498,8 +497,8 @@ class Tag extends database_object {
* This returns the count for the all objects associated with this tag
* If a type is specific only counts for said type are returned
*/
public function count($type='') {
public function count($type='')
{
if ($type) {
$filter_sql = " AND `object_type`='" . Dba::escape($type) . "'";
}
@ -521,8 +520,8 @@ class Tag extends database_object {
* filter_with_prefs
* This filters the tags based on the users preference
*/
public static function filter_with_prefs($l) {
public static function filter_with_prefs($l)
{
$colors = array('#0000FF',
'#00FF00', '#FFFF00', '#00FFFF','#FF00FF','#FF0000');
$prefs = 'tag company';
@ -540,8 +539,7 @@ class Tag extends database_object {
if ($prefs=='all') {
$sql .= '1';
}
else {
} else {
$sql .= 'username in ('.$req.')';
}
@ -564,8 +562,7 @@ class Tag extends database_object {
foreach ($l as $i) {
if ($GLOBALS['user']->id == $i['user']) {
$res[] = $i;
}
elseif (isset($uids[$i['user']])) {
} elseif (isset($uids[$i['user']])) {
$i['color'] = $uids[$i['user']];
$i['username'] = $usernames[$i['user']];
$res[] = $i;
@ -580,8 +577,8 @@ class Tag extends database_object {
* remove_map
* This will only remove tag maps for the current user
*/
public function remove_map($type,$object_id) {
public function remove_map($type,$object_id)
{
if (!self::validate_type($type)) { return false; }
$type = Dba::escape($type);
@ -601,8 +598,8 @@ class Tag extends database_object {
* This validates the type of the object the user wants to tag, we limit this to types
* we currently support
*/
public static function validate_type($type) {
public static function validate_type($type)
{
$valid_array = array('song','artist','album','video','playlist','live_stream');
if (in_array($type,$valid_array)) { return $type; }
@ -615,8 +612,8 @@ class Tag extends database_object {
* clean_tag
* This takes a string and makes it Tagish
*/
public static function clean_tag($value) {
public static function clean_tag($value)
{
$tag = preg_replace("/[^\w\_\-\s\&]/","",$value);
return $tag;
@ -624,4 +621,3 @@ class Tag extends database_object {
} // clean_tag
} // end of Tag class
?>

View file

@ -28,8 +28,8 @@
* visit user_vote from time to time.
*
*/
class Tmp_Playlist extends database_object {
class Tmp_Playlist extends database_object
{
/* Variables from the Datbase */
public $id;
public $session;
@ -46,8 +46,8 @@ class Tmp_Playlist extends database_object {
* information. If no playlist_id is passed or the requested one isn't
* found, return false.
*/
public function __construct($playlist_id='') {
public function __construct($playlist_id='')
{
if (!$playlist_id) { return false; }
$this->id = intval($playlist_id);
@ -66,8 +66,8 @@ class Tmp_Playlist extends database_object {
* This is an internal (private) function that gathers the information
* for this object from the playlist_id that was passed in.
*/
private function _get_info() {
private function _get_info()
{
$sql = "SELECT * FROM `tmp_playlist` WHERE `id`='" . Dba::escape($this->id) . "'";
$db_results = Dba::read($sql);
@ -82,8 +82,8 @@ class Tmp_Playlist extends database_object {
* This returns a playlist object based on the session that is passed to
* us. This is used by the load_playlist on user for the most part.
*/
public static function get_from_session($session_id) {
public static function get_from_session($session_id)
{
$session_id = Dba::escape($session_id);
$sql = "SELECT `id` FROM `tmp_playlist` WHERE `session`='$session_id'";
@ -110,8 +110,8 @@ class Tmp_Playlist extends database_object {
* This returns a tmp playlist object based on a userid passed
* this is used for the user profiles page
*/
public static function get_from_userid($user_id) {
public static function get_from_userid($user_id)
{
// This is a little stupid, but because we don't have the
// user_id in the session or in the tmp_playlist table we have
// to do it this way.
@ -135,8 +135,8 @@ class Tmp_Playlist extends database_object {
* get_items
* Returns an array of all object_ids currently in this Tmp_Playlist.
*/
public function get_items() {
public function get_items()
{
$id = Dba::escape($this->id);
/* Select all objects from this playlist */
@ -164,8 +164,8 @@ class Tmp_Playlist extends database_object {
* get_next_object
* This returns the next object in the tmp_playlist.
*/
public function get_next_object() {
public function get_next_object()
{
$id = Dba::escape($this->id);
$sql = "SELECT `object_id` FROM `tmp_playlist_data` " .
@ -183,8 +183,8 @@ class Tmp_Playlist extends database_object {
* This returns a count of the total number of tracks that are in this
* tmp playlist
*/
public function count_items() {
public function count_items()
{
$id = Dba::escape($this->id);
$sql = "SELECT COUNT(`id`) FROM `tmp_playlist_data` WHERE " .
@ -201,8 +201,8 @@ class Tmp_Playlist extends database_object {
* clear
* This clears all the objects out of a single playlist
*/
public function clear() {
public function clear()
{
$id = Dba::escape($this->id);
$sql = "DELETE FROM `tmp_playlist_data` WHERE " .
@ -219,8 +219,8 @@ class Tmp_Playlist extends database_object {
* the current session rather than a user, as you could have the same
* user logged in from multiple locations.
*/
public static function create($data) {
public static function create($data)
{
$sessid = Dba::escape($data['session_id']);
$type = Dba::escape($data['type']);
$object_type = Dba::escape($data['object_type']);
@ -243,8 +243,8 @@ class Tmp_Playlist extends database_object {
* update_playlist
* This updates the base_playlist on this tmp_playlist
*/
public function update_playlist($playlist_id) {
public function update_playlist($playlist_id)
{
$playlist_id = Dba::escape($playlist_id);
$id = Dba::escape($this->id);
@ -261,8 +261,8 @@ class Tmp_Playlist extends database_object {
* This deletes any other tmp_playlists associated with this
* session
*/
public static function session_clean($sessid, $id) {
public static function session_clean($sessid, $id)
{
$sessid = Dba::escape($sessid);
$id = Dba::escape($id);
@ -281,7 +281,8 @@ class Tmp_Playlist extends database_object {
* gc
* This cleans up old data
*/
public static function gc() {
public static function gc()
{
self::prune_playlists();
self::prune_tracks();
Dba::write("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");
@ -291,8 +292,8 @@ class Tmp_Playlist extends database_object {
* prune_playlists
* This deletes any playlists that don't have an associated session
*/
public static function prune_playlists() {
public static function prune_playlists()
{
/* Just delete if no matching session row */
$sql = "DELETE FROM `tmp_playlist` USING `tmp_playlist` " .
"LEFT JOIN `session` " .
@ -309,8 +310,8 @@ class Tmp_Playlist extends database_object {
* prune_tracks
* This prunes tracks that don't have playlists or don't have votes
*/
public static function prune_tracks() {
public static function prune_tracks()
{
// This prune is always run and clears data for playlists that
// don't exist anymore
$sql = "DELETE FROM `tmp_playlist_data` USING " .
@ -326,8 +327,8 @@ class Tmp_Playlist extends database_object {
* This adds the object of $this->object_type to this tmp playlist
* it takes an optional type, default is song
*/
public function add_object($object_id,$object_type) {
public function add_object($object_id,$object_type)
{
$object_id = Dba::escape($object_id);
$playlist_id = Dba::escape($this->id);
$object_type = $object_type ? Dba::escape($object_type) : 'song';
@ -346,8 +347,8 @@ class Tmp_Playlist extends database_object {
* This checks to see if this playlist is a voting playlist
* and if it is active
*/
public function vote_active() {
public function vote_active()
{
/* Going to do a little more here later */
if ($this->type == 'vote') { return true; }
@ -359,8 +360,8 @@ class Tmp_Playlist extends database_object {
* delete_track
* This deletes a track from the tmpplaylist
*/
public function delete_track($id) {
public function delete_track($id)
{
$id = Dba::escape($id);
/* delete the track its self */

View file

@ -23,13 +23,14 @@
// A collection of methods related to the user interface
class UI {
class UI
{
private static $_classes;
private static $_ticker;
private static $_icon_cache;
public function __construct($data) {
public function __construct($data)
{
return false;
}
@ -38,7 +39,8 @@ class UI {
*
* Throw an error when they try to do something naughty.
*/
public static function access_denied($error = 'Access Denied') {
public static function access_denied($error = 'Access Denied')
{
// Clear any buffered crap
ob_end_clean();
header("HTTP/1.1 403 $error");
@ -52,7 +54,8 @@ class UI {
* Does some trickery with the output buffer to return the output of a
* template.
*/
public static function ajax_include($template) {
public static function ajax_include($template)
{
ob_start();
require Config::get('prefix') . '/templates/' . $template;
$output = ob_get_contents();
@ -66,7 +69,8 @@ class UI {
*
* Checks to see whether iconv is available;
*/
public static function check_iconv() {
public static function check_iconv()
{
if (function_exists('iconv') && function_exists('iconv_substr')) {
return true;
}
@ -79,7 +83,8 @@ class UI {
* Stupid little cutesie thing to ratelimit output of long-running
* operations.
*/
public static function check_ticker() {
public static function check_ticker()
{
if (!isset(self::$_ticker) || (time() > self::$_ticker + 1)) {
self::$_ticker = time();
return true;
@ -95,7 +100,8 @@ class UI {
* UTF-8, but close enough for our purposes.)
* See http://www.w3.org/TR/2006/REC-xml-20060816/#charsets
*/
public static function clean_utf8($string) {
public static function clean_utf8($string)
{
if ($string) {
$clean = preg_replace('/[^\x{9}\x{a}\x{d}\x{20}-\x{d7ff}\x{e000}-\x{fffd}\x{10000}-\x{10ffff}]|[\x{7f}-\x{84}\x{86}-\x{9f}\x{fdd0}-\x{fddf}\x{1fffe}-\x{1ffff}\x{2fffe}-\x{2ffff}\x{3fffe}-\x{3ffff}\x{4fffe}-\x{4ffff}\x{5fffe}-\x{5ffff}\x{6fffe}-\x{6ffff}\x{7fffe}-\x{7ffff}\x{8fffe}-\x{8ffff}\x{9fffe}-\x{9ffff}\x{afffe}-\x{affff}\x{bfffe}-\x{bffff}\x{cfffe}-\x{cffff}\x{dfffe}-\x{dffff}\x{efffe}-\x{effff}\x{ffffe}-\x{fffff}\x{10fffe}-\x{10ffff}]/u', '', $string);
@ -113,11 +119,11 @@ class UI {
* First initialised with an array of two class names. Subsequent calls
* reverse the array then return the first element.
*/
public static function flip_class($classes = null) {
public static function flip_class($classes = null)
{
if (is_array($classes)) {
self::$_classes = $classes;
}
else {
} else {
self::$_classes = array_reverse(self::$_classes);
}
return self::$_classes[0];
@ -128,7 +134,8 @@ class UI {
*
* Turns a size in bytes into the best human-readable value
*/
public static function format_bytes($value, $precision = 2) {
public static function format_bytes($value, $precision = 2)
{
$pass = 0;
while (strlen(floor($value)) > 3) {
$value /= 1024;
@ -152,12 +159,12 @@ class UI {
*
* Parses a human-readable size
*/
public static function unformat_bytes($value) {
public static function unformat_bytes($value)
{
if (preg_match('/^([0-9]+) *([[:alpha:]]+)$/', $value, $matches)) {
$value = $matches[1];
$unit = strtolower(substr($matches[2], 0, 1));
}
else {
} else {
return $value;
}
@ -182,7 +189,8 @@ class UI {
*
* Returns an <img> tag for the specified icon
*/
public static function get_icon($name, $title = null, $id = null) {
public static function get_icon($name, $title = null, $id = null)
{
if (is_array($name)) {
$hover_name = $name[1];
$name = $name[0];
@ -218,7 +226,8 @@ class UI {
*
* Does the finding icon thing
*/
private static function _find_icon($name) {
private static function _find_icon($name)
{
if ($url = self::$_icon_cache[$name]) {
return $url;
}
@ -240,7 +249,8 @@ class UI {
*
* For now this just shows the header template
*/
public static function show_header() {
public static function show_header()
{
require_once Config::get('prefix') . '/templates/header.inc.php';
}
@ -249,7 +259,8 @@ class UI {
*
* For now this just shows the mainframes template
*/
public static function show_mainframes() {
public static function show_mainframes()
{
require_once Config::get('prefix') . '/templates/mainframes.inc.php';
}
@ -258,7 +269,8 @@ class UI {
*
* Shows the footer template and possibly profiling info.
*/
public static function show_footer() {
public static function show_footer()
{
require_once Config::get('prefix') . '/templates/footer.inc.php';
if (isset($_REQUEST['profiling'])) {
Dba::show_profile();
@ -270,7 +282,8 @@ class UI {
*
* This shows the top of the box.
*/
public static function show_box_top($title = '', $class = '') {
public static function show_box_top($title = '', $class = '')
{
require Config::get('prefix') . '/templates/show_box_top.inc.php';
}
@ -279,7 +292,8 @@ class UI {
*
* This shows the bottom of the box
*/
public static function show_box_bottom() {
public static function show_box_bottom()
{
require Config::get('prefix') . '/templates/show_box_bottom.inc.php';
}
@ -289,7 +303,8 @@ class UI {
* Limit text to a certain length; adds an ellipsis if truncation was
* required.
*/
public static function truncate($text, $max = 27) {
public static function truncate($text, $max = 27)
{
// If they want <3, we're having none of that
if ($max <= 3) {
debug_event('UI', "truncate called with $max, refusing to do stupid things to $text", 2);
@ -302,8 +317,7 @@ class UI {
$text = iconv_substr($text, 0, $max - 3, $charset);
$text .= iconv('ISO-8859-1', $charset, '...');
}
}
else {
} else {
if (strlen($text) > $max) {
$text = substr($text, 0, $max - 3) . '...';
}
@ -318,7 +332,8 @@ class UI {
* Convenience function that, if the output is going to a browser,
* blarfs JS to do a fancy update. Otherwise it just outputs the text.
*/
public static function update_text($field, $value) {
public static function update_text($field, $value)
{
if (defined('CLI')) {
echo $value . "\n";
return;

View file

@ -30,8 +30,8 @@
* 1090017.
*/
class Update {
class Update
{
public $key;
public $value;
public static $versions; // array containing version information
@ -41,7 +41,8 @@ class Update {
*
* This should never be called
*/
private function __construct() {
private function __construct()
{
// static class
}
@ -52,8 +53,8 @@ class Update {
* Because we may not have the update_info table we have to check
* for its existence first.
*/
public static function get_version() {
public static function get_version()
{
/* Make sure that update_info exits */
$sql = "SHOW TABLES LIKE 'update_info'";
$db_results = Dba::read($sql);
@ -85,7 +86,8 @@ class Update {
*
* Make the version number pretty.
*/
public static function format_version($data) {
public static function format_version($data)
{
$new_version =
substr($data, 0, strlen($data) - 5) . '.' .
substr($data, strlen($data) - 5, 1) . ' Build:' .
@ -99,7 +101,8 @@ class Update {
*
* Checks to see if we need to update ampache at all.
*/
public static function need_update() {
public static function need_update()
{
$current_version = self::get_version();
if (!is_array(self::$versions)) {
@ -121,8 +124,8 @@ class Update {
* just sets an array the current differences
* that require an update
*/
public static function populate_version() {
public static function populate_version()
{
/* Define the array */
$version = array();
@ -302,6 +305,12 @@ class Update {
$update_string = '- Add option to show number of times a song was played.<br />';
$version[] = array('version' => '360019', 'description' => $update_string);
$update_string = '- Catalog types are plugins now.<br />';
$version[] = array('version' => '360020', 'description' => $update_string);
$update_string = '- Add insertion date on Now Playing and option to show the current song in page title for HTML5 player.<br />';
$version[] = array('version' => '360021', 'description' => $update_string);
return $version;
}
@ -312,8 +321,8 @@ class Update {
* updates to the database. This will actually
* echo out the list...
*/
public static function display_update() {
public static function display_update()
{
$current_version = self::get_version();
if (!is_array(self::$versions)) {
self::$versions = self::populate_version();
@ -330,8 +339,7 @@ class Update {
echo 'Version: ', self::format_version($update['version']);
if (defined('CLI')) {
echo "\n", str_replace('<br />', "\n", $update['description']), "\n";
}
else {
} else {
echo '</b><br />', $update['description'], "<br /></li>\n";
}
} // if newer
@ -345,8 +353,7 @@ class Update {
echo T_('No updates needed.');
if (!defined('CLI')) {
echo '[<a href="', Config::get('web_path'), '">Return</a>]</p>';
}
else {
} else {
echo "\n";
}
}
@ -359,8 +366,8 @@ class Update {
* that need to be run. Checking to make sure
* the function exists first.
*/
public static function run_update() {
public static function run_update()
{
/* Nuke All Active session before we start the mojo */
$sql = "TRUNCATE session";
$db_results = Dba::write($sql);
@ -398,8 +405,7 @@ class Update {
// If the update fails drop out
if ($success) {
self::set_version('db_version', $version['version']);
}
else {
} else {
Error::display('update');
return false;
}
@ -424,7 +430,8 @@ class Update {
* This updates the 'update_info' which is used by the updater
* and plugins
*/
private static function set_version($key, $value) {
private static function set_version($key, $value)
{
$sql = "UPDATE update_info SET value='$value' WHERE `key`='$key'";
Dba::write($sql);
}
@ -436,7 +443,8 @@ class Update {
* minor changes to the song table in an attempt to reduce
* the size of each row
*/
public static function update_340003() {
public static function update_340003()
{
$retval = true;
$sql = "ALTER TABLE `song` CHANGE `mode` `mode` ENUM( 'abr', 'vbr', 'cbr' ) NULL DEFAULT 'cbr'";
$retval = Dba::write($sql) ? $retval : false;
@ -524,7 +532,8 @@ class Update {
* Update the session.id to varchar(64) to handle
* newer configs
*/
public static function update_340004() {
public static function update_340004()
{
$retval = true;
/* Alter the session.id so that it's 64 */
$sql = "ALTER TABLE `session` CHANGE `id` `id` VARCHAR( 64 ) NOT NULL";
@ -577,7 +586,8 @@ class Update {
* update_340005
* This update fixes the preferences types
*/
public static function update_340005() {
public static function update_340005()
{
$retval = true;
$sql = "UPDATE `preference` SET `catagory`='playlist' WHERE `name`='random_method'";
@ -609,7 +619,8 @@ class Update {
* This just updates the size of the album_data table
* and removes the random_method config option
*/
public static function update_340006() {
public static function update_340006()
{
// No matter what remove that random method preference
Dba::write("DELETE FROM `preference` WHERE `name`='random_method'");
return true;
@ -620,7 +631,8 @@ class Update {
* This update converts the session.value to a longtext
* and adds a session_stream table
*/
public static function update_340007() {
public static function update_340007()
{
$retval = true;
// Tweak the session table to handle larger session vars for my page-a-nation hotness
$sql = "ALTER TABLE `session` CHANGE `value` `value` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL";
@ -641,7 +653,8 @@ class Update {
* This modifies the playlist table to handle the different types of objects that it needs to be able to
* store, and tweaks how dynamic playlist stuff works
*/
public static function update_340008() {
public static function update_340008()
{
$retval = true;
$sql = "ALTER TABLE `playlist_data` CHANGE `song` `object_id` INT( 11 ) UNSIGNED NULL DEFAULT NULL";
$retval = Dba::write($sql) ? $retval : false;
@ -679,7 +692,8 @@ class Update {
* update_340009
* This modifies the song table to handle pos fields
*/
public static function update_340009() {
public static function update_340009()
{
$retval = true;
$sql = "ALTER TABLE `album` ADD `disk` smallint(5) UNSIGNED DEFAULT NULL";
$retval = Dba::write($sql) ? $retval : false;
@ -707,7 +721,8 @@ class Update {
* update_340010
* Bunch of minor tweaks to the preference table
*/
public static function update_340010() {
public static function update_340010()
{
$retval = true;
$sql = "UPDATE `preference` SET `catagory`='options' WHERE `name` LIKE 'localplay_%'";
$retval = Dba::write($sql) ? $retval : false;
@ -732,7 +747,8 @@ class Update {
* This update adds in the democratic stuff, checks for some potentially screwed up indexes
* and removes the timestamp from the playlist, and adds the field to the catalog for the upload dir
*/
public static function update_340012() {
public static function update_340012()
{
$retval = true;
$sql = "ALTER TABLE `catalog` ADD `add_path` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL AFTER `path`";
$retval = Dba::write($sql) ? $retval : false;
@ -761,7 +777,8 @@ class Update {
* This update removes a whole bunch of preferences that are no longer
* being used in any way, and changes the ACL XML-RPC to just RPC
*/
public static function update_340013() {
public static function update_340013()
{
$sql = "DELETE FROM `preference` WHERE `name`='localplay_mpd_hostname' OR `name`='localplay_mpd_port' " .
"OR `name`='direct_link' OR `name`='localplay_mpd_password' OR `name`='catalog_echo_count'";
$db_results = Dba::write($sql);
@ -784,7 +801,8 @@ class Update {
* at the same time it updates the core session table to handle the
* additional stuff we're going to ask it to do.
*/
public static function update_340014() {
public static function update_340014()
{
$retval = true;
$sql = "DROP TABLE IF EXISTS `session_api`";
$retval = Dba::write($sql) ? $retval : false;
@ -808,7 +826,8 @@ class Update {
* who say it doesn't work, unreproduceable. This also adds an index to the
* album art table to try to make the random album art faster
*/
public static function update_340015() {
public static function update_340015()
{
$retval = true;
$sql = "ALTER TABLE `playlist` DROP `date`";
$retval = Dba::write($sql) ? $retval : false;
@ -848,7 +867,8 @@ class Update {
* This adds in the base_playlist to the democratic table... should have
* done this in the previous one but I screwed up... sigh.
*/
public static function update_340016() {
public static function update_340016()
{
$sql = "ALTER TABLE `democratic` ADD `base_playlist` INT ( 11 ) UNSIGNED NOT NULL AFTER `name`";
return Dba::write($sql);
}
@ -859,7 +879,8 @@ class Update {
* This finalizes the democratic table.
* And fixes the charset crap.
*/
public static function update_340017() {
public static function update_340017()
{
$retval = true;
$sql = "ALTER TABLE `tmp_playlist` DROP `base_playlist`";
@ -882,7 +903,8 @@ class Update {
*
* It also adjusts the prefix fields so that we can use more prefixes,
*/
public static function update_350001() {
public static function update_350001()
{
$retval = true;
$sql = "ALTER TABLE `tag_map` ADD `tag_id` INT ( 11 ) UNSIGNED NOT NULL AFTER `id`";
$retval = Dba::write($sql) ? $retval : false;
@ -910,7 +932,8 @@ class Update {
* we split them out into one serialized array per row, per person. A little
* slow this way when browsing, but faster and more flexible when not.
*/
public static function update_350002() {
public static function update_350002()
{
$retval = true;
$sql = "ALTER TABLE `song` DROP `genre`";
@ -933,7 +956,8 @@ class Update {
* simplify things for the first little bit and then if it all works out
* we will worry about making it complex again. One thing at a time people...
*/
public static function update_350003() {
public static function update_350003()
{
$retval = true;
$sql = "ALTER TABLE `tag` DROP `order`";
@ -958,7 +982,8 @@ class Update {
* This update makes some changes to the ACL table so that it can support
* IPv6 entries as well as some other feature enhancements.
*/
public static function update_350004() {
public static function update_350004()
{
$retval = true;
$sql = "ALTER TABLE `session` CHANGE `ip` `ip` VARBINARY( 255 ) NULL";
@ -1061,7 +1086,8 @@ class Update {
*
* This update adds the video table... *gasp* no you didn't <head shake>
*/
public static function update_350005() {
public static function update_350005()
{
$retval = true;
$sql = " CREATE TABLE `video` (" .
@ -1100,7 +1126,8 @@ class Update {
*
* This update inserts the Lyrics pref table...
*/
public static function update_350006() {
public static function update_350006()
{
$sql = "INSERT INTO `preference` VALUES (69,'show_lyrics','0','Show Lyrics',0,'boolean','interface')";
Dba::write($sql);
@ -1116,7 +1143,8 @@ class Update {
* This update adds in the random rules tables. Also increase the size of the
* blobs on the album and artist data and add track to tmp_playlist_data
*/
public static function update_350007() {
public static function update_350007()
{
$retval = true;
// We need to clear the thumbs as they will need to be re-generated
@ -1176,7 +1204,8 @@ class Update {
* Add type to the now playing table so that we can handle different playing
* information.
*/
public static function update_350008() {
public static function update_350008()
{
$retval = true;
$sql = "ALTER TABLE `now_playing` CHANGE `song_id` `object_id` INT( 11 ) UNSIGNED NOT NULL";
$retval = Dba::write($sql) ? $retval : false;
@ -1211,7 +1240,8 @@ class Update {
* This adds the MB UUIDs to the different tables as well as some additional
* cleanup.
*/
public static function update_360001() {
public static function update_360001()
{
$retval = true;
$sql = "ALTER TABLE `album` ADD `mbid` CHAR ( 36 ) AFTER `prefix`";
@ -1239,7 +1269,8 @@ class Update {
* This update makes changes to the cataloging to accomodate the new method
* for syncing between Ampache instances.
*/
public static function update_360002() {
public static function update_360002()
{
$retval = true;
// Drop the key from catalog and ACL
$sql = "ALTER TABLE `catalog` DROP `key`";
@ -1294,7 +1325,8 @@ class Update {
*
* This update moves the image data to its own table.
*/
public static function update_360003() {
public static function update_360003()
{
$sql = "CREATE TABLE `image` (" .
"`id` int(11) unsigned NOT NULL auto_increment," .
"`image` mediumblob NOT NULL," .
@ -1335,7 +1367,8 @@ class Update {
*
* This update creates an index on the rating table.
*/
public static function update_360004() {
public static function update_360004()
{
$sql = "CREATE UNIQUE INDEX `unique_rating` ON `rating` (`user`, `object_type`, `object_id`)";
return Dba::write($sql);
}
@ -1345,7 +1378,8 @@ class Update {
*
* This changes the tmp_browse table around.
*/
public static function update_360005() {
public static function update_360005()
{
$retval = true;
$sql = "DROP TABLE IF EXISTS `tmp_browse`";
@ -1368,7 +1402,8 @@ class Update {
*
* This adds the table for newsearch/dynamic playlists
*/
public static function update_360006() {
public static function update_360006()
{
$sql = "CREATE TABLE `search` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user` int(11) NOT NULL,
@ -1387,7 +1422,8 @@ class Update {
* Fix bug that caused the remote_username/password fields to not be created.
* FIXME: Huh?
*/
public static function update_360008() {
public static function update_360008()
{
$retval = true;
$remote_username = false;
$remote_password = false;
@ -1423,7 +1459,8 @@ class Update {
* The main session table was already updated to use varchar(64) for the ID,
* tmp_playlist needs the same change
*/
public static function update_360009() {
public static function update_360009()
{
$sql = "ALTER TABLE `tmp_playlist` CHANGE `session` `session` VARCHAR(64)";
return Dba::write($sql);
}
@ -1434,7 +1471,8 @@ class Update {
* MBz NGS means collaborations have more than one MBID (the ones
* belonging to the underlying artists). We need a bigger column.
*/
public static function update_360010() {
public static function update_360010()
{
$sql = 'ALTER TABLE `artist` CHANGE `mbid` `mbid` VARCHAR(1369)';
return Dba::write($sql);
}
@ -1445,7 +1483,8 @@ class Update {
* We need a place to store actual playlist data for downloadable
* playlist files.
*/
public static function update_360011() {
public static function update_360011()
{
$sql = 'CREATE TABLE `stream_playlist` (' .
'`id` int(11) unsigned NOT NULL AUTO_INCREMENT,' .
'`sid` varchar(64) NOT NULL,' .
@ -1466,7 +1505,8 @@ class Update {
*
* Drop the enum on session.type
*/
public static function update_360012() {
public static function update_360012()
{
return Dba::write('ALTER TABLE `session` CHANGE `type` `type` VARCHAR(16) DEFAULT NULL');
}
@ -1475,7 +1515,8 @@ class Update {
*
* MyISAM works better out of the box for the stream_playlist table
*/
public static function update_360013() {
public static function update_360013()
{
return Dba::write('ALTER TABLE `stream_playlist` ENGINE=MyISAM');
}
@ -1484,7 +1525,8 @@ class Update {
*
* PHP session IDs are an ever-growing beast.
*/
public static function update_360014() {
public static function update_360014()
{
$retval = true;
$retval = Dba::write('ALTER TABLE `stream_playlist` CHANGE `sid` `sid` VARCHAR(256)') ? $retval : false;
@ -1499,7 +1541,8 @@ class Update {
*
* This inserts the Iframes preference...
*/
public static function update_360015() {
public static function update_360015()
{
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('iframes','0','Iframes',25,'boolean','interface')";
Dba::write($sql);
@ -1517,7 +1560,8 @@ class Update {
*
* Add Now Playing filtered per user preference option
*/
public static function update_360016() {
public static function update_360016()
{
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('now_playing_per_user','0','Now playing filtered per user',50,'boolean','interface')";
Dba::write($sql);
@ -1535,7 +1579,8 @@ class Update {
*
* New table to store user flags.
*/
public static function update_360017() {
public static function update_360017()
{
$sql = "CREATE TABLE `user_flag` (" .
"`id` int(11) unsigned NOT NULL AUTO_INCREMENT," .
"`user` int(11) NOT NULL," .
@ -1553,7 +1598,8 @@ class Update {
*
* This inserts the Album default sort preference...
*/
public static function update_360018() {
public static function update_360018()
{
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('album_sort','0','Album Default Sort',25,'string','interface')";
Dba::write($sql);
@ -1571,7 +1617,8 @@ class Update {
*
* Add Show number of times a song was played preference
*/
public static function update_360019() {
public static function update_360019()
{
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('show_played_times','0','Show # played',25,'string','interface')";
Dba::write($sql);
@ -1583,5 +1630,69 @@ class Update {
return true;
}
/**
* update_360020
*
* Catalog types are plugins now
*/
public static function update_360020()
{
$sql = "SELECT `id`, `catalog_type`, `path`, `remote_username`, `remote_password` FROM `catalog`";
$db_results = Dba::read($sql);
$c = Catalog::create_catalog_type('local');
$c->install();
$c = Catalog::create_catalog_type('remote');
$c->install();
while ($results = Dba::fetch_assoc($db_results)) {
if ($results['catalog_type'] == 'local') {
$sql = "INSERT INTO `catalog_local` (`path`, `catalog_id`) VALUES (?, ?)";
Dba::write($sql, array($results['path'], $results['id']));
} elseif ($results['catalog_type'] == 'remote') {
$sql = "INSERT INTO `catalog_remote` (`uri`, `username`, `password`, `catalog_id`) VALUES (?, ?, ?, ?)";
Dba::write($sql, array($results['path'], $results['remote_username'], $results['remote_password'], $results['id']));
}
}
$sql = "ALTER TABLE `catalog` DROP `path`, DROP `remote_username`, DROP `remote_password`";
$retval = Dba::write($sql);
$sql = "ALTER TABLE `catalog` MODIFY COLUMN `catalog_type` varchar(128)";
$retval = Dba::write($sql);
$sql = "UPDATE `artist` SET `mbid` = null WHERE `mbid` = ''";
Dba::write($sql);
$sql = "UPDATE `album` SET `mbid` = null WHERE `mbid` = ''";
Dba::write($sql);
$sql = "UPDATE `song` SET `mbid` = null WHERE `mbid` = ''";
Dba::write($sql);
return true;
}
/**
* update_360021
*
* Add insertion date on Now Playing and option to show the current song in page title for HTML5 player
*/
public static function update_360021()
{
$sql = "ALTER TABLE `now_playing` ADD `insertion` INT (11) AFTER `expire`";
Dba::write($sql);
$sql = "INSERT INTO `preference` (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
"VALUES ('song_page_title','0','Show current song in HTML5 player page title',25,'string','interface')";
$retval = Dba::write($sql);
$id = Dba::insert_id();
$sql = "INSERT INTO `user_preference` VALUES (-1,?,'0')";
$retval = Dba::write($sql, array($id));
return $retval;
}
}
?>

View file

@ -28,8 +28,8 @@
* with a user_id from user.id
*
*/
class User extends database_object {
class User extends database_object
{
//Basic Componets
public $id;
public $username;
@ -49,8 +49,8 @@ class User extends database_object {
* This function is the constructor object for the user
* class, it currently takes a username
*/
public function __construct($user_id=0) {
public function __construct($user_id=0)
{
if (!$user_id) { return false; }
$this->id = intval($user_id);
@ -73,7 +73,8 @@ class User extends database_object {
*
* This returns the number of user accounts that exist.
*/
public static function count() {
public static function count()
{
$sql = 'SELECT COUNT(`id`) FROM `user`';
$db_results = Dba::read($sql);
$data = Dba::fetch_row($db_results);
@ -94,8 +95,8 @@ class User extends database_object {
* _get_info
* This function returns the information for this object
*/
private function _get_info() {
private function _get_info()
{
$id = intval($this->id);
if (parent::is_cached('user',$id)) {
@ -127,8 +128,8 @@ class User extends database_object {
* has a tmp_playlist, creating it if it doesn't, then sets $this->playlist
* as a tmp_playlist object that can be fiddled with later on
*/
public function load_playlist() {
public function load_playlist()
{
$session_id = session_id();
$this->playlist = Tmp_Playlist::get_from_session($session_id);
@ -140,8 +141,8 @@ class User extends database_object {
* This returns a built user from a username. This is a
* static function so it doesn't require an instance
*/
public static function get_from_username($username) {
public static function get_from_username($username)
{
$username = Dba::escape($username);
$sql = "SELECT `id` FROM `user` WHERE `username`='$username'";
@ -159,8 +160,8 @@ class User extends database_object {
* This returns a built user from a email. This is a
* static function so it doesn't require an instance
*/
public static function get_from_email($email) {
public static function get_from_email($email)
{
$email = Dba::escape($email);
$sql = "SELECT `id` FROM `user` WHERE `email`='$email'";
@ -177,8 +178,8 @@ class User extends database_object {
* get_catalogs
* This returns the catalogs as an array of ids that this user is allowed to access
*/
public function get_catalogs() {
public function get_catalogs()
{
if (parent::is_cached('user_catalog',$this->id)) {
return parent::get_from_cache('user_catalog',$this->id);
}
@ -205,8 +206,8 @@ class User extends database_object {
* []['prefs'] = array(array('name','display','value'));
* []['admin'] = t/f value if this is an admin only section
*/
function get_preferences($type = 0, $system = false) {
public function get_preferences($type = 0, $system = false)
{
// Fill out the user id
$user_id = $system ? Dba::escape(-1) : Dba::escape($this->id);
@ -243,8 +244,8 @@ class User extends database_object {
* set_preferences
* sets the prefs for this specific user
*/
public function set_preferences() {
public function set_preferences()
{
$user_id = Dba::escape($this->id);
$sql = "SELECT preference.name,user_preference.value FROM preference,user_preference WHERE user_preference.user='$user_id' " .
@ -261,8 +262,8 @@ class User extends database_object {
* get_favorites
* returns an array of your $type favorites
*/
function get_favorites($type) {
public function get_favorites($type)
{
$web_path = Config::get('web_path');
$results = Stats::get_user(Config::get('popular_threshold'),$type,$this->id,1);
@ -313,8 +314,8 @@ class User extends database_object {
* This returns recommended objects of $type. The recommendations
* are based on voodoo economics,the phase of the moon and my current BAL.
*/
function get_recommendations($type) {
public function get_recommendations($type)
{
/* First pull all of your ratings of this type */
$sql = "SELECT object_id,user_rating FROM ratings " .
"WHERE object_type='" . Dba::escape($type) . "' AND user='" . Dba::escape($this->id) . "'";
@ -379,8 +380,8 @@ class User extends database_object {
* checks to see if $this user is logged in returns their current IP if they
* are logged in
*/
public function is_logged_in() {
public function is_logged_in()
{
$username = Dba::escape($this->username);
$sql = "SELECT `id`,`ip` FROM `session` WHERE `username`='$username'" .
@ -401,8 +402,8 @@ class User extends database_object {
* this function checkes to see if this user has access
* to the passed action (pass a level requirement)
*/
function has_access($needed_level) {
public function has_access($needed_level)
{
if (!Config::get('use_auth') || Config::get('demo_mode')) { return true; }
if ($this->access >= $needed_level) { return true; }
@ -417,7 +418,8 @@ class User extends database_object {
* calls the mini ones does all the error checking and all that
* good stuff
*/
public function update($data) {
public function update($data)
{
if (empty($data['username'])) {
Error::add('username', T_('Error Username Required'));
}
@ -433,8 +435,7 @@ class User extends database_object {
foreach ($data as $name => $value) {
if ($name == 'password1') {
$name = 'password';
}
else {
} else {
$value = scrub_in($value);
}
@ -462,8 +463,8 @@ class User extends database_object {
* update_username
* updates their username
*/
public function update_username($new_username) {
public function update_username($new_username)
{
$new_username = Dba::escape($new_username);
$sql = "UPDATE `user` SET `username`='$new_username' WHERE `id`='$this->id'";
$this->username = $new_username;
@ -477,8 +478,8 @@ class User extends database_object {
* Use this function to update the validation key
* NOTE: crap this doesn't have update_item the humanity of it all
*/
public function update_validation($new_validation) {
public function update_validation($new_validation)
{
$new_validation = Dba::escape($new_validation);
$sql = "UPDATE `user` SET `validation`='$new_validation', `disabled`='1' WHERE `id`='" . Dba::escape($this->id) . "'";
$db_results = Dba::write($sql);
@ -492,8 +493,8 @@ class User extends database_object {
* update_fullname
* updates their fullname
*/
public function update_fullname($new_fullname) {
public function update_fullname($new_fullname)
{
$new_fullname = Dba::escape($new_fullname);
$sql = "UPDATE `user` SET `fullname`='$new_fullname' WHERE `id`='$this->id'";
$db_results = Dba::write($sql);
@ -504,8 +505,8 @@ class User extends database_object {
* update_email
* updates their email address
*/
public function update_email($new_email) {
public function update_email($new_email)
{
$new_email = Dba::escape($new_email);
$sql = "UPDATE `user` SET `email`='$new_email' WHERE `id`='$this->id'";
$db_results = Dba::write($sql);
@ -516,8 +517,8 @@ class User extends database_object {
* disable
* This disables the current user
*/
public function disable() {
public function disable()
{
// Make sure we aren't disabling the last admin
$sql = "SELECT `id` FROM `user` WHERE `disabled` = '0' AND `id` != '" . $this->id . "' AND `access`='100'";
$db_results = Dba::read($sql);
@ -539,8 +540,8 @@ class User extends database_object {
* enable
* this enables the current user
*/
public function enable() {
public function enable()
{
$sql = "UPDATE `user` SET `disabled`='0' WHERE id='" . $this->id . "'";
$db_results = Dba::write($sql);
@ -552,8 +553,8 @@ class User extends database_object {
* update_access
* updates their access level
*/
public function update_access($new_access) {
public function update_access($new_access)
{
/* Prevent Only User accounts */
if ($new_access < '100') {
$sql = "SELECT `id` FROM user WHERE `access`='100' AND `id` != '$this->id'";
@ -571,8 +572,8 @@ class User extends database_object {
@function update_last_seen
@discussion updates the last seen data for this user
*/
function update_last_seen() {
public function update_last_seen()
{
$sql = "UPDATE user SET last_seen='" . time() . "' WHERE `id`='$this->id'";
$db_results = Dba::write($sql);
@ -582,8 +583,8 @@ class User extends database_object {
* update_user_stats
* updates the playcount mojo for this specific user
*/
public function update_stats($song_id) {
public function update_stats($song_id)
{
$song_info = new Song($song_id);
$song_info->format();
$user = $this->id;
@ -613,13 +614,12 @@ class User extends database_object {
* This inserts a row into the IP History recording this user at this
* address at this time in this place, doing this thing.. you get the point
*/
public function insert_ip_history() {
public function insert_ip_history()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$sip = $_SERVER['HTTP_X_FORWARDED_FOR'];
debug_event('User Ip', 'Login from ip adress: ' . $sip,'3');
}
else {
} else {
$sip = $_SERVER['REMOTE_ADDR'];
debug_event('User Ip', 'Login from ip adress: ' . $sip,'3');
}
@ -647,8 +647,8 @@ class User extends database_object {
* create
* inserts a new user into ampache
*/
public static function create($username, $fullname, $email, $password, $access, $disabled = false) {
public static function create($username, $fullname, $email, $password, $access, $disabled = false)
{
/* Lets clean up the fields... */
$username = Dba::escape($username);
$fullname = Dba::escape($fullname);
@ -681,8 +681,8 @@ class User extends database_object {
* update_password
* updates a users password
*/
public function update_password($new_password) {
public function update_password($new_password)
{
$new_password = hash('sha256',$new_password);
$new_password = Dba::escape($new_password);
@ -700,15 +700,13 @@ class User extends database_object {
* user for an admin, these should not be normally called when creating a
* user object
*/
public function format() {
public function format()
{
/* If they have a last seen date */
if (!$this->last_seen) { $this->f_last_seen = T_('Never'); }
else { $this->f_last_seen = date("m\/d\/Y - H:i",$this->last_seen); }
if (!$this->last_seen) { $this->f_last_seen = T_('Never'); } else { $this->f_last_seen = date("m\/d\/Y - H:i",$this->last_seen); }
/* If they have a create date */
if (!$this->create_date) { $this->f_create_date = T_('Unknown'); }
else { $this->f_create_date = date("m\/d\/Y - H:i",$this->create_date); }
if (!$this->create_date) { $this->f_create_date = T_('Unknown'); } else { $this->f_create_date = date("m\/d\/Y - H:i",$this->create_date); }
// Base link
$this->f_link = '<a href="' . Config::get('web_path') . '/stats.php?action=show_user&user_id=' . $this->id . '">' . $this->fullname . '</a>';
@ -727,8 +725,7 @@ class User extends database_object {
/* Get Users Last ip */
if (count($data = $this->get_ip_history(1))) {
$this->ip_history = inet_ntop($data['0']['ip']);
}
else {
} else {
$this->ip_history = T_('Not Enough Data');
}
@ -739,8 +736,8 @@ class User extends database_object {
* takes an array of objects and formats them corrrectly
* and returns a simply array with just <a href values
*/
public function format_favorites($items) {
public function format_favorites($items)
{
// The length of the longest item
$maxlen = strlen($items[0]->count);
@ -767,8 +764,8 @@ class User extends database_object {
* This takes an array of [object_id] = ratings
* and displays them in a semi-pretty format
*/
function format_recommendations($items,$type) {
function format_recommendations($items,$type)
{
foreach ($items as $object_id=>$rating) {
switch ($type) {
@ -801,8 +798,8 @@ class User extends database_object {
* access_name_to_level
* This takes the access name for the user and returns the level
*/
public static function access_name_to_level($level) {
public static function access_name_to_level($level)
{
switch ($level) {
case 'admin':
return '100';
@ -832,8 +829,8 @@ class User extends database_object {
* If -1 is passed it also removes duplicates from the `preferences`
* table.
*/
public static function fix_preferences($user_id) {
public static function fix_preferences($user_id)
{
$user_id = Dba::escape($user_id);
/* Get All Preferences for the current user */
@ -916,8 +913,8 @@ class User extends database_object {
* deletes this user and everything associated with it. This will affect
* ratings and tottal stats
*/
public function delete() {
public function delete()
{
/*
Before we do anything make sure that they aren't the last
admin
@ -993,8 +990,8 @@ class User extends database_object {
* calcs difference between now and last_seen
* if less than delay, we consider them still online
*/
public function is_online( $delay = 1200 ) {
public function is_online( $delay = 1200 )
{
return time() - $this->last_seen <= $delay;
} // is_online
@ -1003,8 +1000,8 @@ class User extends database_object {
* get_user_validation
*if user exists before activation can be done.
*/
public static function get_validation($username) {
public static function get_validation($username)
{
$usename = Dba::escape($username);
$sql = "SELECT `validation` FROM `user` WHERE `username`='$username'";
@ -1021,8 +1018,8 @@ class User extends database_object {
* This gets the recently played items for this user respecting
* the limit passed
*/
public function get_recently_played($limit,$type='') {
public function get_recently_played($limit,$type='')
{
if (!$type) { $type = 'song'; }
$sql = "SELECT * FROM `object_count` WHERE `object_type`='$type' AND `user`='$this->id' " .
@ -1042,8 +1039,8 @@ class User extends database_object {
* This returns the ip_history from the
* last Config::get('user_ip_cardinality') days
*/
public function get_ip_history($count='',$distinct='') {
public function get_ip_history($count='',$distinct='')
{
$username = Dba::escape($this->id);
$count = $count ? intval($count) : intval(Config::get('user_ip_cardinality'));
@ -1073,8 +1070,8 @@ class User extends database_object {
* activate_user
* the user from public_registration
*/
public function activate_user($username) {
public function activate_user($username)
{
$username = Dba::escape($username);
$sql = "UPDATE `user` SET `disabled`='0' WHERE `username`='$username'";
@ -1086,8 +1083,8 @@ class User extends database_object {
* is_xmlrpc
* checks to see if this is a valid xmlrpc user
*/
public function is_xmlrpc() {
public function is_xmlrpc()
{
/* If we aren't using XML-RPC return true */
if (!Config::get('xml_rpc')) {
return false;
@ -1105,8 +1102,8 @@ class User extends database_object {
* This checks to make sure the username passed doesn't already
* exist in this instance of ampache
*/
public static function check_username($username) {
public static function check_username($username)
{
$username = Dba::escape($username);
$sql = "SELECT `id` FROM `user` WHERE `username`='$username'";
@ -1124,8 +1121,8 @@ class User extends database_object {
* rebuild_all_preferences
* This rebuilds the user preferences for all installed users, called by the plugin functions
*/
public static function rebuild_all_preferences() {
public static function rebuild_all_preferences()
{
$sql = "SELECT * FROM `user`";
$db_results = Dba::read($sql);
@ -1140,4 +1137,3 @@ class User extends database_object {
} // rebuild_all_preferences
} //end user class
?>

View file

@ -26,8 +26,8 @@
* This user flag/unflag songs, albums and artists.
*
*/
class Userflag extends database_object {
class Userflag extends database_object
{
// Public variables
public $id; // The ID of the object flagged
public $type; // The type of object we want
@ -37,8 +37,8 @@ class Userflag extends database_object {
* This is run every time a new object is created, and requires
* the id and type of object that we need to pull the flag for
*/
public function __construct($id, $type) {
public function __construct($id, $type)
{
$this->id = intval($id);
$this->type = $type;
@ -51,8 +51,8 @@ class Userflag extends database_object {
* This attempts to get everything we'll need for this page load in a
* single query, saving on connection overhead
*/
public static function build_cache($type, $ids, $user_id = null) {
public static function build_cache($type, $ids, $user_id = null)
{
if (!is_array($ids) OR !count($ids)) { return false; }
if (is_null($user_id)) {
@ -74,8 +74,7 @@ class Userflag extends database_object {
foreach ($ids as $id) {
if (!isset($userflags[$id])) {
$userflag = 0;
}
else {
} else {
$userflag = intval($user_ratings[$id]);
}
parent::add_to_cache('userflag_' . $type . '_user' . $user_id, $id, $userflag);
@ -90,14 +89,15 @@ class Userflag extends database_object {
*
* Remove userflag for items that no longer exist.
*/
public static function gc() {
public static function gc()
{
foreach (array('song', 'album', 'artist', 'video') as $object_type) {
Dba::write("DELETE FROM `user_flag` USING `user_flag` LEFT JOIN `$object_type` ON `$object_type`.`id` = `user_flag`.`object_id` WHERE `object_type` = '$object_type' AND `$object_type`.`id` IS NULL");
}
}
public function get_flag($user_id = null) {
public function get_flag($user_id = null)
{
if (is_null($user_id)) {
$user_id = $GLOBALS['user']->id;
}
@ -126,8 +126,8 @@ class Userflag extends database_object {
* This function sets the user flag for the current object.
* If no userid is passed in, we use the currently logged in user.
*/
public function set_flag($flagged, $user_id = null) {
public function set_flag($flagged, $user_id = null)
{
if (is_null($user_id)) {
$user_id = $GLOBALS['user']->id;
}
@ -141,8 +141,7 @@ class Userflag extends database_object {
"`object_type` = ? AND " .
"`user` = ?";
$params = array($this->id, $this->type, $user_id);
}
else {
} else {
$sql = "REPLACE INTO `user_flag` " .
"(`object_id`, `object_type`, `user`, `date`) " .
"VALUES (?, ?, ?, ?)";
@ -160,8 +159,8 @@ class Userflag extends database_object {
* get_latest
* Get the latest user flagged objects
*/
public static function get_latest($type, $user_id=null, $count='', $offset='') {
public static function get_latest($type, $user_id=null, $count='', $offset='')
{
if (is_null($user_id)) {
$user_id = $GLOBALS['user']->id;
}
@ -198,8 +197,8 @@ class Userflag extends database_object {
* This takes an id and a type and displays the flag state
* enabled.
*/
public static function show($object_id, $type) {
public static function show($object_id, $type)
{
// If user flags aren't enabled don't do anything
if (!Config::get('userflags')) { return false; }
@ -209,4 +208,3 @@ class Userflag extends database_object {
} // show
} //end rating class
?>

View file

@ -26,8 +26,8 @@
* Ampache-friendly way.
*
*/
class vainfo {
class vainfo
{
public $encoding = '';
public $encoding_id3v1 = '';
public $encoding_id3v2 = '';
@ -38,6 +38,7 @@ class vainfo {
protected $_raw = array();
protected $_getID3 = '';
protected $_forcedSize = 0;
protected $_file_encoding = '';
protected $_file_pattern = '';
@ -52,8 +53,9 @@ class vainfo {
* This function just sets up the class, it doesn't pull the information.
*
*/
public function __construct($file, $encoding = null, $encoding_id3v1 = null, $encoding_id3v2 = null, $dir_pattern, $file_pattern) {
public function __construct($file, $encoding = null, $encoding_id3v1 = null, $encoding_id3v2 = null, $dir_pattern = '', $file_pattern ='', $islocal = true)
{
$this->islocal = $islocal;
$this->filename = $file;
$this->encoding = $encoding ?: Config::get('site_charset');
@ -65,12 +67,12 @@ class vainfo {
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
$this->_pathinfo = str_replace('%3A', ':', urlencode($this->filename));
$this->_pathinfo = pathinfo(str_replace('%5C', '\\', $this->_pathinfo));
}
else {
} else {
$this->_pathinfo = pathinfo(str_replace('%2F', '/', urlencode($this->filename)));
}
$this->_pathinfo['extension'] = strtolower($this->_pathinfo['extension']);
if ($this->islocal) {
// Initialize getID3 engine
$this->_getID3 = new getID3();
@ -85,8 +87,7 @@ class vainfo {
// get id3tag encoding (try to work around off-spec id3v1 tags)
try {
$this->_raw = $this->_getID3->analyze($file);
}
catch (Exception $error) {
} catch (Exception $error) {
debug_event('getID3', "Broken file detected: $file: " . $error->message, 1);
$this->_broken = true;
return false;
@ -94,11 +95,9 @@ class vainfo {
if (Config::get('mb_detect_order')) {
$mb_order = Config::get('mb_detect_order');
}
elseif (function_exists('mb_detect_order')) {
} elseif (function_exists('mb_detect_order')) {
$mb_order = implode(", ", mb_detect_order());
}
else {
} else {
$mb_order = "auto";
}
@ -106,8 +105,7 @@ class vainfo {
if ($encoding_id3v1) {
$this->encoding_id3v1 = $encoding_id3v1;
}
else {
} else {
foreach ($test_tags as $tag) {
if ($value = $this->_raw['id3v1'][$tag]) {
$tags[$tag] = $value;
@ -131,6 +129,12 @@ class vainfo {
$this->_getID3->encoding_id3v1 = $this->encoding_id3v1;
}
}
public function forceSize($size)
{
$this->_forcedSize = $size;
}
/**
* _detect_encoding
@ -138,12 +142,15 @@ class vainfo {
* Takes an array of tags and attempts to automatically detect their
* encoding.
*/
private static function _detect_encoding($tags, $mb_order) {
private static function _detect_encoding($tags, $mb_order)
{
if (function_exists('mb_detect_encoding')) {
$encodings = array();
if (is_array($tags)) {
foreach ($tags as $tag) {
$encodings[mb_detect_encoding($tag, $mb_order, true)]++;
}
}
debug_event('vainfo', 'encoding detection: ' . json_encode($encodings), 5);
$high = 0;
@ -156,8 +163,7 @@ class vainfo {
if ($encoding != 'ASCII' && $encoding != '0') {
return $encoding;
}
else {
} else {
return 'ISO-8859-1';
}
}
@ -170,7 +176,8 @@ class vainfo {
*
* This function runs the various steps to gathering the metadata
*/
public function get_info() {
public function get_info()
{
// If this is broken, don't waste time figuring it out a second
// time, just return their rotting carcass of a media file.
if ($this->_broken) {
@ -178,12 +185,13 @@ class vainfo {
return true;
}
if ($this->islocal) {
try {
$this->_raw = $this->_getID3->analyze($this->filename);
}
catch (Exception $error) {
} catch (Exception $error) {
debug_event('getID2', 'Unable to catalog file: ' . $error->message, 1);
}
}
/* Figure out what type of file we are dealing with */
$this->type = $this->_get_type();
@ -194,7 +202,7 @@ class vainfo {
$this->tags['filename'] = $this->_parse_filename($this->filename);
}
if (in_array('getID3', $enabled_sources)) {
if (in_array('getID3', $enabled_sources) && $this->islocal) {
$this->tags['getID3'] = $this->_get_tags();
}
@ -210,7 +218,8 @@ class vainfo {
* tag_order doesn't match anything then it throws up its hands and uses
* everything in random order.
*/
public static function get_tag_type($results, $config_key = 'metadata_order') {
public static function get_tag_type($results, $config_key = 'metadata_order')
{
$order = (array) Config::get($config_key);
// Iterate through the defined key order adding them to an ordered array.
@ -227,9 +236,11 @@ class vainfo {
}
// Unless they explicitly set it, add bitrate/mode/mime/etc.
if (is_array($returned_keys)) {
if (!in_array('general', $returned_keys)) {
$returned_keys[] = 'general';
}
}
return $returned_keys;
}
@ -241,7 +252,8 @@ class vainfo {
* key we've decided on and the filename and returns it in a
* sanitized format that ampache can actually use
*/
public static function clean_tag_info($results, $keys, $filename = null) {
public static function clean_tag_info($results, $keys, $filename = null)
{
$info = array();
$info['file'] = $filename;
@ -278,8 +290,7 @@ class vainfo {
if (!is_array($tags['genre'])) {
// not all tag formats will return an array, but we need one
$info['genre'][] = trim($tags['genre']);
}
else {
} else {
// if we trim the array we lose everything after 1st entry
foreach ($tags['genre'] as $genre) {
$info['genre'][] = trim($genre);
@ -321,7 +332,8 @@ class vainfo {
* This function takes the raw information and figures out what type of
* file we are dealing with.
*/
private function _get_type() {
private function _get_type()
{
// There are a few places that the file type can come from, in the end
// we trust the encoding type.
if ($type = $this->_raw['video']['dataformat']) {
@ -346,13 +358,14 @@ class vainfo {
*
* This processes the raw getID3 output and bakes it.
*/
private function _get_tags() {
private function _get_tags()
{
$results = array();
// The tags can come in many different shapes and colors
// depending on the encoding time of day and phase of the moon.
if (is_array($this->_raw['tags'])) {
foreach ($this->_raw['tags'] as $key => $tag_array) {
switch ($key) {
case 'ape':
@ -406,6 +419,7 @@ class vainfo {
$results[$key] = $parsed;
}
}
$results['general'] = $this->_parse_general($this->_raw);
@ -420,7 +434,8 @@ class vainfo {
*
* Get additional metadata from plugins
*/
private function _get_plugin_tags() {
private function _get_plugin_tags()
{
$tag_order = Config::get('metadata_order');
if (!is_array($tag_order)) {
$tag_order = array($tag_order);
@ -443,7 +458,8 @@ class vainfo {
* Gather and return the general information about a file (vbr/cbr,
* sample rate, channels, etc.)
*/
private function _parse_general($tags) {
private function _parse_general($tags)
{
$parsed = array();
$parsed['title'] = urldecode($this->_pathinfo['filename']);
@ -454,10 +470,10 @@ class vainfo {
$parsed['bitrate'] = $tags['audio']['bitrate'];
$parsed['channels'] = intval($tags['audio']['channels']);
$parsed['rate'] = intval($tags['audio']['sample_rate']);
$parsed['size'] = intval($tags['filesize']);
$parsed['size'] = $this->_forcedSize ?: intval($tags['filesize']);
$parsed['encoding'] = $tags['encoding'];
$parsed['mime'] = $tags['mime_type'];
$parsed['time'] = $tags['playtime_seconds'];
$parsed['time'] = ($this->_forcedSize ? ((($this->_forcedSize - $tags['avdataoffset']) * 8) / $tags['bitrate']) : $tags['playtime_seconds']);
$parsed['video_codec'] = $tags['video']['fourcc'];
$parsed['audio_codec'] = $tags['audio']['dataformat'];
$parsed['resolution_x'] = $tags['video']['resolution_x'];
@ -470,8 +486,8 @@ class vainfo {
* _clean_type
* This standardizes the type that we are given into a recognized type.
*/
private function _clean_type($type) {
private function _clean_type($type)
{
switch ($type) {
case 'mp3':
case 'mp2':
@ -503,7 +519,8 @@ class vainfo {
*
* This does generic cleanup.
*/
private function _cleanup_generic($tags) {
private function _cleanup_generic($tags)
{
$parsed = array();
foreach ($tags as $tagname => $data) {
switch ($tagname) {
@ -525,7 +542,8 @@ class vainfo {
*
* This is supposed to handle lyrics3. FIXME: does it?
*/
private function _cleanup_lyrics($tags) {
private function _cleanup_lyrics($tags)
{
$parsed = array();
foreach ($tags as $tag => $data) {
@ -542,7 +560,8 @@ class vainfo {
*
* Standardises tag names from vorbis.
*/
private function _cleanup_vorbiscomment($tags) {
private function _cleanup_vorbiscomment($tags)
{
$parsed = array();
foreach ($tags as $tag => $data) {
@ -576,7 +595,8 @@ class vainfo {
*
* Doesn't do much.
*/
private function _cleanup_id3v1($tags) {
private function _cleanup_id3v1($tags)
{
$parsed = array();
foreach ($tags as $tag => $data) {
@ -593,7 +613,8 @@ class vainfo {
*
* Whee, v2!
*/
private function _cleanup_id3v2($tags) {
private function _cleanup_id3v2($tags)
{
$parsed = array();
foreach ($tags as $tag => $data) {
@ -661,7 +682,8 @@ class vainfo {
/**
* _cleanup_riff
*/
private function _cleanup_riff($tags) {
private function _cleanup_riff($tags)
{
$parsed = array();
foreach ($tags as $tag => $data) {
@ -681,7 +703,8 @@ class vainfo {
/**
* _cleanup_quicktime
*/
private function _cleanup_quicktime($tags) {
private function _cleanup_quicktime($tags)
{
$parsed = array();
foreach ($tags as $tag => $data) {
@ -717,21 +740,28 @@ class vainfo {
* This function uses the file and directory patterns to pull out extra tag
* information.
*/
private function _parse_filename($filename) {
private function _parse_filename($filename)
{
$origin = $filename;
$results = array();
// Correctly detect the slash we need to use here
if (strpos($filename, '/') !== false) {
$slash_type = '/';
}
else {
} else {
$slash_type = '\\';
}
// Combine the patterns
$pattern = preg_quote($this->_dir_pattern) . $slash_type . preg_quote($this->_file_pattern);
// Remove first left directories from filename to match pattern
$cntslash = substr_count($pattern, $slash_type) + 1;
$filepart = explode($slash_type, $filename);
if (count($filepart) > $cntslash) {
$filename = implode($slash_type, array_slice($filepart, count($filepart) - $cntslash));
}
// Pull out the pattern codes into an array
preg_match_all('/\%\w/', $pattern, $elements);
@ -758,7 +788,9 @@ class vainfo {
}
$results['title'] = $results['title'] ?: basename($filename);
$results['size'] = filesize($filename);
if ($this->islocal) {
$results['size'] = filesize($origin);
}
return $results;
}
@ -770,8 +802,8 @@ class vainfo {
*
* @return array Return broken title, album, artist
*/
public function set_broken() {
public function set_broken()
{
/* Pull In the config option */
$order = Config::get('tag_order');
@ -790,4 +822,3 @@ class vainfo {
} // set_broken
} // end class vainfo
?>

View file

@ -20,8 +20,8 @@
*
*/
class Video extends database_object implements media {
class Video extends database_object implements media
{
public $id;
public $title;
public $enabled;
@ -33,8 +33,8 @@ class Video extends database_object implements media {
* This pulls the shoutbox information from the database and returns
* a constructed object, uses user_shout table
*/
public function __construct($id) {
public function __construct($id)
{
// Load the data from the database
$info = $this->get_info($id);
foreach ($info as $key=>$value) {
@ -49,8 +49,8 @@ class Video extends database_object implements media {
* build_cache
* Build a cache based on the array of ids passed, saves lots of little queries
*/
public static function build_cache($ids=array()) {
public static function build_cache($ids=array())
{
if (!is_array($ids) OR !count($ids)) { return false; }
$idlist = '(' . implode(',',$ids) . ')';
@ -68,8 +68,8 @@ class Video extends database_object implements media {
* format
* This formats a video object so that it is human readable
*/
public function format() {
public function format()
{
$this->f_title = scrub_out($this->title);
$this->f_link = scrub_out($this->title);
$this->f_codec = $this->video_codec . ' / ' . $this->audio_codec;
@ -79,8 +79,8 @@ class Video extends database_object implements media {
} // format
public function get_stream_types() {
public function get_stream_types()
{
return array('native');
} // native_stream
@ -90,8 +90,8 @@ class Video extends database_object implements media {
* This returns a "PLAY" url for the video in question here, this currently feels a little
* like a hack, might need to adjust it in the future
*/
public static function play_url($oid,$sid='',$force_http='') {
public static function play_url($oid,$sid='',$force_http='')
{
$video = new Video($oid);
if (!$video->id) { return false; }
@ -110,7 +110,8 @@ class Video extends database_object implements media {
*
* FIXME: Video transcoding is not implemented
*/
public function get_transcode_settings($target = null) {
public function get_transcode_settings($target = null)
{
return false;
}
@ -119,10 +120,8 @@ class Video extends database_object implements media {
* returns true if the video has been flagged and we shouldn't try to re-read
* the meta data
*/
public function has_flag() {
public function has_flag()
{
} // has_flag
} // end Video class

View file

@ -28,8 +28,8 @@
* are all static calls
*
*/
class XML_Data {
class XML_Data
{
// This is added so that we don't pop any webservers
private static $limit = '5000';
private static $offset = '0';
@ -40,8 +40,8 @@ class XML_Data {
*
* We don't use this, as its really a static class
*/
private function __construct() {
private function __construct()
{
// Rien a faire
} // constructor
@ -54,8 +54,8 @@ class XML_Data {
* @param integer $offset (description here...)
* @return void
*/
public static function set_offset($offset) {
public static function set_offset($offset)
{
$offset = intval($offset);
self::$offset = $offset;
@ -69,8 +69,8 @@ class XML_Data {
* @param integer $limit (description here...)
* @return void
*/
public static function set_limit($limit) {
public static function set_limit($limit)
{
if (!$limit) { return false; }
$limit = intval($limit);
@ -86,8 +86,8 @@ class XML_Data {
* @param string $type XML_Data type
* @return void
*/
public static function set_type($type) {
public static function set_type($type)
{
if (!in_array($type,array('rss','xspf','itunes'))) { return false; }
self::$type = $type;
@ -104,8 +104,8 @@ class XML_Data {
* @param string $string Error message
* @return string return error message xml
*/
public static function error($code,$string) {
public static function error($code,$string)
{
$string = self::_header() . "\t<error code=\"$code\"><![CDATA[$string]]></error>" . self::_footer();
return $string;
@ -120,8 +120,8 @@ class XML_Data {
* @param string $string xml data
* @return string return xml
*/
public static function single_string($key,$string) {
public static function single_string($key,$string)
{
$final = self::_header() . "\t<$key><![CDATA[$string]]></$key>" . self::_footer();
return $final;
@ -136,8 +136,8 @@ class XML_Data {
* @see _header()
* @return string return xml
*/
public static function header() {
public static function header()
{
return self::_header();
} // header
@ -150,8 +150,8 @@ class XML_Data {
* @see _footer()
* @return string return xml
*/
public static function footer() {
public static function footer()
{
return self::_footer();
} // footer
@ -162,8 +162,8 @@ class XML_Data {
* This returns the formatted 'tags' string for an xml document
*
*/
private static function tags_string($tags) {
private static function tags_string($tags)
{
$string = '';
if (is_array($tags)) {
@ -189,8 +189,8 @@ class XML_Data {
* @param boolean $callback (description here...)
* @return string return xml
*/
public static function keyed_array($array,$callback='') {
public static function keyed_array($array,$callback='')
{
$string = '';
// Foreach it
@ -206,8 +206,7 @@ class XML_Data {
if (is_array($value)) {
$value = self::keyed_array($value,1);
$string .= "<$key$attribute>\n$value\n</$key>\n";
}
else {
} else {
$string .= "\t<$key$attribute><![CDATA[$value]]></$key>\n";
}
@ -229,8 +228,8 @@ class XML_Data {
* @param array $tags (description here...)
* @return string return xml
*/
public static function tags($tags) {
public static function tags($tags)
{
if (count($tags) > self::$limit OR self::$offset > 0) {
$tags = array_splice($tags,self::$offset,self::$limit);
}
@ -266,8 +265,8 @@ class XML_Data {
* @param array $artists (description here...)
* @return string return xml
*/
public static function artists($artists) {
public static function artists($artists)
{
if (count($artists) > self::$limit OR self::$offset > 0) {
$artists = array_splice($artists,self::$offset,self::$limit);
}
@ -308,8 +307,8 @@ class XML_Data {
* @param array $albums (description here...)
* @return string return xml
*/
public static function albums($albums) {
public static function albums($albums)
{
if (count($albums) > self::$limit OR self::$offset > 0) {
$albums = array_splice($albums,self::$offset,self::$limit);
}
@ -331,8 +330,7 @@ class XML_Data {
// Do a little check for artist stuff
if ($album->artist_count != 1) {
$string .= "\t<artist id=\"0\"><![CDATA[Various]]></artist>\n";
}
else {
} else {
$string .= "\t<artist id=\"$album->artist_id\"><![CDATA[$album->artist_name]]></artist>\n";
}
@ -361,8 +359,8 @@ class XML_Data {
* @param array $playlists (description here...)
* @return string return xml
*/
public static function playlists($playlists) {
public static function playlists($playlists)
{
if (count($playlists) > self::$limit OR self::$offset > 0) {
$playlists = array_slice($playlists,self::$offset,self::$limit);
}
@ -399,8 +397,8 @@ class XML_Data {
* This returns an xml document from an array of song ids.
* (Spiffy isn't it!)
*/
public static function songs($songs) {
public static function songs($songs)
{
if (count($songs) > self::$limit OR self::$offset > 0) {
$songs = array_slice($songs, self::$offset, self::$limit);
}
@ -459,8 +457,8 @@ class XML_Data {
* @param array $videos (description here...)
* @return string return xml
*/
public static function videos($videos) {
public static function videos($videos)
{
if (count($videos) > self::$limit OR self::$offset > 0) {
$videos = array_slice($videos,self::$offset,self::$limit);
}
@ -497,8 +495,8 @@ class XML_Data {
* @param array $object_ids Object IDs
* @return string return xml
*/
public static function democratic($object_ids=array()) {
public static function democratic($object_ids=array())
{
if (!is_array($object_ids)) { $object_ids = array(); }
$democratic = Democratic::get_current_playlist();
@ -559,8 +557,8 @@ class XML_Data {
* @param string $date publish date
* @return string RSS feed xml
*/
public static function rss_feed($data,$title,$description,$date) {
public static function rss_feed($data,$title,$description,$date)
{
$string = "\t<title>$title</title>\n\t<link>" . Config::get('web_path') . "</link>\n\t" .
"<pubDate>" . date("r",$date) . "</pubDate>\n";
@ -584,8 +582,8 @@ class XML_Data {
*
* @return string Header xml tag.
*/
private static function _header() {
private static function _header()
{
switch (self::$type) {
case 'xspf':
$header = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" .
@ -632,8 +630,8 @@ class XML_Data {
*
* @return string Footer xml tag.
*/
private static function _footer() {
private static function _footer()
{
switch (self::$type) {
case 'itunes':
$footer = "\t\t</dict>\t\n</dict>\n</plist>\n";
@ -655,5 +653,3 @@ class XML_Data {
} // _footer
} // XML_Data
?>

View file

@ -20,7 +20,8 @@
*
*/
function check_php() {
function check_php()
{
if (
check_php_version() &&
check_php_hash() &&
@ -37,34 +38,41 @@ function check_php() {
return false;
}
function check_php_version() {
function check_php_version()
{
if (floatval(phpversion()) < 5.3) {
return false;
}
return true;
}
function check_php_hash() {
function check_php_hash()
{
return function_exists('hash_algos');
}
function check_php_hash_algo() {
function check_php_hash_algo()
{
return function_exists('hash_algos') ? in_array('sha256', hash_algos()) : false;
}
function check_php_json() {
function check_php_json()
{
return function_exists('json_encode');
}
function check_php_session() {
function check_php_session()
{
return function_exists('session_set_save_handler');
}
function check_php_pdo() {
function check_php_pdo()
{
return class_exists('PDO');
}
function check_php_pdo_mysql() {
function check_php_pdo_mysql()
{
return class_exists('PDO') ? in_array('mysql', PDO::getAvailableDrivers()) : false;
}
@ -72,8 +80,8 @@ function check_php_pdo_mysql() {
* check_config_values
* checks to make sure that they have at least set the needed variables
*/
function check_config_values($conf) {
function check_config_values($conf)
{
if (!$conf['database_hostname']) {
return false;
}
@ -114,8 +122,8 @@ function check_config_values($conf) {
* recommended range, this doesn't take into account the size of your
* catalog.
*/
function check_php_memory() {
function check_php_memory()
{
$current_memory = ini_get('memory_limit');
$current_memory = substr($current_memory,0,strlen($current_memory)-1);
@ -132,8 +140,8 @@ function check_php_memory() {
* This checks to make sure that the php timelimit is set to some
* semi-sane limit, IE greater then 60 seconds
*/
function check_php_timelimit() {
function check_php_timelimit()
{
$current = intval(ini_get('max_execution_time'));
return ($current >= 60 || $current == 0);
@ -143,7 +151,8 @@ function check_php_timelimit() {
* check_safe_mode
* Checks to make sure we aren't in safe mode
*/
function check_php_safemode() {
function check_php_safemode()
{
if (ini_get('safe_mode')) {
return false;
}
@ -154,7 +163,8 @@ function check_php_safemode() {
* check_override_memory
* This checks to see if we can manually override the memory limit
*/
function check_override_memory() {
function check_override_memory()
{
/* Check memory */
$current_memory = ini_get('memory_limit');
$current_memory = substr($current_memory,0,strlen($current_memory)-1);
@ -179,7 +189,8 @@ function check_override_memory() {
* check_override_exec_time
* This checks to see if we can manually override the max execution time
*/
function check_override_exec_time() {
function check_override_exec_time()
{
$current = ini_get('max_execution_time');
set_time_limit($current+60);
@ -194,8 +205,8 @@ function check_override_exec_time() {
* check_config_writable
* This checks whether we can write the config file
*/
function check_config_writable() {
function check_config_writable()
{
// file eixsts && is writable, or dir is writable
return ((file_exists(Config::get('prefix') . '/config/ampache.cfg.php') && is_writable(Config::get('prefix') . '/config/ampache.cfg.php'))
|| (!file_exists(Config::get('prefix') . '/config/ampache.cfg.php') && is_writeable(Config::get('prefix') . '/config/')));
@ -206,7 +217,8 @@ function check_config_writable() {
*
* Convenience function to format the output.
*/
function debug_result($status = false, $value = null, $comment = '') {
function debug_result($status = false, $value = null, $comment = '')
{
$class = $status ? 'ok' : 'notok';
if (!$value) {
@ -216,4 +228,3 @@ function debug_result($status = false, $value = null, $comment = '') {
return '[ <span class="' . $class . '">' . scrub_out($value) .
'</span> <em>' . $comment . '</em> ]';
}
?>

View file

@ -25,8 +25,8 @@
* This function attempts to change the php memory limit using init_set.
* Will never reduce it below the current setting.
*/
function set_memory_limit($new_limit) {
function set_memory_limit($new_limit)
{
$current_limit = ini_get('memory_limit');
if ($current_limit == -1) {
return;
@ -45,8 +45,8 @@ function set_memory_limit($new_limit) {
* generate_password
* This generates a random password of the specified length
*/
function generate_password($length) {
function generate_password($length)
{
$vowels = 'aAeEuUyY12345';
$consonants = 'bBdDgGhHjJmMnNpPqQrRsStTvVwWxXzZ6789';
$password = '';
@ -57,8 +57,7 @@ function generate_password($length) {
if ($alt == 1) {
$password .= $consonants[(rand(0,strlen($consonants)-1))];
$alt = 0;
}
else {
} else {
$password .= $vowels[(rand(0,strlen($vowels)-1))];
$alt = 1;
}
@ -72,12 +71,11 @@ function generate_password($length) {
* scrub_in
* Run on inputs, stuff that might get stuck in our db
*/
function scrub_in($input) {
if (!is_array($input)) { // this doesn't make any sense, why are we encoding input?
function scrub_in($input)
{
if (!is_array($input)) {
return stripslashes(htmlspecialchars(strip_tags($input), ENT_QUOTES, Config::get('site_charset')));
}
else {
} else {
$results = array();
foreach ($input as $item) {
$results[] = scrub_in($item);
@ -94,7 +92,7 @@ function scrub_in($input) {
*/
function scrub_out($string) {
return html_entity_decode($string, ENT_QUOTES, Config::get('site_charset'));
return htmlentities($string, ENT_QUOTES, Config::get('site_charset'));
} // scrub_out
@ -102,8 +100,8 @@ function scrub_out($string) {
* unhtmlentities
* Undoes htmlentities()
*/
function unhtmlentities($string) {
function unhtmlentities($string)
{
return html_entity_decode($string, ENT_QUOTES, Config::get('site_charset'));
} //unhtmlentities
@ -127,8 +125,8 @@ function scrub_arg($arg)
* This takes a value and returns what we consider to be the correct boolean
* value. We need a special function because PHP considers "false" to be true.
*/
function make_bool($string) {
function make_bool($string)
{
if (strcasecmp($string,'false') == 0) {
return false;
}
@ -141,8 +139,8 @@ function make_bool($string) {
* invert_bool
* This returns the opposite of what you've got
*/
function invert_bool($value) {
function invert_bool($value)
{
return make_bool($value) ? false : true;
} // invert_bool
@ -154,8 +152,8 @@ function invert_bool($value) {
* is drop one in and it will show up on the context menu. It returns
* in the form of an array of names
*/
function get_languages() {
function get_languages()
{
/* Open the locale directory */
$handle = @opendir(Config::get('prefix') . '/locale');
@ -238,7 +236,8 @@ function get_languages() {
* is_rtl
* This checks whether to be a rtl language.
*/
function is_rtl($locale) {
function is_rtl($locale)
{
return in_array($locale, array("he_IL", "fa_IR", "ar_SA"));
}
@ -248,8 +247,8 @@ function is_rtl($locale) {
* 'tag' name that said pattern code corrasponds to. It returns false if nothing
* is found.
*/
function translate_pattern_code($code) {
function translate_pattern_code($code)
{
$code_array = array('%A'=>'album',
'%a'=>'artist',
'%c'=>'comment',
@ -273,7 +272,8 @@ function translate_pattern_code($code) {
* This takes an array of results and re-generates the config file
* this is used by the installer and by the admin/system page
*/
function generate_config($current) {
function generate_config($current)
{
// Start building the new config file
$distfile = Config::get('prefix') . '/config/ampache.cfg.php.dist';
$handle = fopen($distfile,'r');
@ -293,8 +293,7 @@ function generate_config($current) {
// Put in the current value
if ($key == 'config_version') {
$line = $key . ' = ' . escape_ini($value);
}
elseif (isset($current[$key])) {
} elseif (isset($current[$key])) {
$line = $key . ' = "' . escape_ini($current[$key]) . '"';
unset($current[$key]);
}
@ -312,8 +311,7 @@ function generate_config($current) {
* Escape a value used for inserting into an ini file.
* Won't quote ', like addslashes does.
*/
function escape_ini($str) {
function escape_ini($str)
{
return str_replace('"', '\"', $str);
}
?>

View file

@ -26,7 +26,8 @@
*
* @return void
*/
function load_gettext() {
function load_gettext()
{
$lang = Config::get('lang');
$charset = Config::get('site_charset') ?: 'UTF-8';
$locale = $lang . '.' . $charset;
@ -45,8 +46,7 @@ function load_gettext() {
* @param string $string
* @return string
*/
function gettext_noop($string) {
function gettext_noop($string)
{
return $string;
}
?>

View file

@ -48,15 +48,13 @@ spl_autoload_register(array('Core', 'autoload'), true, true);
if ((isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' )
|| (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')) {
$http_type = 'https://';
}
else {
} else {
$http_type = 'http://';
}
if (isset($_SERVER['HTTP_X_FORWARDED_PORT'])) {
$http_port = $_SERVER['HTTP_X_FORWARDED_PORT'];
}
else if (isset($_SERVER['SERVER_PORT'])) {
} else if (isset($_SERVER['SERVER_PORT'])) {
$http_port = $_SERVER['SERVER_PORT'];
}
if (!isset($http_port) || !$http_port) {
@ -86,4 +84,3 @@ UI::flip_class(array('odd', 'even'));
// Merge GET then POST into REQUEST effectively stripping COOKIE without
// depending on a PHP setting change for the effect
$_REQUEST = array_merge($_GET, $_POST);
?>

View file

@ -41,8 +41,7 @@ $path = $http_type . $_SERVER['HTTP_HOST'] . $path;
// send them over to the install script.
if (!file_exists($configfile)) {
$link = $path . '/install.php';
}
else {
} else {
// Make sure the config file is set up and parsable
$results = @parse_ini_file($configfile);
@ -58,7 +57,7 @@ if (!check_php()) {
}
// Do the redirect if we can't continue
if ($link) {
if (!empty($link)) {
header ("Location: $link");
exit();
}
@ -67,13 +66,13 @@ if ($link) {
$results['version'] = '3.6-alpha6+FUTURE';
$results['int_config_version'] = '12';
if ($results['force_ssl']) {
if (!empty($results['force_ssl'])) {
$http_type = 'https://';
}
$results['raw_web_path'] = $results['web_path'];
$results['web_path'] = $http_type . $_SERVER['HTTP_HOST'] . $results['web_path'];
$results['http_port'] = $results['http_port'] ?: $http_port;
$results['http_port'] = (!empty($results['http_port'])) ? $results['http_port'] : $http_port;
$results['site_charset'] = $results['site_charset'] ?: 'UTF-8';
$results['raw_web_path'] = $results['raw_web_path'] ?: '/';
$_SERVER['SERVER_NAME'] = $_SERVER['SERVER_NAME'] ?: '';
@ -153,8 +152,7 @@ if (!defined('NO_SESSION') && Config::get('use_auth')) {
/* Load preferences and theme */
$GLOBALS['user']->update_last_seen();
}
elseif (!Config::get('use_auth')) {
} elseif (!Config::get('use_auth')) {
$auth['success'] = 1;
$auth['username'] = '-1';
$auth['fullname'] = "Ampache User";
@ -169,13 +167,11 @@ elseif (!Config::get('use_auth')) {
$GLOBALS['user']->username = $auth['username'];
$GLOBALS['user']->fullname = $auth['fullname'];
$GLOBALS['user']->access = $auth['access'];
}
else {
} else {
Session::check();
if ($_SESSION['userdata']['username']) {
$GLOBALS['user'] = User::get_from_username($_SESSION['userdata']['username']);
}
else {
} else {
$GLOBALS['user'] = new User($auth['username']);
$GLOBALS['user']->id = '-1';
$GLOBALS['user']->username = $auth['username'];
@ -195,8 +191,7 @@ else {
session_id(scrub_in($_REQUEST['sid']));
session_start();
$GLOBALS['user'] = new User($_SESSION['userdata']['uid']);
}
else {
} else {
$GLOBALS['user'] = new User();
}
@ -238,4 +233,3 @@ $GLOBALS['xmlrpc_internalencoding'] = Config::get('site_charset');
if (Config::get('debug')) {
error_reporting(E_ALL);
}
?>

View file

@ -24,7 +24,8 @@
* split_sql
* splits up a standard SQL dump file into distinct sql queries
*/
function split_sql($sql) {
function split_sql($sql)
{
$sql = trim($sql);
$sql = preg_replace("/\n#[^\n]*\n/", "\n", $sql);
$buffer = array();
@ -38,8 +39,7 @@ function split_sql($sql) {
}
if ($in_string && ($sql[$i] == $in_string) && $buffer[1] != "\\") {
$in_string = false;
}
elseif(!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset($buffer[0]) || $buffer[0] != "\\")) {
} elseif (!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset($buffer[0]) || $buffer[0] != "\\")) {
$in_string = $sql[$i];
}
if (isset($buffer[1])) {
@ -59,8 +59,8 @@ function split_sql($sql) {
* still need to install ampache. This function is
* very important, we don't want to reinstall over top of an existing install
*/
function install_check_status($configfile) {
function install_check_status($configfile)
{
/*
Check and see if the config file exists
if it does they can't use the web interface
@ -94,8 +94,7 @@ function install_check_status($configfile) {
if (!Dba::num_rows($db_results)) {
return true;
}
else {
} else {
Error::add('general', T_('Existing Database detected, unable to continue installation'));
return false;
}
@ -110,7 +109,8 @@ function install_check_status($configfile) {
*
* Inserts the database using the values from Config.
*/
function install_insert_db($db_user = null, $db_pass = null, $overwrite = false, $use_existing_db = false) {
function install_insert_db($db_user = null, $db_pass = null, $overwrite = false, $use_existing_db = false)
{
$database = Config::get('database_name');
// Make sure that the database name is valid
$is_valid = preg_match('/([^\d\w\_\-])/', $database, $matches);
@ -131,11 +131,9 @@ function install_insert_db($db_user = null, $db_pass = null, $overwrite = false,
if ($db_exists) {
if ($use_existing_db) {
$create_db = false;
}
else if ($overwrite) {
} else if ($overwrite) {
Dba::write('DROP DATABASE `' . $database . '`');
}
else {
} else {
Error::add('general', T_('Error: Database already exists and overwrite not checked'));
return false;
}
@ -198,8 +196,8 @@ function install_insert_db($db_user = null, $db_pass = null, $overwrite = false,
*
* Attempts to write out the config file or offer it as a download.
*/
function install_create_config($download = false) {
function install_create_config($download = false)
{
$config_file = Config::get('prefix') . '/config/ampache.cfg.php';
/* Attempt to make DB connection */
@ -218,16 +216,14 @@ function install_create_config($download = false) {
if (!check_config_writable()) {
Error::add('general', T_('Config file is not writable'));
return false;
}
else {
} else {
// Given that $final is > 0, we can ignore lazy comparison problems
if (!file_put_contents($config_file, $final)) {
Error::add('general', T_('Error writing config file'));
return false;
}
}
}
else {
} else {
$browser = new Horde_Browser();
$browser->downloadHeaders('ampache.cfg.php', 'text/plain', false, strlen($final));
echo $final;
@ -241,8 +237,8 @@ function install_create_config($download = false) {
* install_create_account
* this creates your initial account and sets up the preferences for the -1 user and you
*/
function install_create_account($username, $password, $password2) {
function install_create_account($username, $password, $password2)
{
if (!strlen($username) OR !strlen($password)) {
Error::add('general', T_('No Username/Password specified'));
return false;
@ -279,5 +275,3 @@ function install_create_account($username, $password, $password2) {
return true;
} // install_create_account
?>

View file

@ -87,23 +87,36 @@ function check_inline_song_edit(type, song) {
}
}
function showAddTagDialog(id, type, path) {
$('#dialog_tag_item').dialog({
modal: true,
buttons: [
{
title: "Tag",
text: 'ok',
click: function () {
var tagName = $('#dialog_tag_item_tag_name').val();
function showAddTagSlideout(elm) {
$(elm).show(500, 'slide');
}
function saveTag(id, type, path) {
var tagName = $('#dialog_tag_item_tag_name_'+id).val();
if (tagName != null || tagName != '') {
ajaxPut(path + '/server/ajax.server.php?page=tag&action=add_tag_by_name&type=' + type + '&object_id=' + id + '&tag_name=' + tagName);
}
$('#dialog_tag_item_tag_name').val('');
$(this).dialog('close');
}
}
]
}).show();
$(this).parent().hide(500, 'slide');
}
function showAddTagDialog(id, type, path) {
//$('#dialog_tag_item').dialog({
// modal: true,
// buttons: [
// {
// title: "Tag",
// text: 'ok',
// click: function () {
// var tagName = $('#dialog_tag_item_tag_name').val();
// if (tagName != null || tagName != '') {
// ajaxPut(path + '/server/ajax.server.php?page=tag&action=add_tag_by_name&type=' + type + '&object_id=' + id + '&tag_name=' + tagName);
// }
// $('#dialog_tag_item_tag_name').val('');
// $(this).dialog('close');
// }
// }
// ]
//}).show();
}

View file

@ -22,14 +22,14 @@
require_once '../init.php';
function arrayToJSON($array) {
function arrayToJSON($array)
{
$json = '{ ';
foreach ($array as $key => $value) {
$json .= '"' . $key . '" : ';
if (is_array($value)) {
$json .= arrayToJSON($value);
}
else {
} else {
// Make sure to strip backslashes and convert things to
// entities in our output
$json .= '"' . scrub_out(str_replace('\\', '', $value)) . '"';
@ -49,4 +49,3 @@ echo arrayToJSON($search->types) . "'.evalJSON());\n";
echo 'var basetypes = $H(\'';
echo arrayToJSON($search->basetypes) . "'.evalJSON());\n";
echo 'removeIcon = \'<a href="javascript: void(0)">' . UI::get_icon('disable', T_('Remove')) . '</a>\';';
?>

View file

@ -24,7 +24,8 @@
* log_event
* Logs an event to a defined log file based on config options
*/
function log_event($username, $event_name, $event_description, $log_name) {
function log_event($username, $event_name, $event_description, $log_name)
{
/* Set it up here to make sure it's _always_ the same */
$time = time();
// Turn time into strings
@ -53,7 +54,8 @@ function log_event($username, $event_name, $event_description, $log_name) {
* An error handler for ampache that traps as many errors as it can and logs
* them.
*/
function ampache_error_handler($errno, $errstr, $errfile, $errline) {
function ampache_error_handler($errno, $errstr, $errfile, $errline)
{
$level = 1;
switch ($errno) {
@ -127,8 +129,8 @@ function ampache_error_handler($errno, $errstr, $errfile, $errline) {
* log_event. It checks config for debug and debug_level and only
* calls log event if both requirements are met.
*/
function debug_event($type, $message, $level, $file = '', $username = '') {
function debug_event($type, $message, $level, $file = '', $username = '')
{
if (!Config::get('debug') || $level > Config::get('debug_level')) {
return false;
}
@ -143,5 +145,3 @@ function debug_event($type, $message, $level, $file = '', $username = '') {
}
} // debug_event
?>

View file

@ -26,8 +26,8 @@
* and then runs throught $_REQUEST looking for those
* values and updates them for this user
*/
function update_preferences($pref_id=0) {
function update_preferences($pref_id=0)
{
$pref_user = new User($pref_id);
/* Get current keys */
@ -63,8 +63,7 @@ function update_preferences($pref_id=0) {
}
if (preg_match('/_pass$/', $name)) {
if ($value == '******') { unset($_REQUEST[$name]); }
else if (preg_match('/md5_pass$/', $name)) {
if ($value == '******') { unset($_REQUEST[$name]); } else if (preg_match('/md5_pass$/', $name)) {
$value = md5($value);
}
}
@ -89,8 +88,8 @@ function update_preferences($pref_id=0) {
* update_preference
* This function updates a single preference and is called by the update_preferences function
*/
function update_preference($user_id,$name,$pref_id,$value) {
function update_preference($user_id,$name,$pref_id,$value)
{
$apply_check = "check_" . $name;
$level_check = "level_" . $name;
@ -120,8 +119,8 @@ function update_preference($user_id,$name,$pref_id,$value) {
* create_preference_input
* takes the key and then creates the correct type of input for updating it
*/
function create_preference_input($name,$value) {
function create_preference_input($name,$value)
{
// Escape it for output
$value = scrub_out($value);
@ -131,15 +130,12 @@ function create_preference_input($name,$value) {
if (!Preference::has_access($name)) {
if ($value == '1') {
echo "Enabled";
}
elseif ($value == '0') {
} elseif ($value == '0') {
echo "Disabled";
}
else {
} else {
if (preg_match('/_pass$/', $name)) {
echo "******";
}
else {
} else {
echo $value;
}
}
@ -169,18 +165,15 @@ function create_preference_input($name,$value) {
case 'iframes':
case 'now_playing_per_user':
case 'show_played_times':
if ($value == '1') { $is_true = "selected=\"selected\""; }
else { $is_false = "selected=\"selected\""; }
case 'song_page_title':
if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; }
echo "<select name=\"$name\">\n";
echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n";
echo "\t<option value=\"0\" $is_false>" . T_("Disable") . "</option>\n";
echo "</select>\n";
break;
case 'play_type':
if ($value == 'localplay') { $is_local = 'selected="selected"'; }
elseif ($value == 'democratic') { $is_vote = 'selected="selected"'; }
elseif ($value == 'html5_player') { $is_html5_player = 'selected="selected"'; }
else { $is_stream = "selected=\"selected\""; }
if ($value == 'localplay') { $is_local = 'selected="selected"'; } elseif ($value == 'democratic') { $is_vote = 'selected="selected"'; } elseif ($value == 'html5_player') { $is_html5_player = 'selected="selected"'; } else { $is_stream = "selected=\"selected\""; }
echo "<select name=\"$name\">\n";
echo "\t<option value=\"\">" . T_('None') . "</option>\n";
if (Config::get('allow_stream_playback')) {
@ -229,9 +222,7 @@ function create_preference_input($name,$value) {
echo "</select>\n";
break;
case 'localplay_level':
if ($value == '25') { $is_user = 'selected="selected"'; }
elseif ($value == '100') { $is_admin = 'selected="selected"'; }
elseif ($value == '50') { $is_manager = 'selected="selected"'; }
if ($value == '25') { $is_user = 'selected="selected"'; } elseif ($value == '100') { $is_admin = 'selected="selected"'; } elseif ($value == '50') { $is_manager = 'selected="selected"'; }
echo "<select name=\"$name\">\n";
echo "<option value=\"0\">" . T_('Disabled') . "</option>\n";
echo "<option value=\"25\" $is_user>" . T_('User') . "</option>\n";
@ -283,19 +274,14 @@ function create_preference_input($name,$value) {
echo "</select>\n";
break;
case 'show_lyrics':
if ($value == '1') { $is_true = "selected=\"selected\""; }
else { $is_false = "selected=\"selected\""; }
if ($value == '1') { $is_true = "selected=\"selected\""; } else { $is_false = "selected=\"selected\""; }
echo "<select name=\"$name\">\n";
echo "\t<option value=\"1\" $is_true>" . T_("Enable") . "</option>\n";
echo "\t<option value=\"0\" $is_false>" . T_("Disable") . "</option>\n";
echo "</select>\n";
break;
case 'album_sort':
if ($value == 'year_asc') { $is_sort_year_asc = 'selected="selected"'; }
elseif ($value == 'year_desc') { $is_sort_year_desc = 'selected="selected"'; }
elseif ($value == 'name_asc') { $is_sort_name_asc = 'selected="selected"'; }
elseif ($value == 'name_desc') { $is_sort_name_desc = 'selected="selected"'; }
else { $is_sort_default = 'selected="selected"'; }
if ($value == 'year_asc') { $is_sort_year_asc = 'selected="selected"'; } elseif ($value == 'year_desc') { $is_sort_year_desc = 'selected="selected"'; } elseif ($value == 'name_asc') { $is_sort_name_asc = 'selected="selected"'; } elseif ($value == 'name_desc') { $is_sort_name_desc = 'selected="selected"'; } else { $is_sort_default = 'selected="selected"'; }
echo "<select name=\"$name\">\n";
echo "\t<option value=\"default\" $is_sort_default>" . T_('Default') . "</option>\n";
@ -308,8 +294,7 @@ function create_preference_input($name,$value) {
default:
if (preg_match('/_pass$/', $name)) {
echo '<input type="password" size="16" name="' . $name . '" value="******" />';
}
else {
} else {
echo '<input type="text" size="' . $len . '" name="' . $name . '" value="' . $value .'" />';
}
break;
@ -317,5 +302,3 @@ function create_preference_input($name,$value) {
}
} // create_preference_input
?>

View file

@ -24,8 +24,8 @@
* show_rating
* This takes an artist id and includes the right file
*/
function show_rating($object_id,$type) {
function show_rating($object_id,$type)
{
$rating = new Rating($object_id,$type);
require Config::get('prefix') . '/templates/show_object_rating.inc.php';
@ -36,8 +36,8 @@ function show_rating($object_id,$type) {
* get_rating_name
* This takes a score and returns the name that we should use
*/
function get_rating_name($score) {
function get_rating_name($score)
{
switch ($score) {
case '0':
return T_("Don't Play");
@ -66,5 +66,3 @@ function get_rating_name($score) {
return true;
} // get_rating_name
?>

View file

@ -26,8 +26,8 @@
* theme.cfg.php files it can find and returns an
* array of the results
*/
function get_themes() {
function get_themes()
{
/* Open the themes dir and start reading it */
$handle = opendir(Config::get('prefix') . '/themes');
@ -47,8 +47,7 @@ function get_themes() {
$r = parse_ini_file($file . $theme_cfg);
$r['path'] = $f;
$results[$r['name']] = $r;
}
else {
} else {
debug_event('theme', "$theme_cfg not found in $f", 5);
}
} // end while directory
@ -65,8 +64,8 @@ function get_themes() {
@discussion get a single theme and read the config file
then return the results
*/
function get_theme($name) {
function get_theme($name)
{
if (strlen($name) < 1) { return false; }
$config_file = Config::get('prefix') . "/themes/" . $name . "/theme.cfg.php";
@ -80,8 +79,8 @@ function get_theme($name) {
@function get_theme_author
@discussion returns the author of this theme
*/
function get_theme_author($theme_name) {
function get_theme_author($theme_name)
{
$theme_path = Config::get('prefix') . '/themes/' . Config::get('theme_name') . '/theme.cfg.php';
$results = read_config($theme_path);
@ -93,8 +92,8 @@ function get_theme_author($theme_name) {
@function theme_exists
@discussion this function checks to make sure that a theme actually exists
*/
function theme_exists($theme_name) {
function theme_exists($theme_name)
{
$theme_path = Config::get('prefix') . '/themes/' . $theme_name . '/theme.cfg.php';
if (!file_exists($theme_path)) {
@ -104,5 +103,3 @@ function theme_exists($theme_name) {
return true;
} // theme_exists
?>

View file

@ -35,12 +35,11 @@
* @param integer $cancel T/F show a cancel button that uses return_referrer()
* @return void
*/
function show_confirmation($title,$text,$next_url,$cancel=0,$form_name='confirmation') {
function show_confirmation($title,$text,$next_url,$cancel=0,$form_name='confirmation')
{
if (substr_count($next_url,Config::get('web_path'))) {
$path = $next_url;
}
else {
} else {
$path = Config::get('web_path') . "/$next_url";
}
@ -54,13 +53,12 @@ function show_confirmation($title,$text,$next_url,$cancel=0,$form_name='confirma
* this is not %100 accurate. Also because this is not passed by us we need
* to clean it up, take the filename then check for a /admin/ and dump the rest
*/
function return_referer() {
function return_referer()
{
$referer = $_SERVER['HTTP_REFERER'];
if (substr($referer, -1)=='/') {
$file = 'index.php';
}
else {
} else {
$file = basename($referer);
/* Strip off the filename */
$referer = substr($referer,0,strlen($referer)-strlen($file));
@ -85,14 +83,13 @@ function return_referer() {
* ['page'] actual page name
* ['section'] name of the section we are in, admin, browse etc (submenu)
*/
function get_location() {
function get_location()
{
$location = array();
if (strlen($_SERVER['PHP_SELF'])) {
$source = $_SERVER['PHP_SELF'];
}
else {
} else {
$source = $_SERVER['REQUEST_URI'];
}
@ -178,24 +175,26 @@ function get_location() {
* show_preference_box
* This shows the preference box for the preferences pages.
*/
function show_preference_box($preferences) {
function show_preference_box($preferences)
{
require Config::get('prefix') . '/templates/show_preference_box.inc.php';
} // show_preference_box
static $album_id_cnt = 0;
/**
* show_album_select
* This displays a select of every album that we've got in Ampache (which can be
* hella long). It's used by the Edit page and takes a $name and a $album_id
*/
function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) {
function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0)
{
// Generate key to use for HTML element ID
static $id_cnt;
if ($song_id) {
$key = "album_select_$song_id";
} else {
$key = "album_select_c" . ++$id_cnt;
$key = "album_select_c" . ++$album_id_cnt;
}
// Added ID field so we can easily observe this element
@ -224,18 +223,20 @@ function show_album_select($name='album',$album_id=0,$allow_add=0,$song_id=0) {
} // show_album_select
static $artist_id_cnt = 0;
/**
* show_artist_select
* This is the same as show_album_select except it's *gasp* for artists! How
* inventive!
*/
function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id=0) {
function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id=0)
{
// Generate key to use for HTML element ID
static $id_cnt;
if ($song_id) {
$key = "artist_select_$song_id";
} else {
$key = "artist_select_c" . ++$id_cnt;
$key = "artist_select_c" . ++$artist_id_cnt;
}
echo "<select name=\"$name\" id=\"$key\">\n";
@ -268,8 +269,8 @@ function show_artist_select($name='artist', $artist_id=0, $allow_add=0, $song_id
* Yet another one of these buggers. this shows a drop down of all of your
* catalogs.
*/
function show_catalog_select($name='catalog',$catalog_id=0,$style='') {
function show_catalog_select($name='catalog',$catalog_id=0,$style='')
{
echo "<select name=\"$name\" style=\"$style\">\n";
$sql = "SELECT `id`, `name` FROM `catalog` ORDER BY `name`";
@ -294,8 +295,8 @@ function show_catalog_select($name='catalog',$catalog_id=0,$style='') {
* This one is for users! shows a select/option statement so you can pick a user
* to blame
*/
function show_user_select($name,$selected='',$style='') {
function show_user_select($name,$selected='',$style='')
{
echo "<select name=\"$name\" style=\"$style\">\n";
echo "\t<option value=\"\">" . T_('All') . "</option>\n";
@ -321,8 +322,8 @@ function show_user_select($name,$selected='',$style='') {
* show_playlist_select
* This one is for playlists!
*/
function show_playlist_select($name,$selected='',$style='') {
function show_playlist_select($name,$selected='',$style='')
{
echo "<select name=\"$name\" style=\"$style\">\n";
echo "\t<option value=\"\">" . T_('None') . "</option>\n";
@ -348,8 +349,8 @@ function show_playlist_select($name,$selected='',$style='') {
* This takes a one dimensional array and creates a XML document from it. For
* use primarily by the ajax mojo.
*/
function xml_from_array($array, $callback = false, $type = '') {
function xml_from_array($array, $callback = false, $type = '')
{
$string = '';
// If we weren't passed an array then return
@ -362,8 +363,7 @@ function xml_from_array($array, $callback = false, $type = '') {
if (is_array($value)) {
$value = xml_from_array($value,1,$type);
$string .= "\t\t<$key>\n$value\t\t</$key>\n";
}
else {
} else {
if ($key == "key") {
$string .= "\t\t<$key>$value</$key>\n";
} elseif (is_int($value)) {
@ -385,8 +385,7 @@ function xml_from_array($array, $callback = false, $type = '') {
if (is_array($value)) {
$value = xml_from_array($value,1,$type);
$string .= "\t\t<$key>\n$value\t\t</$key>\n";
}
else {
} else {
if ($key == "key") {
$string .= "\t\t<$key>$value</$key>\n";
} elseif (is_numeric($value)) {
@ -412,8 +411,7 @@ function xml_from_array($array, $callback = false, $type = '') {
// Call ourself
$value = xml_from_array($value, true);
$string .= "\t<content div=\"$key\">$value</content>\n";
}
else {
} else {
/* We need to escape the value */
$string .= "\t<content div=\"$key\"><![CDATA[$value]]></content>\n";
}
@ -433,7 +431,8 @@ function xml_from_array($array, $callback = false, $type = '') {
* xml_get_header
* This takes the type and returns the correct xml header
*/
function xml_get_header($type){
function xml_get_header($type)
{
switch ($type) {
case 'itunes':
$header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
@ -472,7 +471,8 @@ function xml_get_header($type){
* xml_get_footer
* This takes the type and returns the correct xml footer
*/
function xml_get_footer($type){
function xml_get_footer($type)
{
switch ($type) {
case 'itunes':
$footer = " </dict>\n" .
@ -495,8 +495,8 @@ function xml_get_footer($type){
* toggle_visible
* This is identical to the javascript command that it actually calls
*/
function toggle_visible($element) {
function toggle_visible($element)
{
echo '<script type="text/javascript">';
echo "toggleVisible('$element');";
echo "</script>\n";
@ -508,12 +508,11 @@ function toggle_visible($element) {
* This function takes a boolean value and then prints out a friendly text
* message.
*/
function print_bool($value) {
function print_bool($value)
{
if ($value) {
$string = '<span class="item_on">' . T_('On') . '</span>';
}
else {
} else {
$string = '<span class="item_off">' . T_('Off') . '</span>';
}
@ -526,8 +525,8 @@ function print_bool($value) {
* This shows the now playing templates and does some garbage collecion
* this should really be somewhere else
*/
function show_now_playing() {
function show_now_playing()
{
Session::gc(null);
Stream::gc_now_playing();
@ -536,6 +535,3 @@ function show_now_playing() {
require_once Config::get('prefix') . '/templates/show_now_playing.inc.php';
} // show_now_playing
?>

View file

@ -91,4 +91,3 @@ switch ($_REQUEST['action']) {
} // end switch action
UI::show_footer();
?>

View file

@ -61,17 +61,14 @@ if (($_POST['username'] && $_POST['password']) ||
$auth['info']['username'] = 'Admin - DEMO';
$auth['info']['fullname'] = 'Administrative User';
$auth['info']['offset_limit'] = 25;
}
else {
} else {
if ($_POST['username'] && $_POST['password']) {
$username = scrub_in($_POST['username']);
$password = $_POST['password'];
}
else {
} else {
if ($_SERVER['REMOTE_USER']) {
$username = $_SERVER['REMOTE_USER'];
}
elseif ($_SERVER['HTTP_REMOTE_USER']) {
} elseif ($_SERVER['HTTP_REMOTE_USER']) {
$username = $_SERVER['HTTP_REMOTE_USER'];
}
$password = '';
@ -81,8 +78,7 @@ if (($_POST['username'] && $_POST['password']) ||
if ($auth['success']) {
$username = $auth['username'];
}
else {
} else {
debug_event('Login', scrub_out($username) . ' attempted to login and failed', '1');
Error::add('general', T_('Error Username or Password incorrect, please try again'));
}
@ -117,8 +113,7 @@ if (($_POST['username'] && $_POST['password']) ||
if (User::create($username, $name, $email,
hash('sha256', mt_rand()), $access)) {
$user = User::get_from_username($username);
}
else {
} else {
$auth['success'] = false;
Error::add('general', T_('Unable to create local account'));
}
@ -168,5 +163,3 @@ if ($auth['success']) {
} // auth success
require Config::get('prefix') . '/templates/show_login_form.inc.php';
?>

View file

@ -28,4 +28,3 @@ require_once 'lib/init.php';
// To end a legitimate session, just call logout.
Auth::logout('',false);
?>

View file

@ -47,7 +47,8 @@ switch ($action) {
require Config::get('prefix') . '/templates/show_lostpassword_form.inc.php';
}
function send_newpassword($email,$current_ip){
function send_newpassword($email,$current_ip)
{
/* get the Client and set the new password */
$client = User::get_from_email($email);
if ($client->email == $email) {
@ -69,4 +70,3 @@ function send_newpassword($email,$current_ip){
}
return false;
}
?>

Some files were not shown because too many files have changed in this diff Show more