X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FIrc%2Fextlib%2Fphergie%2FPhergie%2FPlugin%2FUrl%2FShorten%2FAbstract.php;fp=plugins%2FIrc%2Fextlib%2Fphergie%2FPhergie%2FPlugin%2FUrl%2FShorten%2FAbstract.php;h=0000000000000000000000000000000000000000;hb=c6f89b21748948fde902904f6ac9ce9afa026b84;hp=607d1654c4157bc9e48ff6b328c015d8f450b21b;hpb=597a3c89edd7200ab069f0e43c4f63406ca3d7f9;p=quix0rs-gnu-social.git diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Url/Shorten/Abstract.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Url/Shorten/Abstract.php deleted file mode 100644 index 607d1654c4..0000000000 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/Url/Shorten/Abstract.php +++ /dev/null @@ -1,105 +0,0 @@ - - * @copyright 2008-2010 Phergie Development Team (http://phergie.org) - * @license http://phergie.org/license New BSD License - * @link http://pear.phergie.org/package/Phergie_Plugin_Php - */ - -/** - * URL shortener abstract class - * - * @category Phergie - * @package Phergie_Plugin_Url - * @author Phergie Development Team - * @license http://phergie.org/license New BSD License - * @link http://pear.phergie.org/package/Phergie_Plugin_Url - * @uses Phergie_Plugin_Http pear.phergie.org - */ -abstract class Phergie_Plugin_Url_Shorten_Abstract -{ - protected $http; - - /** - * Constructor - * - * @param Phergie_Plugin_Http $http instance of the http plugin - */ - public function __construct(Phergie_Plugin_Http $http) - { - $this->http = $http; - } - - /** - * Returns an array of request parameters given a url to shorten. The - * following keys are valid request parameters: - * - * * 'uri': the URI for the request (required) - * * 'query': an array of key-value pairs sent in a GET request - * * 'post': an array of key-value pairs sent in a POST request - * * 'callback': to be called after the request is finished. Should accept - * a Phergie_Plugin_Http_Response object and return either the shortened - * url or false if an error has occured. - * - * If the 'post' key is present a POST request shall be made; otherwise - * a GET request will be made. The 'post' key can be an empty array and - * a post request will still be made. - * - * If no callback is provided the contents of the response will be returned. - * - * @param string $url the url to shorten - * - * @return array the request parameters - */ - protected abstract function getRequestParams($url); - - /** - * Shortens a given url. - * - * @param string $url the url to shorten - * - * @return string the shortened url or false on a failure - */ - public function shorten($url) - { - $defaults = array('get' => array(), 'post' => array(), 'callback' => null); - $options = array('timeout' => 2); - $params = $this->getRequestParams($url) + $defaults; - - // Should some kind of notice be thrown? Maybe just if getRequestParams does not return an array? - if (!is_array($params) || empty($params['uri'])) { - return $url; - } - - if (!empty($params['post'])) { - $response = $this->http->post($params['uri'], $params['get'], $params['post'], $options); - } else { - $response = $this->http->get($params['uri'], $params['get'], $options); - } - - if (is_callable($params['callback'])) { - return call_user_func($params['callback'], $response); - } - - $code = $response->getCode(); - $content = trim($response->getContent); - if ($code < 200 || $code >= 300 || empty($content)) { - return false; - } - - return $response->getContent(); - } -}