Example #1
0
 public static function get_store()
 {
     $store = null;
     $store_path = AmpConfig::get('tmp_dir_path');
     if (empty($store_path)) {
         if (function_exists('sys_get_temp_dir')) {
             $store_path = sys_get_temp_dir();
         } else {
             if (strpos(PHP_OS, 'WIN') === 0) {
                 $store_path = $_ENV['TMP'];
                 if (!isset($store_path)) {
                     $store_path = 'C:\\Windows\\Temp';
                 }
             } else {
                 $store_path = @$_ENV['TMPDIR'];
                 if (!isset($store_path)) {
                     $store_path = '/tmp';
                 }
             }
         }
         $store_path .= DIRECTORY_SEPARATOR . '_openid';
     }
     if (empty($store_path) || !file_exists($store_path) && !mkdir($store_path)) {
         debug_event('openid', 'Could not access/create the FileStore directory ' . $store_path . '. Please check the effective permissions.', '5');
     } else {
         $store = new Auth_OpenID_FileStore($store_path);
         return $store;
     }
     return $store;
 }
Example #2
0
/**
 * get_themes
 * this looks in /themes and pulls all of the
 * theme.cfg.php files it can find and returns an
 * array of the results
 */
function get_themes()
{
    /* Open the themes dir and start reading it */
    $handle = opendir(AmpConfig::get('prefix') . '/themes');
    if (!is_resource($handle)) {
        debug_event('theme', 'Failed to open /themes directory', 2);
        return array();
    }
    $results = array();
    $theme_cfg = '/theme.cfg.php';
    while (($f = readdir($handle)) !== false) {
        debug_event('theme', "Checking {$f}", 5);
        $file = AmpConfig::get('prefix') . '/themes/' . $f;
        if (file_exists($file . $theme_cfg)) {
            debug_event('theme', "Loading {$theme_cfg} from {$f}", 5);
            $r = parse_ini_file($file . $theme_cfg);
            $r['path'] = $f;
            $results[$r['name']] = $r;
        } else {
            debug_event('theme', "{$theme_cfg} not found in {$f}", 5);
        }
    }
    // end while directory
    // Sort by the theme name
    ksort($results);
    return $results;
}
Example #3
0
function get_theme($name)
{
    static $_mapcache = array();
    if (strlen($name) < 1) {
        return false;
    }
    $name = strtolower($name);
    if (isset($_mapcache[$name])) {
        return $_mapcache[$name];
    }
    $config_file = AmpConfig::get('prefix') . "/themes/" . $name . "/theme.cfg.php";
    if (file_exists($config_file)) {
        $results = parse_ini_file($config_file);
        $results['path'] = $name;
        $results['base'] = explode(',', $results['base']);
        $nbbases = count($results['base']);
        for ($i = 0; $i < $nbbases; $i++) {
            $results['base'][$i] = explode('|', $results['base'][$i]);
        }
        $results['colors'] = explode(',', $results['colors']);
    } else {
        debug_event('theme', $config_file . ' not found.', 3);
        $results = null;
    }
    $_mapcache[$name] = $results;
    return $results;
}
Example #4
0
 /**
  * set
  *
  * This sets config values.
  */
 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));
         return false;
     }
     self::$_global[$name] = $value;
 }
Example #5
0
 /**
  * insert
  * This inserts a new record for the specified object
  * with the specified information, amazing!
  */
 public static function insert($type, $oid, $user, $agent = '')
 {
     $type = self::validate_type($type);
     $sql = "INSERT INTO `object_count` (`object_type`,`object_id`,`date`,`user`,`agent`) " . " VALUES (?, ?, ?, ?, ?)";
     $db_results = Dba::write($sql, array($type, $oid, time(), $user, $agent));
     if (!$db_results) {
         debug_event('statistics', 'Unabled to insert statistics:' . $sql, '3');
     }
 }
Example #6
0
 /**
  * insert
  *
  * This inserts the song preview described by the passed array
  */
 public static function insert($results)
 {
     $sql = 'INSERT INTO `song_preview` (`file`, `album_mbid`, `artist`, `artist_mbid`, `title`, `disk`, `track`, `mbid`, `session`) ' . ' VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
     $db_results = Dba::write($sql, array($results['file'], $results['album_mbid'], $results['artist'], $results['artist_mbid'], $results['title'], $results['disk'], $results['track'], $results['mbid'], $results['session']));
     if (!$db_results) {
         debug_event('song_preview', 'Unable to insert ' . $results[''], 2);
         return false;
     }
     return Dba::insert_id();
 }
Example #7
0
 public function getChild($name)
 {
     debug_event('webdav', 'Catalog getChild for `' . $name . '`', 5);
     $matches = Catalog::search_childrens($name, $this->catalog_id);
     debug_event('webdav', 'Found ' . count($matches) . ' childs.', 5);
     // Always return first match
     // Warning: this means that two items with the same name will not be supported for now
     if (count($matches) > 0) {
         return WebDAV_Directory::getChildFromArray($matches[0]);
     }
     throw new DAV\Exception\NotFound('The artist with name: ' . $name . ' could not be found');
 }
