public function get(RESTApiRequest $request, $parent_id) { $rec_id = $parent_id; if (empty($this->params['users.id'])) { throw new RESTBadRequest("User required"); } $user_id = $this->params['users.id']; $user = \Stb::getById($user_id); if (empty($user)) { throw new RESTNotFound("User not found"); } $pvr = new \RemotePvr(); $recording = $pvr->getById($rec_id); if (empty($recording)) { throw new RESTNotFound("Recording not found"); } if ($recording['uid'] != $user_id) { throw new RESTNotFound("User don't have access to this recording"); } try { $url = $pvr->getUrlByRecId($rec_id); } catch (\Exception $e) { throw new RESTServerError("Failed to obtain url"); } if (preg_match("/(\\S+:\\/\\/\\S+)/", $url, $match)) { $url = $match[1]; } return $url; }
if (empty($user)) { header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); exit; } $pvr = new RemotePvr(); $recording = $pvr->getById($link['media_id']); if (empty($recording)) { header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); exit; } if ($recording['uid'] != $link['uid']) { header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); exit; } try { $url = $pvr->getUrlByRecId($link['media_id']); } catch (\Exception $e) { header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); exit; } if (preg_match('/(\\S+:\\/\\/\\S+)/', $url, $match)) { $url = $match[1]; } if ($url) { header("Location: " . $url); ob_end_clean(); exit; } } header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); exit;