From 3668475526cbc4950b9ccc6a08d4b21c1b591d13 Mon Sep 17 00:00:00 2001 From: Mitsukarenai Date: Fri, 18 Jul 2014 14:06:39 +0200 Subject: [PATCH] Whyd: tightening input, use username if provided --- bridges/WhydBridge.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bridges/WhydBridge.php b/bridges/WhydBridge.php index 6f98f574..78bc303b 100644 --- a/bridges/WhydBridge.php +++ b/bridges/WhydBridge.php @@ -8,7 +8,7 @@ * @description Returns 10 newest music from user profile * @maintainer kranack * @update 2014-07-18 -* @use1(u="username") +* @use1(u="username/id") * */ class WhydBridge extends BridgeAbstract{ @@ -21,12 +21,16 @@ class WhydBridge extends BridgeAbstract{ if (isset($param['u'])) { $this->request = $param['u']; - $html = file_get_html('http://www.whyd.com/u/'.urlencode($this->request)) or $this->returnError('No results for this query.', 404); + if (strlen(preg_replace("/[^0-9a-f]/",'', $this->request)) == 24) // is input the userid ? + $html = file_get_html('http://www.whyd.com/u/'.preg_replace("/[^0-9a-f]/",'', $this->request)) or $this->returnError('No results for this query.', 404); + else // input may be the username + $html = file_get_html('http://www.whyd.com/'.urlencode($this->request)) or $this->returnError('No results for this query.', 404); + $this->name = $html->find('div#profileTop', 0)->find('h1', 0)->plaintext; } else { - $this->returnError('You must specify username', 400); + $this->returnError('You must specify username or id', 400); } for($i = 0; $i < 10; $i++) {