Skip to content

Instantly share code, notes, and snippets.

@dgomesbr
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgomesbr/7839d8668e223d7970f8 to your computer and use it in GitHub Desktop.
Save dgomesbr/7839d8668e223d7970f8 to your computer and use it in GitHub Desktop.
Patch for domain defined in user properties.
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"]:"");
}
/**
* 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;
}
@dgomesbr
Copy link
Author

dgomesbr commented Jun 6, 2014

lines 3 and 12 added for customDomain registed for the user using API.

@kbrmedia
Copy link

kbrmedia commented Jun 6, 2014

Thanks 👍

@dgomesbr
Copy link
Author

dgomesbr commented Jun 9, 2014

@kbrmedia added patch for latest version as well, on lines 16 and 25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment