/** * Checks whether or not a track * can be played right now. * This is based on media_lock_mode * and the user's permissions. * * @author Ben Dodson * @version 7/7/05 * @since 7/7/05 **/ function canPlay($el, $user) { global $media_lock_mode; // What to return: $permissions = false; $locked = false; $valid = true; // First, is the user allowed to play it in general? if (checkPermission($user, "stream", $el->getPath("String")) === false) { return $permissions; } // Fast case: if (isNothing($media_lock_mode) || $media_lock_mode == "off") { return $valid; } $be = new jzBackend(); if ($media_lock_mode == "track") { $arr = $be->getPlaying(); foreach ($arr as $key => $more) { if ($more['fpath'] == $el->getFileName("host")) { return $locked; } } return $valid; } if ($media_lock_mode == "album") { $alb = $el->getAncestor("album"); if ($alb === false) { return $valid; } $arr = $be->getPlaying(); foreach ($arr as $key => $more) { $t = new jzMediaTrack($more['path']); $ta = $t->getAncestor("album"); if ($ta !== false) { if ($ta->getPath("String") == $alb->getPath("String")) { return $locked; } } } return $valid; } if ($media_lock_mode == "artist") { $artist = $el->getAncestor("artist"); if ($artist === false) { return $valid; } $arr = $be->getPlaying(); foreach ($arr as $key => $more) { $t = new jzMediaTrack($more['path']); $ta = $t->getAncestor("artist"); if ($ta !== false) { if ($ta->getPath("String") == $artist->getPath("String")) { return $locked; } } } return $valid; } if ($media_lock_mode == "genre") { $gen = $el->getAncestor("genre"); if ($gen === false) { return $valid; } $arr = $be->getPlaying(); foreach ($arr as $key => $more) { $t = new jzMediaTrack($more['path']); $ta = $t->getAncestor("genre"); if ($ta !== false) { if ($ta->getPath("String") == $gen->getPath("String")) { return $locked; } } } return $valid; } return $valid; }