Example #8
0
 public function get()
 {
     debug_event('webdav', 'File get', 5);
     // Only media associated to a local catalog is supported
     if ($this->libitem->catalog) {
         $catalog = Catalog::create_from_id($this->libitem->catalog);
         if ($catalog->get_type() === 'local') {
             return fopen($this->libitem->file, 'r');
         } else {
             debug_event('webdav', 'Catalog associated to the media is not local. This is currently unsupported.', 3);
         }
     } else {
         debug_event('webdav', 'No catalog associated to the media.', 3);
     }
     return null;
 }
Example #9
0
 /**
  * gc
  *
  * Remove bookmark for items that no longer exist.
  */
 public static function gc($object_type = null, $object_id = null)
 {
     $types = array('song', 'video', 'podcast_episode');
     if ($object_type != null) {
         if (in_array($object_type, $types)) {
             $sql = "DELETE FROM `bookmark` WHERE `object_type` = ? AND `object_id` = ?";
             Dba::write($sql, array($object_type, $object_id));
         } else {
             debug_event('bookmark', 'Garbage collect on type `' . $object_type . '` is not supported.', 1);
         }
     } else {
         foreach ($types as $type) {
             Dba::write("DELETE FROM `bookmark` USING `bookmark` LEFT JOIN `{$type}` ON `{$type}`.`id` = `bookmark`.`object_id` WHERE `bookmark`.`object_type` = '{$type}' AND `{$type}`.`id` IS NULL");
         }
     }
 }
Example #10
0
 /**
  * gc
  *
  * Cleans out orphaned shoutbox items
  */
 public static function gc($object_type = null, $object_id = null)
 {
     $types = array('song', 'album', 'artist', 'label');
     if ($object_type != null) {
         if (in_array($object_type, $types)) {
             $sql = "DELETE FROM `user_shout` WHERE `object_type` = ? AND `object_id` = ?";
             Dba::write($sql, array($object_type, $object_id));
         } else {
             debug_event('shoutbox', 'Garbage collect on type `' . $object_type . '` is not supported.', 1);
         }
     } else {
         foreach ($types as $type) {
             Dba::write("DELETE FROM `user_shout` USING `user_shout` LEFT JOIN `{$type}` ON `{$type}`.`id` = `user_shout`.`object_id` WHERE `{$type}`.`id` IS NULL AND `user_shout`.`object_type` = '{$type}'");
         }
     }
 }
Example #11
0
 public function getChild($name)
 {
     // Clean song name
     if (strtolower(get_class($this->libitem)) === "album") {
         $splitname = explode('-', $name, 3);
         $name = trim($splitname[count($splitname) - 1]);
         $nameinfo = pathinfo($name);
         $name = $nameinfo['filename'];
     }
     debug_event('webdav', 'Directory getChild: ' . $name, 5);
     $matches = $this->libitem->search_childrens($name);
     // Always return first match
     // Warning: this means that two items with the same name will not be supported for now
     if (count($matches) > 0) {
         return WebDAV_Directory::getChildFromArray($matches[0]);
     }
     throw new DAV\Exception\NotFound('The child with name: ' . $name . ' could not be found');
 }
Example #12
0
 protected static function get_images($artist_name)
 {
     $images = array();
     if (AmpConfig::get('echonest_api_key')) {
         $echonest = new EchoNest_Client(new EchoNest_HttpClient_Requests());
         $echonest->authenticate(AmpConfig::get('echonest_api_key'));
         try {
             $images = $echonest->getArtistApi()->setName($artist_name)->getImages();
         } catch (Exception $e) {
             debug_event('echonest', 'EchoNest artist images error: ' . $e->getMessage(), '1');
         }
     }
     foreach (Plugin::get_plugins('get_photos') as $plugin_name) {
         $plugin = new Plugin($plugin_name);
         if ($plugin->load($GLOBALS['user'])) {
             $images += $plugin->_plugin->get_photos($artist_name);
         }
     }
     return $images;
 }
Example #13
0
 private function parseDescriptionUrl($descriptionUrl)
 {
     debug_event('upnpdevice', 'parseDescriptionUrl: ' . $descriptionUrl, 5);
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $descriptionUrl);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $response = curl_exec($ch);
     curl_close($ch);
     //!!debug_event('upnpdevice', 'parseDescriptionUrl response: ' . $response, 5);
     $responseXML = simplexml_load_string($response);
     $services = $responseXML->device->serviceList->service;
     foreach ($services as $service) {
         $serviceType = $service->serviceType;
         $serviceTypeNames = explode(":", $serviceType);
         $serviceTypeName = $serviceTypeNames[3];
         $this->_settings['controlURLs'][$serviceTypeName] = (string) $service->controlURL;
         $this->_settings['eventURLs'][$serviceTypeName] = (string) $service->eventSubURL;
     }
     $urldata = parse_url($descriptionUrl);
     $this->_settings['host'] = $urldata['scheme'] . '://' . $urldata['host'] . ':' . $urldata['port'];
     $this->_settings['descriptionURL'] = $descriptionUrl;
     Session::create(array('type' => 'api', 'sid' => 'upnp_dev_' . $descriptionUrl, 'value' => serialize($this->_settings)));
 }
