public function uploadImage($image)
 {
     if (!is_null($image)) {
         $result = $this->uploader->uploadFile($image);
         $longUrl = $result['url'];
         //initialize bitly
         $this->initBitly();
         //shorten url
         $this->shortUrl = $this->shortener->shortenUrl($longUrl);
     }
 }
Example #2
0
        }
    }
    protected function users()
    {
        if ($this->method == 'POST') {
            if ($this->verb == 'urls') {
                $this->urlClass->setUser($this->id);
                if (property_exists($this->postContent, 'url')) {
                    $this->urlClass->setUrl($this->postContent->url);
                    return $this->urlClass->insert_url();
                } else {
                    return array('status' => 500, 'result' => 'The POST data is out of the API standards');
                }
            } else {
                return array('status' => 404, 'result' => 'Not Found');
            }
        } else {
            return array('status' => 200, 'result' => 'Only accepts POST requests');
        }
    }
}
// Requests from the same server don't have a HTTP_ORIGIN header
if (!array_key_exists('HTTP_ORIGIN', $_SERVER)) {
    $_SERVER['HTTP_ORIGIN'] = $_SERVER['SERVER_NAME'];
}
try {
    $API = new UrlShortener($_REQUEST['request'], $_SERVER['HTTP_ORIGIN']);
    echo $API->processAPI();
} catch (Exception $e) {
    echo json_encode(array('error' => $e->getMessage()));
}
Example #3
0
 /**
  * Shorten the file url
  * @param  string $longUrl 
  * @return string          the shortened url
  */
 public function shortenUrl($longUrl)
 {
     return $this->shortener->shortenUrl($longUrl);
 }
 function get_urlshortener()
 {
     $urlshortener = new UrlShortener();
     $bitlylogin = $this->get_config('announce_bitly_login');
     $bitlyapikey = $this->get_config('announce_bitly_apikey');
     $yourlsurl = $this->get_config('announce_yourls_url');
     $yourlsapikey = $this->get_config('announce_yourls_apikey');
     $piratlyapikey = $this->get_config('announce_piratly_apikey', '0');
     $this->log("blogin:"******" bapi: " . $bitlyapikey);
     $urlshortener->setBitlyLogin($bitlylogin, $bitlyapikey);
     $this->log("slogin:"******" sapi: " . $urlshortener->bitly_apikey);
     $urlshortener->setPiratlyToken($piratlyapikey);
     $urlshortener->setYourlsLogin($yourlsurl, $yourlsapikey);
     return $urlshortener;
 }
Example #5
0
 /**
  *  @test
  */
 public function it_returns_new_instance_on_driver_hot_swap()
 {
     $this->assertInstanceOf(UrlShortener::class, \UrlShortener::driver('google'));
 }
 function shorten_via_jmp($url, &$shorturls)
 {
     // if we already evaluated the shorturl, stop here
     if (!empty($shorturls['jmp'])) {
         return;
     }
     $short_url = trim(UrlShortener::_make_bitly_api_url($url, 'xml', 'j.mp'));
     if (!empty($short_url)) {
         $shorturls['jmp'] = $short_url;
     }
 }