## This program is free software: you can redistribute it and/or modify it ## under the terms of the GNU General Public License version 3, as published ## by the Free Software Foundation. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranties of ## MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR ## PURPOSE. See the GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License along ## with this program. If not, see . #### END LICENSE # /** * @file * the settings for Ampache Now Playing **/ if ($_POST['ampachenowplaying_hidden'] == 'Y' && $_POST['Submit'] == 'Save Settings' ) { // data was sent // data update_option('ampachenowplaying_show_agent', $_POST['ampachenowplaying_show_agent']); update_option('ampachenowplaying_show_date', $_POST['ampachenowplaying_show_date']); update_option('ampachenowplaying_show_album_art', $_POST['ampachenowplaying_show_album_art']); update_option('ampachenowplaying_show_now_playing', $_POST['ampachenowplaying_show_now_playing']); // validate user input if ( _ampachenowplaying_validate_input($_POST) == TRUE) { _print_updated('Settings saved'); } // validate username and password by authenticating if (isset($_POST['ampachenowplaying_username']) && isset($_POST['ampachenowplaying_password']) && $_POST['ampachenowplaying_username'] != '' && $_POST['ampachenowplaying_password'] != '') { if (_ampachenowplaying_validate_account($_POST) == TRUE) { update_option('ampachenowplaying_username', $_POST['ampachenowplaying_username']); update_option('ampachenowplaying_password', $_POST['ampachenowplaying_password']); _print_updated('Authenticated to Ampache succesfully!' ); } else { _print_updated('Authentication to Ampache failed! Invalid username/password or ACL error.' ); } } } if ($_POST['Submit'] == 'Clear Album Art') { _ampachenowplaying_clear_album_art(); } elseif ($_POST['Submit'] == 'Clear Album ID Table') { _ampachenowplaying_clear_album_ids(); } $rss_feed = get_option('ampachenowplaying_rss_feed', 'http://example.com/ampache/rss.php?type=now_playing'); $rss_threshold = get_option('ampachenowplaying_rss_threshold', 10); $show_agent = get_option('ampachenowplaying_show_agent', FALSE); $show_date = get_option('ampachenowplaying_show_date', FALSE); $show_album_art = get_option('ampachenowplaying_show_album_art', FALSE); $show_now_playing = get_option('ampachenowplaying_show_now_playing', 'Not Playing'); $username = get_option('ampachenowplaying_username', NULL); $password = get_option('ampachenowplaying_password', NULL); ?>



Example: http://example.com/ampache/rss.php?type=now_playing" ); ?>



Enabling this limits the amount of connections Wordpress will make to Ampache.
Set to 0 to disable (NOT RECOMMENDED). Default: 10" ); ?>


Note: changes to this might take a couple seconds to take effect due to the cache max time.'); ?>

/> Show the user agent

/> Show the time song was played

/> Show the album art

> Show the last song that was playing

> Show "Not Playing"


These fields are optional otherwise.') ?>





()

Both should be cleared if you re-catalog your music, or reinstall Ampache -- or if things are just acting weird."); ?>

0 ){ foreach($glob as $v) { if (file_exists($v)) { // delete the pictures unlink($v); #echo $v; $i += 1; } } } _print_updated("Album art cleared. $i Pictures deleted."); } /** * This function clears the album_ids and song_ids from the ampachenowplaying * table created in the wordpress database. This table links song_ids to album_ids * to cut down on the number of authentications drupal will need to make to Ampache * * @param none * @return none */ function _ampachenowplaying_clear_album_ids() { global $wpdb, $table_prefix; $ampache_table = $table_prefix . "ampachenowplaying"; $wpdb->query("DELETE FROM $ampache_table"); _print_updated('Ampache Album ID table cleared.'); } /** * Validate input */ function _ampachenowplaying_validate_input($new) { // check the rss threshold to make sure it's numeric and between 0 and 300 seconds $result = FALSE; $failed = FALSE; $max_cache_age = $new['ampachenowplaying_rss_threshold']; if (!isset($max_cache_age)) { // do nothing } elseif (!is_numeric($max_cache_age)) { // not numeric _print_updated('The max cache age value must be numeric.'); $failed = TRUE; } elseif ($max_cache_age <= 0 || $max_cache_age > 300) { // invalid number _print_updated('The max cache age value must be between 0 and 300.'); $failed = TRUE; } else { // successful update_option('ampachenowplaying_rss_threshold', $max_cache_age); $result = TRUE; } // check the rss feed url for validity $rss_feed = $new['ampachenowplaying_rss_feed']; if (!isset($rss_feed)) { // do nothing } elseif (!_ampachenowplaying_valid_url($rss_feed)) { _print_updated('The RSS feed must be a valid URL.'); $failed = TRUE; } else { // successful update_option('ampachenowplaying_rss_feed', $rss_feed); $result = TRUE; } if ($failed == FALSE) { return $result; } return FALSE; } function _ampachenowplaying_validate_account($new) { $user = $new['ampachenowplaying_username']; $pass = $new['ampachenowplaying_password']; $ampache_base = preg_replace('/rss\.php.*/', '', get_option('ampachenowplaying_rss_feed', NULL)); if ($ampache_base) { // the rss feed was saved before require_once('ampachenowplaying-api.php'); $auth = _ampachenowplaying_authenticate($user, $pass, $ampache_base); if ($auth) { // authentication successful return TRUE; } } return FALSE; } /** * Helper function to make sure a given URL is valid * * @param $url * A string with a URL in it * @return BOOL * True or False */ function _ampachenowplaying_valid_url($url) { return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url); } function _print_updated($string) { echo '

'; _e($string); echo '

'; } ?>