Example #14
0
 /**
  * delete_track
  * This must take an array of ID's (as passed by get function) from Ampache
  * and delete them from vlc webinterface
  */
 public function delete_track($object_id)
 {
     if (is_null($this->_vlc->delete_pos($object_id))) {
         debug_event('vlc_del', 'ERROR Unable to delete ' . $object_id . ' from Vlc', '1');
         return false;
     }
     return true;
 }
Example #15
0
 /**
  * gather_lastfm
  * This returns the art from lastfm. It doesn't currently require an
  * account but may in the future.
  * @param int $limit
  * @param array $data
  * @return array
  */
 public function gather_lastfm($limit = 5, $data = array())
 {
     if (!$limit) {
         $limit = 5;
     }
     $images = array();
     if ($this->type != 'album' || empty($data['artist']) || empty($data['album'])) {
         return $images;
     }
     try {
         $xmldata = Recommendation::album_search($data['artist'], $data['album']);
         if (!count($xmldata)) {
             return array();
         }
         $xalbum = $xmldata->album;
         if (!$xalbum) {
             return array();
         }
         $coverart = (array) $xalbum->image;
         if (!$coverart) {
             return array();
         }
         ksort($coverart);
         foreach ($coverart as $url) {
             // We need to check the URL for the /noimage/ stuff
             if (is_array($url) || strpos($url, '/noimage/') !== false) {
                 debug_event('LastFM', 'Detected as noimage, skipped ' . $url, 3);
                 continue;
             }
             // HACK: we shouldn't rely on the extension to determine file type
             $results = pathinfo($url);
             $mime = 'image/' . $results['extension'];
             $images[] = array('url' => $url, 'mime' => $mime, 'title' => 'LastFM');
             if ($limit && count($images) >= $limit) {
                 return $images;
             }
         }
         // end foreach
     } catch (Exception $e) {
         debug_event('art', 'LastFM error: ' . $e->getMessage(), 5);
     }
     return $images;
 }
Example #16
0
 /**
  * form_verify
  *
  * This takes a form name and then compares it with the posted sid, if
  * they don't match then it returns false and doesn't let the person
  * continue
  */
 public static function form_verify($name, $type = 'post')
 {
     switch ($type) {
         case 'post':
             $sid = $_POST['form_validation'];
             break;
         case 'get':
             $sid = $_GET['form_validation'];
             break;
         case 'cookie':
             $sid = $_COOKIE['form_validation'];
             break;
         case 'request':
             $sid = $_REQUEST['form_validation'];
             break;
         default:
             return false;
     }
     if (!isset($_SESSION['forms'][$sid])) {
         debug_event('Core', "Form {$sid} not found in session, rejecting request", 2);
         return false;
     }
     $form = $_SESSION['forms'][$sid];
     unset($_SESSION['forms'][$sid]);
     if ($form['name'] == $name) {
         debug_event('Core', "Verified SID {$sid} for {$type} form {$name}", 5);
         if ($form['expire'] < time()) {
             debug_event('Core', "Form {$sid} is expired, rejecting request", 2);
             return false;
         }
         return true;
     }
     // OMG HAX0RZ
     debug_event('Core', "{$type} form {$sid} failed consistency check, rejecting request", 2);
     return false;
 }
Example #17
0
/**
 * Sub-Ajax page, requires AJAX_INCLUDE
 */
