Last active
August 29, 2015 14:02
-
-
Save dgomesbr/7839d8668e223d7970f8 to your computer and use it in GitHub Desktop.
Patch for domain defined in user properties.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(!$user = $this->db->get("user",array("api"=>"?"),array("limit"=>1),array($key))) return $this->api_build(array("error"=>1,"msg"=>"A valid API key is required to use this service.")); | |
$this->userid = $user->id; | |
$this->customDomain = $user->domain; | |
// Check Request type | |
if(!isset($_GET["url"]) && !isset($_GET["short"])) return $this->api_build(array("error"=>1,"msg"=>"Please enter a valid URL.")); | |
// Check if shorten request is made | |
if(isset($_GET["url"])){ | |
$array = array(); | |
$array["url"] = Main::clean($_GET["url"],3,TRUE); | |
$array["domain"] = $this->customDomain; | |
if(isset($_GET["custom"]) && !empty($_GET["custom"])) $array["custom"] = Main::slug($_GET["custom"]); | |
$result = $this->add($array,TRUE); | |
return $this->api_build($result,isset($result["short"])?$result["short"]:""); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* API | |
* @since 4.0 | |
**/ | |
private function api(){ | |
// Validate request | |
if(!$this->config["api"]) return $this->api_build(array("error"=>1,"msg"=>"API service is disabled.")); | |
// Check API Key | |
if(!isset($_GET["key"]) && !isset($_GET["api"])) return $this->api_build(array("error"=>1,"msg"=>"A valid API key is required to use this service.")); | |
$key = isset($_GET["key"]) ? $_GET["key"] : $_GET["api"]; | |
// Get user | |
if(!$user = $this->db->get("user",array("api"=>"?"),array("limit"=>1),array($key))) return $this->api_build(array("error"=>1,"msg"=>"A valid API key is required to use this service.")); | |
$this->userid = $user->id; | |
$this->customDomain = $user->domain; | |
$this->config["captcha"]=0; | |
// Check Request type | |
if(!isset($_GET["url"]) && !isset($_GET["short"])) return $this->api_build(array("error"=>1,"msg"=>"Please enter a valid URL.")); | |
// Check if shorten request is made | |
if(isset($_GET["url"])){ | |
$array = array(); | |
$array["url"] = Main::clean($_GET["url"],3,TRUE); | |
$array["domain"] = $this->customDomain; | |
if(isset($_GET["custom"]) && !empty($_GET["custom"])) $array["custom"] = Main::slug($_GET["custom"]); | |
$result = $this->add($array,TRUE); | |
return $this->api_build($result,isset($result["short"])?$result["short"]:""); | |
} | |
// Check if retrieval request is made | |
if(isset($_GET["short"])){ | |
$g = parse_url($_GET["short"]); | |
$g = explode("/",$g["path"]); | |
$g = array_reverse($g); | |
if(!$url = $this->db->get("url","alias=:q OR custom=:q",array("limit"=>1),array(":q"=>$g[0]))) return $this->api_build(array("error"=>1,"msg"=>"This URL couldn't be found. Please double check it.")); | |
if((!empty($url->pass) || !$url->public) && $url->userid !== $user->id) return $this->api_build(array("error"=>1,"msg"=>"This URL is private or password-protected.")); | |
$array = array( | |
"error" => 0, | |
"long" => $url->url, | |
"click" => $url->click, | |
"date" => $url->date, | |
"location" => json_decode($url->location,TRUE) | |
); | |
return $this->api_build($array,$url->url); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lines 3 and 12 added for customDomain registed for the user using API.