Version 3.3.4
This commit is contained in:
1 parent
78706903a2
commit
fb6b5baabc
2206 files changed
+409828
-382984
No files matched your search
@@ -1,72 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.2.3
|
||||
* URL shortener
|
||||
* Owner: Matt Mecham
|
||||
* Last Updated: $Date: 2011-05-05 07:03:47 -0400 (Thu, 05 May 2011) $
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Mecham
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license This is NULLED!
|
||||
* @package IP.Board
|
||||
* @link http://hatynka.in
|
||||
* @since 24th November 2009
|
||||
* @version $Revision: 8644 $
|
||||
*/
|
||||
|
||||
|
||||
/* Class name must match shortener directory name */
|
||||
class bitly extends urlShorten
|
||||
{
|
||||
protected $_config = array();
|
||||
|
||||
protected $_cfm;
|
||||
|
||||
/**
|
||||
* Method constructor
|
||||
*
|
||||
* If you pass false as the key, it will not save out the imported GUIDs
|
||||
* @access public
|
||||
* @return @e void
|
||||
*
|
||||
*/
|
||||
public function __construct( $config=array() )
|
||||
{
|
||||
$this->_config = $config;
|
||||
|
||||
$classToLoad = IPSLib::loadLibrary( IPS_KERNEL_PATH . 'classFileManagement.php', 'classFileManagement' );
|
||||
$this->_cfm = new $classToLoad();
|
||||
$this->_cfm->timeout = 30;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten URL
|
||||
*
|
||||
* @access public
|
||||
* @param string URL to shorten
|
||||
* @return array ( 'status' => [ok/failed], 'url' => [shortened url], 'method' => [api used], 'raw' => [any raw data] )
|
||||
* Exception codes:
|
||||
*/
|
||||
public function apiShorten( $url )
|
||||
{
|
||||
/* Query the service */
|
||||
$response = $this->_cfm->getFileContents( "http://api.bit.ly/shorten?version=2.0.1&longUrl=" . urlencode( $url ) . "&login={$this->_config['login']}&apiKey={$this->_config['apiKey']}" );
|
||||
|
||||
if ( ! $response )
|
||||
{
|
||||
return array( 'status' => 'failed' );
|
||||
}
|
||||
|
||||
$obj = json_decode( $response, TRUE );
|
||||
|
||||
return array( 'status' => 'ok',
|
||||
'url' => $obj['results'][$url]['shortUrl'],
|
||||
'method' => 'bitly',
|
||||
'raw' => $obj['results'] );
|
||||
}
|
||||
|
||||
<?php
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.3.4
|
||||
* URL shortener
|
||||
* Owner: Matt Mecham
|
||||
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Mecham
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/company/standards.php#license
|
||||
* @package IP.Board
|
||||
* @link http://www.invisionpower.com
|
||||
* @since 24th November 2009
|
||||
* @version $Revision: 10914 $
|
||||
*/
|
||||
|
||||
|
||||
/* Class name must match shortener directory name */
|
||||
class bitly extends urlShorten
|
||||
{
|
||||
protected $_config = array();
|
||||
|
||||
protected $_cfm;
|
||||
|
||||
/**
|
||||
* Method constructor
|
||||
*
|
||||
* If you pass false as the key, it will not save out the imported GUIDs
|
||||
* @access public
|
||||
* @return @e void
|
||||
*
|
||||
*/
|
||||
public function __construct( $config=array() )
|
||||
{
|
||||
$this->_config = $config;
|
||||
|
||||
$classToLoad = IPSLib::loadLibrary( IPS_KERNEL_PATH . 'classFileManagement.php', 'classFileManagement' );
|
||||
$this->_cfm = new $classToLoad();
|
||||
$this->_cfm->timeout = 30;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten URL
|
||||
*
|
||||
* @access public
|
||||
* @param string URL to shorten
|
||||
* @return array ( 'status' => [ok/failed], 'url' => [shortened url], 'method' => [api used], 'raw' => [any raw data] )
|
||||
* Exception codes:
|
||||
*/
|
||||
public function apiShorten( $url )
|
||||
{
|
||||
/* Query the service */
|
||||
$response = $this->_cfm->getFileContents( "http://api.bit.ly/shorten?version=2.0.1&longUrl=" . urlencode( $url ) . "&login={$this->_config['login']}&apiKey={$this->_config['apiKey']}" );
|
||||
|
||||
if ( ! $response )
|
||||
{
|
||||
return array( 'status' => 'failed' );
|
||||
}
|
||||
|
||||
$obj = json_decode( $response, TRUE );
|
||||
|
||||
return array( 'status' => 'ok',
|
||||
'url' => $obj['results'][$url]['shortUrl'],
|
||||
'method' => 'bitly',
|
||||
'raw' => $obj['results'] );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,19 +3,19 @@
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.2.3
|
||||
* IP.Board v3.3.4
|
||||
* URL shortener
|
||||
* Owner: Matt Mecham
|
||||
* Last Updated: $Date: 2010-12-17 08:01:38 -0500 (Fri, 17 Dec 2010) $
|
||||
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Mecham
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license This is NULLED!
|
||||
* @license http://www.invisionpower.com/company/standards.php#license
|
||||
* @package IP.Board
|
||||
* @link http://hatynka.in
|
||||
* @link http://www.invisionpower.com
|
||||
* @since 24th November 2009
|
||||
* @version $Revision: 7445 $
|
||||
* @version $Revision: 10914 $
|
||||
*/
|
||||
|
||||
$config = array();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<html>
|
||||
<head><title>IP.Board - Bulletin Board System</title></head>
|
||||
<body>
|
||||
<h1>403: IP.Board -> Forbidden</h1>
|
||||
<hr>
|
||||
You have reached this page in error, please use your back button to return to the forum.
|
||||
<hr>
|
||||
<a href="http://www.invisionpower.com">IP.Board</a>
|
||||
</body>
|
||||
<html>
|
||||
<head><title>IP.Board - Bulletin Board System</title></head>
|
||||
<body>
|
||||
<h1>403: IP.Board -> Forbidden</h1>
|
||||
<hr>
|
||||
You have reached this page in error, please use your back button to return to the forum.
|
||||
<hr>
|
||||
<a href="http://www.invisionpower.com">IP.Board</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,10 +1,10 @@
|
||||
<html>
|
||||
<head><title>IP.Board - Bulletin Board System</title></head>
|
||||
<body>
|
||||
<h1>403: IP.Board -> Forbidden</h1>
|
||||
<hr>
|
||||
You have reached this page in error, please use your back button to return to the forum.
|
||||
<hr>
|
||||
<a href="http://www.invisionpower.com">IP.Board</a>
|
||||
</body>
|
||||
<html>
|
||||
<head><title>IP.Board - Bulletin Board System</title></head>
|
||||
<body>
|
||||
<h1>403: IP.Board -> Forbidden</h1>
|
||||
<hr>
|
||||
You have reached this page in error, please use your back button to return to the forum.
|
||||
<hr>
|
||||
<a href="http://www.invisionpower.com">IP.Board</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,74 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.2.3
|
||||
* URL shortener
|
||||
* Owner: Matt Mecham
|
||||
* Last Updated: $Date: 2011-05-05 07:03:47 -0400 (Thu, 05 May 2011) $
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Mecham
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license This is NULLED!
|
||||
* @package IP.Board
|
||||
* @link http://hatynka.in
|
||||
* @since 24th November 2009
|
||||
* @version $Revision: 8644 $
|
||||
*/
|
||||
|
||||
|
||||
/* Class name must match shortener directory name */
|
||||
class topic extends urlShorten
|
||||
{
|
||||
protected $_config = array();
|
||||
|
||||
protected $_cfm;
|
||||
|
||||
/**
|
||||
* Method constructor
|
||||
*
|
||||
* If you pass false as the key, it will not save out the imported GUIDs
|
||||
*
|
||||
* @return @e void
|
||||
*
|
||||
*/
|
||||
public function __construct( $config=array() )
|
||||
{
|
||||
$this->_config = $config;
|
||||
|
||||
$classToLoad = IPSLib::loadLibrary( IPS_KERNEL_PATH . 'classFileManagement.php', 'classFileManagement' );
|
||||
$this->_cfm = new $classToLoad();
|
||||
$this->_cfm->timeout = 30;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten URL
|
||||
*
|
||||
* @param string URL to shorten
|
||||
* @return array ( 'status' => [ok/failed], 'url' => [shortened url], 'method' => [api used], 'raw' => [any raw data] )
|
||||
*/
|
||||
public function apiShorten( $url )
|
||||
{
|
||||
/* Query the service */
|
||||
$response = $this->_cfm->getFileContents( "http://topic.to/api.php?action=shorturl&url=" . urlencode( $url ) . "&format=json" );
|
||||
|
||||
if ( ! $response )
|
||||
{
|
||||
return array( 'status' => 'failed' );
|
||||
}
|
||||
|
||||
$obj = json_decode( $response, TRUE );
|
||||
|
||||
if ( $obj['statusCode'] != 200 )
|
||||
{
|
||||
return array( 'status' => 'failed' );
|
||||
}
|
||||
|
||||
return array( 'status' => 'ok',
|
||||
'url' => $obj['shorturl'],
|
||||
'method' => 'topic',
|
||||
'raw' => $obj['url'] );
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.3.4
|
||||
* URL shortener
|
||||
* Owner: Matt Mecham
|
||||
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Mecham
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/company/standards.php#license
|
||||
* @package IP.Board
|
||||
* @link http://www.invisionpower.com
|
||||
* @since 24th November 2009
|
||||
* @version $Revision: 10914 $
|
||||
*/
|
||||
|
||||
|
||||
/* Class name must match shortener directory name */
|
||||
class topic extends urlShorten
|
||||
{
|
||||
protected $_config = array();
|
||||
|
||||
protected $_cfm;
|
||||
|
||||
/**
|
||||
* Method constructor
|
||||
*
|
||||
* If you pass false as the key, it will not save out the imported GUIDs
|
||||
*
|
||||
* @return @e void
|
||||
*
|
||||
*/
|
||||
public function __construct( $config=array() )
|
||||
{
|
||||
$this->_config = $config;
|
||||
|
||||
$classToLoad = IPSLib::loadLibrary( IPS_KERNEL_PATH . 'classFileManagement.php', 'classFileManagement' );
|
||||
$this->_cfm = new $classToLoad();
|
||||
$this->_cfm->timeout = 30;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten URL
|
||||
*
|
||||
* @param string URL to shorten
|
||||
* @return array ( 'status' => [ok/failed], 'url' => [shortened url], 'method' => [api used], 'raw' => [any raw data] )
|
||||
*/
|
||||
public function apiShorten( $url )
|
||||
{
|
||||
/* Query the service */
|
||||
$response = $this->_cfm->getFileContents( "http://topic.to/api.php?action=shorturl&url=" . urlencode( $url ) . "&format=json" );
|
||||
|
||||
if ( ! $response )
|
||||
{
|
||||
return array( 'status' => 'failed' );
|
||||
}
|
||||
|
||||
$obj = json_decode( $response, TRUE );
|
||||
|
||||
if ( $obj['statusCode'] != 200 )
|
||||
{
|
||||
return array( 'status' => 'failed' );
|
||||
}
|
||||
|
||||
return array( 'status' => 'ok',
|
||||
'url' => $obj['shorturl'],
|
||||
'method' => 'topic',
|
||||
'raw' => $obj['url'] );
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,19 @@
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.2.3
|
||||
* IP.Board v3.3.4
|
||||
* URL shortener
|
||||
* Owner: Matt Mecham
|
||||
* Last Updated: $Date: 2010-12-17 08:01:38 -0500 (Fri, 17 Dec 2010) $
|
||||
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Mecham
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license This is NULLED!
|
||||
* @license http://www.invisionpower.com/company/standards.php#license
|
||||
* @package IP.Board
|
||||
* @link http://hatynka.in
|
||||
* @link http://www.invisionpower.com
|
||||
* @since 24th November 2009
|
||||
* @version $Revision: 7445 $
|
||||
* @version $Revision: 10914 $
|
||||
*/
|
||||
|
||||
$config = array();
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<html>
|
||||
<head><title>IP.Board - Bulletin Board System</title></head>
|
||||
<body>
|
||||
<h1>403: IP.Board -> Forbidden</h1>
|
||||
<hr>
|
||||
You have reached this page in error, please use your back button to return to the forum.
|
||||
<hr>
|
||||
<a href="http://www.invisionpower.com">IP.Board</a>
|
||||
</body>
|
||||
<html>
|
||||
<head><title>IP.Board - Bulletin Board System</title></head>
|
||||
<body>
|
||||
<h1>403: IP.Board -> Forbidden</h1>
|
||||
<hr>
|
||||
You have reached this page in error, please use your back button to return to the forum.
|
||||
<hr>
|
||||
<a href="http://www.invisionpower.com">IP.Board</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,10 +1,10 @@
|
||||
<html>
|
||||
<head><title>IP.Board - Bulletin Board System</title></head>
|
||||
<body>
|
||||
<h1>403: IP.Board -> Forbidden</h1>
|
||||
<hr>
|
||||
You have reached this page in error, please use your back button to return to the forum.
|
||||
<hr>
|
||||
<a href="http://www.invisionpower.com">IP.Board</a>
|
||||
</body>
|
||||
<html>
|
||||
<head><title>IP.Board - Bulletin Board System</title></head>
|
||||
<body>
|
||||
<h1>403: IP.Board -> Forbidden</h1>
|
||||
<hr>
|
||||
You have reached this page in error, please use your back button to return to the forum.
|
||||
<hr>
|
||||
<a href="http://www.invisionpower.com">IP.Board</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,183 +1,183 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.2.3
|
||||
* URL Shortener
|
||||
* Owner: Matt Mecham
|
||||
* Last Updated: $Date: 2011-03-11 12:41:48 -0500 (Fri, 11 Mar 2011) $
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Mecham
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license This is NULLED!
|
||||
* @package IP.Board
|
||||
* @link http://hatynka.in
|
||||
* @since 24th November 2009
|
||||
* @version $Revision: 8042 $
|
||||
*/
|
||||
|
||||
/*
|
||||
# Example: Shorten URL
|
||||
# require_once( IPS_ROOT_PATH . 'sources/classes/url/shorten.php' );/*noLibHook*/
|
||||
# $shorten = new urlShorten();
|
||||
# $data = $shorten->shorten( 'http://www.invisionpower.com', 'bitly' );
|
||||
#
|
||||
# print $data['url'];
|
||||
#
|
||||
# Example: List available shorteners
|
||||
# require_once( IPS_ROOT_PATH . 'sources/classes/url/shorten.php' );/*noLibHook*/
|
||||
# $shorten = new urlShorten();
|
||||
#
|
||||
# print_r( $shorten->fetchAvailableApis() );
|
||||
#
|
||||
|
||||
class urlShorten
|
||||
{
|
||||
/**
|
||||
* Main API classes directory
|
||||
*
|
||||
* @var $_mainDir
|
||||
*/
|
||||
protected $_mainDir;
|
||||
|
||||
/**
|
||||
* API object
|
||||
*
|
||||
* @var $_api
|
||||
*/
|
||||
protected $_api;
|
||||
|
||||
/**
|
||||
* Array of additional error messages
|
||||
*
|
||||
* @var $errors
|
||||
*/
|
||||
public $errors = array();
|
||||
|
||||
/**
|
||||
* Method constructor
|
||||
*
|
||||
* @return @e void
|
||||
*
|
||||
* @throws Exception
|
||||
* @li NO_METHOD (API class could not be found)
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_mainDir = IPS_ROOT_PATH . 'sources/classes/url/apis';
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten URL
|
||||
*
|
||||
* @param string $url URL to shorten
|
||||
* @param string $apiKey Method key to use (If left blank, we'll just grab the first one)
|
||||
* @return @e array Shortened url data
|
||||
*
|
||||
* @throws Exception
|
||||
* @li NO_METHOD (API class could not be found)
|
||||
* @li BAD_FORMAT (URL is not in the correct format)
|
||||
* @li FAILED (URL shorten failed)
|
||||
*/
|
||||
public function shorten( $url, $apiKey )
|
||||
{
|
||||
/* Check URL */
|
||||
if ( ! strstr( $url, 'http://' ) AND ! strstr( $url, 'https://' ) )
|
||||
{
|
||||
throw new Exception( 'BAD_FORMAT' );
|
||||
}
|
||||
|
||||
if ( $apiKey )
|
||||
{
|
||||
$_thisDir = $this->_mainDir . '/' . $apiKey;
|
||||
|
||||
if ( @is_file( $_thisDir . '/api.php' ) )
|
||||
{
|
||||
$this->_setMethod( $apiKey );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We don't care */
|
||||
$apis = $this->fetchAvailableApis();
|
||||
|
||||
if ( is_array( $apis ) AND count( $apis ) )
|
||||
{
|
||||
$apiKey = array_shift( $apis );
|
||||
|
||||
if ( $apiKey )
|
||||
{
|
||||
$this->_setMethod( $apiKey );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! is_object( $this->_api ) )
|
||||
{
|
||||
throw new Exception( 'NO_METHOD' );
|
||||
}
|
||||
|
||||
/* still here? */
|
||||
$data = $this->_api->apiShorten( $url );
|
||||
|
||||
if ( $data['status'] == 'ok' )
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* could do something more useful here */
|
||||
throw new Exception( 'FAILED' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set method
|
||||
* Assumes that the folder and files exist
|
||||
*
|
||||
* @param string $apiKey API key
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _setMethod( $apiKey )
|
||||
{
|
||||
$config = array();
|
||||
|
||||
if ( is_file( $this->_mainDir . '/' . $apiKey . '/conf.php' ) )
|
||||
{
|
||||
require( $this->_mainDir . '/' . $apiKey . '/conf.php' );/*noLibHook*/
|
||||
}
|
||||
|
||||
$classToLoad = IPSLib::loadLibrary( $this->_mainDir . '/' . $apiKey . '/api.php', $apiKey );
|
||||
$this->_api = new $classToLoad( $config );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all available APIs
|
||||
*
|
||||
* @return @e array Available APIs
|
||||
*/
|
||||
public function fetchAvailableApis()
|
||||
{
|
||||
$apis = array();
|
||||
|
||||
try
|
||||
{
|
||||
foreach( new DirectoryIterator( $this->_mainDir ) as $file )
|
||||
{
|
||||
if ( ! $file->isDot() AND $file->isDir() )
|
||||
{
|
||||
$_name = $file->getFileName();
|
||||
|
||||
if ( substr( $_name, 0, 1 ) != '.' )
|
||||
{
|
||||
$apis[] = $_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( Exception $e ) {}
|
||||
|
||||
return $apis;
|
||||
}
|
||||
<?php
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* Invision Power Services
|
||||
* IP.Board v3.3.4
|
||||
* URL Shortener
|
||||
* Owner: Matt Mecham
|
||||
* Last Updated: $Date: 2012-06-12 10:14:49 -0400 (Tue, 12 Jun 2012) $
|
||||
* </pre>
|
||||
*
|
||||
* @author Matt Mecham
|
||||
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/company/standards.php#license
|
||||
* @package IP.Board
|
||||
* @link http://www.invisionpower.com
|
||||
* @since 24th November 2009
|
||||
* @version $Revision: 10914 $
|
||||
*/
|
||||
|
||||
/*
|
||||
# Example: Shorten URL
|
||||
# require_once( IPS_ROOT_PATH . 'sources/classes/url/shorten.php' );/*noLibHook*/
|
||||
# $shorten = new urlShorten();
|
||||
# $data = $shorten->shorten( 'http://www.invisionpower.com', 'bitly' );
|
||||
#
|
||||
# print $data['url'];
|
||||
#
|
||||
# Example: List available shorteners
|
||||
# require_once( IPS_ROOT_PATH . 'sources/classes/url/shorten.php' );/*noLibHook*/
|
||||
# $shorten = new urlShorten();
|
||||
#
|
||||
# print_r( $shorten->fetchAvailableApis() );
|
||||
#
|
||||
|
||||
class urlShorten
|
||||
{
|
||||
/**
|
||||
* Main API classes directory
|
||||
*
|
||||
* @var $_mainDir
|
||||
*/
|
||||
protected $_mainDir;
|
||||
|
||||
/**
|
||||
* API object
|
||||
*
|
||||
* @var $_api
|
||||
*/
|
||||
protected $_api;
|
||||
|
||||
/**
|
||||
* Array of additional error messages
|
||||
*
|
||||
* @var $errors
|
||||
*/
|
||||
public $errors = array();
|
||||
|
||||
/**
|
||||
* Method constructor
|
||||
*
|
||||
* @return @e void
|
||||
*
|
||||
* @throws Exception
|
||||
* @li NO_METHOD (API class could not be found)
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_mainDir = IPS_ROOT_PATH . 'sources/classes/url/apis';
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten URL
|
||||
*
|
||||
* @param string $url URL to shorten
|
||||
* @param string $apiKey Method key to use (If left blank, we'll just grab the first one)
|
||||
* @return @e array Shortened url data
|
||||
*
|
||||
* @throws Exception
|
||||
* @li NO_METHOD (API class could not be found)
|
||||
* @li BAD_FORMAT (URL is not in the correct format)
|
||||
* @li FAILED (URL shorten failed)
|
||||
*/
|
||||
public function shorten( $url, $apiKey )
|
||||
{
|
||||
/* Check URL */
|
||||
if ( ! strstr( $url, 'http://' ) AND ! strstr( $url, 'https://' ) )
|
||||
{
|
||||
throw new Exception( 'BAD_FORMAT' );
|
||||
}
|
||||
|
||||
if ( $apiKey )
|
||||
{
|
||||
$_thisDir = $this->_mainDir . '/' . $apiKey;
|
||||
|
||||
if ( @is_file( $_thisDir . '/api.php' ) )
|
||||
{
|
||||
$this->_setMethod( $apiKey );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* We don't care */
|
||||
$apis = $this->fetchAvailableApis();
|
||||
|
||||
if ( is_array( $apis ) AND count( $apis ) )
|
||||
{
|
||||
$apiKey = array_shift( $apis );
|
||||
|
||||
if ( $apiKey )
|
||||
{
|
||||
$this->_setMethod( $apiKey );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! is_object( $this->_api ) )
|
||||
{
|
||||
throw new Exception( 'NO_METHOD' );
|
||||
}
|
||||
|
||||
/* still here? */
|
||||
$data = $this->_api->apiShorten( $url );
|
||||
|
||||
if ( $data['status'] == 'ok' )
|
||||
{
|
||||
return $data;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* could do something more useful here */
|
||||
throw new Exception( 'FAILED' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set method
|
||||
* Assumes that the folder and files exist
|
||||
*
|
||||
* @param string $apiKey API key
|
||||
* @return @e void
|
||||
*/
|
||||
protected function _setMethod( $apiKey )
|
||||
{
|
||||
$config = array();
|
||||
|
||||
if ( is_file( $this->_mainDir . '/' . $apiKey . '/conf.php' ) )
|
||||
{
|
||||
require( $this->_mainDir . '/' . $apiKey . '/conf.php' );/*noLibHook*/
|
||||
}
|
||||
|
||||
$classToLoad = IPSLib::loadLibrary( $this->_mainDir . '/' . $apiKey . '/api.php', $apiKey );
|
||||
$this->_api = new $classToLoad( $config );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all available APIs
|
||||
*
|
||||
* @return @e array Available APIs
|
||||
*/
|
||||
public function fetchAvailableApis()
|
||||
{
|
||||
$apis = array();
|
||||
|
||||
try
|
||||
{
|
||||
foreach( new DirectoryIterator( $this->_mainDir ) as $file )
|
||||
{
|
||||
if ( ! $file->isDot() AND $file->isDir() )
|
||||
{
|
||||
$_name = $file->getFileName();
|
||||
|
||||
if ( substr( $_name, 0, 1 ) != '.' )
|
||||
{
|
||||
$apis[] = $_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( Exception $e ) {}
|
||||
|
||||
return $apis;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user