require_once '../lib/init.php';
if (!Core::is_session_started()) {
    session_start();
}
if (!defined('AJAX_INCLUDE')) {
    exit;
}
if (isset($_REQUEST['browse_id'])) {
    $browse_id = $_REQUEST['browse_id'];
} else {
    $browse_id = null;
}
debug_event('browse.ajax.php', 'Called for action: {' . $_REQUEST['action'] . '}', '5');
$browse = new Browse($browse_id);
if (isset($_REQUEST['show_header']) && $_REQUEST['show_header']) {
    $browse->set_show_header($_REQUEST['show_header'] == 'true');
}
$argument = null;
if ($_REQUEST['argument']) {
    $argument = scrub_in($_REQUEST['argument']);
}
$results = array();
switch ($_REQUEST['action']) {
    case 'browse':
        $object_ids = array();
        // Check 'value' with isset because it can null
        //(user type a "start with" word and deletes it)
        if ($_REQUEST['key'] && (isset($_REQUEST['multi_alpha_filter']) or isset($_REQUEST['value']))) {
Example #18
0
// Switch on Action
switch ($_REQUEST['action']) {
    case 'delete':
        if (AmpConfig::get('demo_mode')) {
            break;
        }
        $song_id = scrub_in($_REQUEST['song_id']);
        show_confirmation(T_('Song Deletion'), T_('Are you sure you want to permanently delete this song?'), AmpConfig::get('web_path') . "/song.php?action=confirm_delete&song_id=" . $song_id, 1, 'delete_song');
        break;
    case 'confirm_delete':
        if (AmpConfig::get('demo_mode')) {
            break;
        }
        $song = new Song($_REQUEST['song_id']);
        if (!Catalog::can_remove($song)) {
            debug_event('song', 'Unauthorized to remove the song `.' . $song->id . '`.', 1);
            UI::access_denied();
            exit;
        }
        if ($song->remove_from_disk()) {
            show_confirmation(T_('Song Deletion'), T_('Song has been deleted.'), AmpConfig::get('web_path'));
        } else {
            show_confirmation(T_('Song Deletion'), T_('Cannot delete this song.'), AmpConfig::get('web_path'));
        }
        break;
    case 'show_lyrics':
        $song = new Song($_REQUEST['song_id']);
        $song->format();
        $song->fill_ext_info();
        $lyrics = $song->get_lyrics();
        require_once AmpConfig::get('prefix') . UI::find_template('show_lyrics.inc.php');
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
define('AJAX_INCLUDE', '1');
require_once '../lib/init.php';
debug_event('refresh_reordered.server.php', 'Called for action: {' . $_REQUEST['action'] . '}', '5');
/* Switch on the action passed in */
switch ($_REQUEST['action']) {
    case 'refresh_playlist_medias':
        $playlist = new Playlist($_REQUEST['id']);
        $playlist->format();
        $object_ids = $playlist->get_items();
        $browse = new Browse();
        $browse->set_type('playlist_media');
        $browse->add_supplemental_object('playlist', $playlist->id);
        $browse->set_static_content(true);
        $browse->show_objects($object_ids);
        $browse->store();
        break;
    case 'refresh_album_songs':
        $browse = new Browse();
Example #20
0
 /**
  * update_360051
  *
  * Copy default .htaccess configurations
  */
 public static function update_360051()
 {
     require_once AmpConfig::get('prefix') . '/lib/install.lib.php';
     if (!install_check_server_apache()) {
         debug_event('update', 'Not using Apache, update 360051 skipped.', '5');
         return true;
     }
     $htaccess_play_file = AmpConfig::get('prefix') . '/play/.htaccess';
     $htaccess_rest_file = AmpConfig::get('prefix') . '/rest/.htaccess';
     $htaccess_channel_file = AmpConfig::get('prefix') . '/channel/.htaccess';
     $ret = true;
     if (!is_readable($htaccess_play_file)) {
         $created = false;
         if (check_htaccess_play_writable()) {
             if (!install_rewrite_rules($htaccess_play_file, AmpConfig::get('raw_web_path'), false)) {
                 AmpError::add('general', T_('File copy error.'));
             } else {
                 $created = true;
             }
         }
         if (!$created) {
             AmpError::add('general', T_('Cannot copy default .htaccess file.') . ' Please copy <b>' . $htaccess_play_file . '.dist</b> to <b>' . $htaccess_play_file . '</b>.');
             $ret = false;
         }
     }
     if (!is_readable($htaccess_rest_file)) {
         $created = false;
         if (check_htaccess_rest_writable()) {
             if (!install_rewrite_rules($htaccess_rest_file, AmpConfig::get('raw_web_path'), false)) {
                 AmpError::add('general', T_('File copy error.'));
             } else {
                 $created = true;
             }
         }
         if (!$created) {
             AmpError::add('general', T_('Cannot copy default .htaccess file.') . ' Please copy <b>' . $htaccess_rest_file . '.dist</b> to <b>' . $htaccess_rest_file . '</b>.');
             $ret = false;
         }
     }
     if (!is_readable($htaccess_channel_file)) {
         $created = false;
         if (check_htaccess_channel_writable()) {
             if (!install_rewrite_rules($htaccess_channel_file, AmpConfig::get('raw_web_path'), false)) {
                 AmpError::add('general', T_('File copy error.'));
             } else {
                 $created = true;
             }
         }
         if (!$created) {
             AmpError::add('general', T_('Cannot copy default .htaccess file.') . ' Please copy <b>' . $htaccess_channel_file . '.dist</b> to <b>' . $htaccess_channel_file . '</b>.');
             $ret = false;
         }
     }
     return $ret;
 }
Example #21
0
 /**
  * reset_db_charset
  *
  * This cruises through the database and trys to set the charset to the
  * current site charset. This is an admin function that can be run by an
  * administrator only. This can mess up data if you switch between charsets
  * that are not overlapping.
  */
 public static function reset_db_charset()
 {
     $translated_charset = self::translate_to_mysqlcharset(AmpConfig::get('site_charset'));
     $target_charset = $translated_charset['charset'];
     $target_collation = $translated_charset['collation'];
     // Alter the charset for the entire database
     $sql = "ALTER DATABASE `" . AmpConfig::get('database_name') . "` DEFAULT CHARACTER SET {$target_charset} COLLATE {$target_collation}";
     Dba::write($sql);
     $sql = "SHOW TABLES";
     $db_results = Dba::read($sql);
     // Go through the tables!
     while ($row = Dba::fetch_row($db_results)) {
         $sql = "DESCRIBE `" . $row['0'] . "`";
         $describe_results = Dba::read($sql);
         // Change the tables default charset and colliation
         $sql = "ALTER TABLE `" . $row['0'] . "`  DEFAULT CHARACTER SET {$target_charset} COLLATE {$target_collation}";
         Dba::write($sql);
         // Iterate through the columns of the table
         while ($table = Dba::fetch_assoc($describe_results)) {
             if (strpos($table['Type'], 'varchar') !== false || strpos($table['Type'], 'enum') !== false || strpos($table['Table'], 'text') !== false) {
                 $sql = "ALTER TABLE `" . $row['0'] . "` MODIFY `" . $table['Field'] . "` " . $table['Type'] . " CHARACTER SET " . $target_charset;
                 $charset_results = Dba::write($sql);
                 if (!$charset_results) {
                     debug_event('CHARSET', 'Unable to update the charset of ' . $table['Field'] . '.' . $table['Type'] . ' to ' . $target_charset, '3');
                 }
                 // if it fails
             }
         }
     }
 }
Example #22
0
 /**
  * Check stream control
  * @param array $media_ids
  * @return boolean
  */
 public function stream_control($media_ids)
 {
     // No check if unlimited bandwidth (= -1)
     if ($this->bandwidth_max < 0) {
         return true;
     }
     // Calculate all media size
     $next_total = 0;
     foreach ($media_ids as $media_id) {
         $media = new $media_id['object_type']($media_id['object_id']);
         $next_total += $media->size;
     }
     $graph = new Graph();
     $end_date = time();
     $start_date = $end_date - $this->bandwidth_days * 86400;
     $current_total = $graph->get_total_bandwidth($this->user_id, $start_date, $end_date);
     $next_total += $current_total;
     $max = $this->bandwidth_max * 1024 * 1024;
     debug_event('stream_control_bandwidth', 'Next stream bandwidth will be ' . $next_total . ' / ' . $max, 3);
     return $next_total <= $max;
 }
Example #23
0
 /**
  * show_objects
  * This takes an array of objects
  * and requires the correct template based on the
  * type that we are currently browsing
  *
  * @param int[] $object_ids
  */
 public function show_objects($object_ids = null, $argument = null)
 {
     if ($this->is_simple() || !is_array($object_ids)) {
         $object_ids = $this->get_saved();
     } else {
         $this->save_objects($object_ids);
     }
     // Limit is based on the user's preferences if this is not a
     // simple browse because we've got too much here
     if ($this->get_start() >= 0 && count($object_ids) > $this->get_start() && !$this->is_simple()) {
         $object_ids = array_slice($object_ids, $this->get_start(), $this->get_offset(), true);
     } else {
         if (!count($object_ids)) {
             $this->set_total(0);
         }
     }
     // Load any additional object we need for this
     $extra_objects = $this->get_supplemental_objects();
     $browse = $this;
     foreach ($extra_objects as $class_name => $id) {
         ${$class_name} = new $class_name($id);
     }
     $match = '';
     // 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')) {
         $match = ' (' . $filter_value . ')';
         /*} elseif ($filter_value = $this->get_filter('regex_match')) {
               $match = ' (' . $filter_value . ')';
           } elseif ($filter_value = $this->get_filter('regex_not_match')) {
               $match = ' (' . $filter_value . ')';*/
     } elseif ($filter_value = $this->get_filter('catalog')) {
         // Get the catalog title
         $catalog = Catalog::create_from_id(intval($filter_value));
         $match = ' (' . $catalog->name . ')';
     }
     $type = $this->get_type();
     // Update the session value only if it's allowed on the current browser
     if ($this->get_update_session()) {
         $_SESSION['browse_current_' . $type]['start'] = $browse->get_start();
     }
     // Set the correct classes based on type
     $class = "box browse_" . $type;
     $argument_param = $argument ? '&argument=' . scrub_in($argument) : '';
     debug_event('browse', 'Show objects called for type {' . $type . '}', '5');
     $limit_threshold = $this->get_threshold();
     // Switch on the type of browsing we're doing
     switch ($type) {
         case 'song':
             $box_title = T_('Songs') . $match;
             Song::build_cache($object_ids, $limit_threshold);
             $box_req = AmpConfig::get('prefix') . '/templates/show_songs.inc.php';
             break;
         case 'album':
             Album::build_cache($object_ids);
             $box_title = T_('Albums') . $match;
             if (is_array($argument)) {
                 $allow_group_disks = $argument['group_disks'];
                 if ($argument['title']) {
                     $box_title = $argument['title'];
                 }
             } else {
                 $allow_group_disks = false;
             }
             $box_req = AmpConfig::get('prefix') . '/templates/show_albums.inc.php';
             break;
         case 'user':
             $box_title = T_('Users') . $match;
             $box_req = AmpConfig::get('prefix') . '/templates/show_users.inc.php';
             break;
         case 'artist':
             $box_title = T_('Artists') . $match;
             Artist::build_cache($object_ids, true, $limit_threshold);
             $box_req = AmpConfig::get('prefix') . '/templates/show_artists.inc.php';
             break;
         case 'live_stream':
             require_once AmpConfig::get('prefix') . '/templates/show_live_stream.inc.php';
             $box_title = T_('Radio Stations') . $match;
             $box_req = AmpConfig::get('prefix') . '/templates/show_live_streams.inc.php';
             break;
         case 'playlist':
             Playlist::build_cache($object_ids);
             $box_title = T_('Playlists') . $match;
             $box_req = AmpConfig::get('prefix') . '/templates/show_playlists.inc.php';
             break;
         case 'playlist_song':
             $box_title = T_('Playlist Songs') . $match;
             $box_req = AmpConfig::get('prefix') . '/templates/show_playlist_songs.inc.php';
             break;
         case 'playlist_localplay':
             $box_title = T_('Current Playlist');
             $box_req = AmpConfig::get('prefix') . '/templates/show_localplay_playlist.inc.php';
             UI::show_box_bottom();
             break;
         case 'smartplaylist':
             $box_title = T_('Smart Playlists') . $match;
             $box_req = AmpConfig::get('prefix') . '/templates/show_searches.inc.php';
             break;
         case 'catalog':
             $box_title = T_('Catalogs');
             $box_req = AmpConfig::get('prefix') . '/templates/show_catalogs.inc.php';
             break;
         case 'shoutbox':
             $box_title = T_('Shoutbox Records');
             $box_req = AmpConfig::get('prefix') . '/templates/show_manage_shoutbox.inc.php';
             break;
         case 'tag':
             Tag::build_cache($object_ids);
             $box_title = T_('Tag Cloud');
             $box_req = AmpConfig::get('prefix') . '/templates/show_tagcloud.inc.php';
             break;
         case 'video':
             Video::build_cache($object_ids);
             $video_type = 'video';
             $box_title = T_('Videos');
             $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php';
             break;
         case 'democratic':
             $box_title = T_('Democratic Playlist');
             $box_req = AmpConfig::get('prefix') . '/templates/show_democratic_playlist.inc.php';
             break;
         case 'wanted':
             $box_title = T_('Wanted Albums');
             $box_req = AmpConfig::get('prefix') . '/templates/show_wanted_albums.inc.php';
             break;
         case 'share':
             $box_title = T_('Shared Objects');
             $box_req = AmpConfig::get('prefix') . '/templates/show_shared_objects.inc.php';
             break;
         case 'song_preview':
             $box_title = T_('Songs');
             $box_req = AmpConfig::get('prefix') . '/templates/show_song_previews.inc.php';
             break;
         case 'channel':
             $box_title = T_('Channels');
             $box_req = AmpConfig::get('prefix') . '/templates/show_channels.inc.php';
             break;
         case 'broadcast':
             $box_title = T_('Broadcasts');
             $box_req = AmpConfig::get('prefix') . '/templates/show_broadcasts.inc.php';
             break;
         case 'license':
             $box_title = T_('Media Licenses');
             $box_req = AmpConfig::get('prefix') . '/templates/show_manage_license.inc.php';
             break;
         case 'tvshow':
             $box_title = T_('TV Shows');
             $box_req = AmpConfig::get('prefix') . '/templates/show_tvshows.inc.php';
             break;
         case 'tvshow_season':
             $box_title = T_('Seasons');
             $box_req = AmpConfig::get('prefix') . '/templates/show_tvshow_seasons.inc.php';
             break;
         case 'tvshow_episode':
             $box_title = T_('Episodes');
             $video_type = $type;
             $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php';
             break;
         case 'movie':
             $box_title = T_('Movies');
             $video_type = $type;
             $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php';
             break;
         case 'clip':
             $box_title = T_('Clips');
             $video_type = $type;
             $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php';
             break;
         case 'personal_video':
             $box_title = T_('Personal Videos');
             $video_type = $type;
             $box_req = AmpConfig::get('prefix') . '/templates/show_videos.inc.php';
             break;
         case 'label':
             $box_title = T_('Labels');
             $box_req = AmpConfig::get('prefix') . '/templates/show_labels.inc.php';
             break;
         case 'pvmsg':
             $box_title = T_('Private Messages');
             $box_req = AmpConfig::get('prefix') . '/templates/show_pvmsgs.inc.php';
             break;
         default:
             // Rien a faire
             break;
     }
     // end switch on type
     Ajax::start_container($this->get_content_div(), 'browse_content');
     if ($this->get_show_header()) {
         if (isset($box_req) && isset($box_title)) {
             UI::show_box_top($box_title, $class);
         }
     }
     if (isset($box_req)) {
         require $box_req;
     }
     if ($this->get_show_header()) {
         if (isset($box_req)) {
             UI::show_box_bottom();
         }
         echo '<script type="text/javascript">';
         echo Ajax::action('?page=browse&action=get_filters&browse_id=' . $this->id . $argument_param, '');
         echo ';</script>';
     } else {
         if (!$this->get_use_pages()) {
             $this->show_next_link($argument);
         }
     }
     Ajax::end_container();
 }
Example #24
0
 /**
  * load
  * This loads up the data we need into this object, this stuff comes
  * from the preferences.
  */
 public function load($user)
 {
     $this->api_key = AmpConfig::get('lastfm_api_key');
     $this->secret = AmpConfig::get('lastfm_api_secret');
     $user->set_preferences();
     $data = $user->prefs;
     $this->user_id = $user->id;
     // check if user have a session key
     if (strlen(trim($data['lastfm_challenge']))) {
         $this->challenge = trim($data['lastfm_challenge']);
     } else {
         debug_event($this->name, 'No session key, not scrobbling (need to grant Ampache to last.fm)', '5');
         return false;
     }
     return true;
 }
Example #25
0
 private function api_call($func)
 {
     $url = 'http://www.theaudiodb.com/api/v1/json/' . $this->api_key . '/' . $func;
     debug_event('tadb', 'API call: ' . $url, 5);
     $request = Requests::get($url, array(), Core::requests_options());
     if ($request->status_code != 200) {
         return null;
     }
     return json_decode($request->body);
 }
Example #26
0
 /** 
  * sendCommand
  * This is the core of this library it takes care of sending the HTTP
  * request to the vlc server and getting the response 
  */
 private function sendCommand($cmd, $args)
 {
     $fp = fsockopen($this->host, $this->port, $errno, $errstr);
     if (!$fp) {
         debug_event('vlc', "VlcPlayer: {$errstr} ({$errno})", '1');
         return null;
     }
     // Define the base message
     $msg = "GET /requests/{$cmd}";
     // Foreach our arguments
     foreach ($args as $key => $val) {
         $msg .= "{$key}={$val}";
     }
     $msg .= " HTTP/1.0\r\n";
     // Basic authentication
     if (!empty($this->password)) {
         $b64pwd = base64_encode(':' . $this->password);
         $msg .= "Authorization: Basic " . $b64pwd . "\r\n";
     }
     $msg .= "\r\n";
     fputs($fp, $msg);
     $data = '';
     $header = "";
     // here the header is split from the xml to avoid problems
     do {
         // loop until the end of the header
         $header .= fgets($fp);
     } while (strpos($header, "\r\n\r\n") === false);
     // now put the body in variable $data
     while (!feof($fp)) {
         $data .= fgets($fp);
     }
     fclose($fp);
     // send to xml parser and make an array
     $result = $this->xmltoarray($data);
     return $result;
 }
Example #27
0
// end action switch
// See if we need a special streamtype
switch ($_REQUEST['action']) {
    case 'download':
        $stream_type = 'download';
        break;
    case 'democratic':
        // Don't let them loop it
        // FIXME: This looks hacky
        if (AmpConfig::get('play_type') == 'democratic') {
            AmpConfig::set('play_type', 'stream', true);
        }
    default:
        $stream_type = AmpConfig::get('play_type');
        if ($stream_type == 'stream') {
            $stream_type = AmpConfig::get('playlist_type');
        }
        break;
}
debug_event('stream.php', 'Stream Type: ' . $stream_type . ' Media IDs: ' . json_encode($media_ids), 5);
if (count(media_ids)) {
    $playlist = new Stream_Playlist();
    $playlist->add($media_ids);
    if (isset($urls)) {
        $playlist->add_urls($urls);
    }
    // Depending on the stream type, will either generate a redirect or actually do the streaming.
    $playlist->generate_playlist($stream_type, true);
} else {
    debug_event('stream.php', 'No item. Ignoring...', 5);
}
Example #28
0
 /**
  * load
  * This loads up the data we need into this object, this stuff comes 
  * from the preferences.
  */
 public function load($user)
 {
     $user->set_preferences();
     $data = $user->prefs;
     if (strlen(trim($data['librefm_user']))) {
         $this->username = trim($data['librefm_user']);
     } else {
         debug_event($this->name, 'No Username, not scrobbling', '3');
         return false;
     }
     if (strlen(trim($data['librefm_md5_pass']))) {
         $this->password = trim($data['librefm_md5_pass']);
     } else {
         debug_event($this->name, 'No Password, not scrobbling', '3');
         return false;
     }
     $this->user_id = $user->id;
     // If we don't have the other stuff try to get it before giving up
     if (!$data['librefm_host'] || !$data['librefm_port'] || !$data['librefm_url'] || !$data['librefm_challenge']) {
         debug_event($this->name, 'Running Handshake, missing information', '3');
         if (!$this->set_handshake($this->user_id)) {
             debug_event($this->name, 'Handshake failed, you lose', '3');
             return false;
         }
     } else {
         $this->hostname = $data['librefm_host'];
         $this->port = $data['librefm_port'];
         $this->path = $data['librefm_url'];
         $this->challenge = $data['librefm_challenge'];
     }
     return true;
 }
Example #29
0
 /**
  * update_tag_list
  * Update the tags list based on commated list (ex. tag1,tag2,tag3,..)
  */
 public static function update_tag_list($tags_comma, $type, $object_id, $overwrite)
 {
     debug_event('tag.class', 'Updating tags for values {' . $tags_comma . '} type {' . $type . '} object_id {' . $object_id . '}', '5');
     $ctags = Tag::get_top_tags($type, $object_id);
     $editedTags = explode(",", $tags_comma);
     if (is_array($ctags)) {
         foreach ($ctags as $ctid => $ctv) {
             if ($ctv['id'] != '') {
                 $ctag = new Tag($ctv['id']);
                 debug_event('tag.class', 'Processing tag {' . $ctag->name . '}...', '5');
                 $found = false;
                 foreach ($editedTags as $tk => $tv) {
                     if ($ctag->name == $tv) {
                         $found = true;
                         break;
                     }
                 }
                 if ($found) {
                     debug_event('tag.class', 'Already found. Do nothing.', '5');
                     unset($editedTags[$tk]);
                 } else {
                     if ($overwrite) {
                         debug_event('tag.class', 'Not found in the new list. Delete it.', '5');
                         $ctag->remove_map($type, $object_id);
                     }
                 }
             }
         }
     }
     // Look if we need to add some new tags
     foreach ($editedTags as $tk => $tv) {
         if ($tv != '') {
             debug_event('tag.class', 'Adding new tag {' . $tv . '}', '5');
             Tag::add($type, $object_id, $tv, false);
         }
     }
 }
Example #30
0
 /**
  * jukeboxControl
  * Control the jukebox.
  * Takes the action with optional index, offset, song id and volume gain in parameters.
  * Not supported.
  */
 public static function jukeboxcontrol($input)
 {
     self::check_version($input, "1.2.0");
     $action = self::check_parameter($input, 'action');
     $id = $input['id'];
     $gain = $input['gain'];
     $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_DATA_NOTFOUND);
     debug_event('subsonic', 'Using Localplay controller: ' . AmpConfig::get('localplay_controller'), 5);
     $localplay = new Localplay(AmpConfig::get('localplay_controller'));
     if ($localplay->connect()) {
         $ret = false;
         switch ($action) {
             case 'get':
             case 'status':
                 $ret = true;
                 break;
             case 'start':
                 $ret = $localplay->play();
                 break;
             case 'stop':
                 $ret = $localplay->stop();
                 break;
             case 'skip':
                 if (isset($input['index'])) {
                     if ($localplay->skip($input['index'])) {
                         $ret = $localplay->play();
                     }
                 } elseif (isset($input['offset'])) {
                     debug_event('subsonic', 'Skip with offset is not supported on JukeboxControl.', 5);
                 } else {
                     $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_MISSINGPARAM);
                 }
                 break;
             case 'set':
                 $localplay->delete_all();
             case 'add':
                 if ($id) {
                     if (!is_array($id)) {
                         $rid = array();
                         $rid[] = $id;
                         $id = $rid;
                     }
                     foreach ($id as $i) {
                         $url = null;
                         if (Subsonic_XML_Data::isSong($i)) {
                             $url = Song::generic_play_url('song', Subsonic_XML_Data::getAmpacheId($i), '', 'api');
                         } elseif (Subsonic_XML_Data::isVideo($i)) {
                             $url = Song::generic_play_url('video', Subsonic_XML_Data::getAmpacheId($i), '', 'api');
                         }
                         if ($url) {
                             debug_event('subsonic', 'Adding ' . $url, 5);
                             $stream = array();
                             $stream['url'] = $url;
                             $ret = $localplay->add_url(new Stream_URL($stream));
                         }
                     }
                 }
                 break;
             case 'clear':
                 $ret = $localplay->delete_all();
                 break;
             case 'remove':
                 if (isset($input['index'])) {
                     $ret = $localplay->delete_track($input['index']);
                 } else {
                     $r = Subsonic_XML_Data::createError(Subsonic_XML_Data::SSERROR_MISSINGPARAM);
                 }
                 break;
             case 'shuffle':
                 $ret = $localplay->random(true);
                 break;
             case 'setGain':
                 $ret = $localplay->volume_set($gain * 100);
                 break;
         }
         if ($ret) {
             $r = Subsonic_XML_Data::createSuccessResponse();
             if ($action == 'get') {
                 Subsonic_XML_Data::addJukeboxPlaylist($r, $localplay);
             } else {
                 Subsonic_XML_Data::createJukeboxStatus($r, $localplay);
             }
         }
     }
     self::apiOutput($input, $r);
 }