9 * This source file is subject to the new BSD license that is bundled
10 * with this package in the file LICENSE.
11 * It is also available through the world-wide-web at this URL:
12 * http://phergie.org/license
15 * @package Phergie_Plugin_Php
16 * @author Phergie Development Team <team@phergie.org>
17 * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
18 * @license http://phergie.org/license New BSD License
19 * @link http://pear.phergie.org/package/Phergie_Plugin_Php
23 * Shortens urls via the tr.im service
26 * @package Phergie_Plugin_Url
27 * @author Phergie Development Team <team@phergie.org>
28 * @license http://phergie.org/license New BSD License
29 * @link http://pear.phergie.org/package/Phergie_Plugin_Url
31 class Phergie_Plugin_Url_Shorten_Trim extends Phergie_Plugin_Url_Shorten_Abstract
34 * Returns an array of request parameters given a url to shorten. The
35 * following keys are valid request parameters:
37 * @param string $url the url to shorten
39 * @return array the request parameters
41 protected function getRequestParams($url)
44 'uri' => 'http://api.tr.im/v1/trim_simple?url=' . rawurlencode($url),
45 'callback' => array($this, 'onComplete')
50 * Callback for when the URL has been shortened. Checks for error messages.
52 * @param Phergie_Plugin_Http_Response $response the response object
54 * @return string|bool the shortened url or false on failure
56 protected function onComplete($response)
58 if (strpos($response->getContent(), 'Error: ') === 0) {
62 return $response->getContent();