Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -12,16 +12,27 @@
|
||||
namespace IPS\convert\api;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DirectoryIterator;
|
||||
use IPS\Api\Controller;
|
||||
use IPS\Api\Response;
|
||||
use IPS\Lang;
|
||||
use IPS\Request;
|
||||
use ReflectionMethod;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Converters API
|
||||
*/
|
||||
class _converters extends \IPS\Api\Controller
|
||||
class converters extends Controller
|
||||
{
|
||||
/**
|
||||
* GET /convert/converters
|
||||
@@ -31,13 +42,13 @@ class _converters extends \IPS\Api\Controller
|
||||
* @apiparam string applications Comma-delimited list of applications to filter by
|
||||
* @return array
|
||||
*/
|
||||
public function GETindex()
|
||||
public function GETindex(): Response
|
||||
{
|
||||
$response = array();
|
||||
$applications = \IPS\Request::i()->applications ? explode( ',', \IPS\Request::i()->applications ) : array();
|
||||
$applications = Request::i()->applications ? explode( ',', Request::i()->applications ) : array();
|
||||
|
||||
/* Loop over software directory to figure out software we can convert */
|
||||
foreach( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/convert/sources/Software/' ) as $directory )
|
||||
foreach( new DirectoryIterator( \IPS\ROOT_PATH . '/applications/convert/sources/Software/' ) as $directory )
|
||||
{
|
||||
/* Skip ../ and any non-directories */
|
||||
if( $directory->isDot() OR !$directory->isDir() )
|
||||
@@ -46,13 +57,13 @@ class _converters extends \IPS\Api\Controller
|
||||
}
|
||||
|
||||
/* Are we filtering by supported applications? */
|
||||
if( \count( $applications ) AND !\in_array( mb_convert_case( $directory->getFilename(), MB_CASE_TITLE ) ) )
|
||||
if( count( $applications ) AND !in_array( mb_convert_case( $directory->getFilename(), MB_CASE_TITLE ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Loop over all of the software in this directory */
|
||||
foreach( new \DirectoryIterator( $directory->getPathname() ) as $softwares )
|
||||
foreach( new DirectoryIterator( $directory->getPathname() ) as $softwares )
|
||||
{
|
||||
/* Skip ../ and any non-files */
|
||||
if( $softwares->isDot() OR !$softwares->isFile() OR mb_substr( $softwares->getFilename(), -3 ) !== 'php' )
|
||||
@@ -101,12 +112,12 @@ class _converters extends \IPS\Api\Controller
|
||||
foreach( $rawConvert as $convertType )
|
||||
{
|
||||
/* Skip extra steps */
|
||||
if( \in_array( $convertType, $extraSteps ) )
|
||||
if( in_array( $convertType, $extraSteps ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$canConvert[] = \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->addToStack(
|
||||
$canConvert[] = Lang::load( Lang::defaultLanguage() )->addToStack(
|
||||
preg_replace_callback( "/([A-Z])/", function( $match ){
|
||||
return "_" . mb_strtolower( $match[1] );
|
||||
}, $convertType )
|
||||
@@ -114,7 +125,7 @@ class _converters extends \IPS\Api\Controller
|
||||
}
|
||||
|
||||
/* Reflect the class to figure out if redirects are enabled */
|
||||
$reflect = new \ReflectionMethod( $classname, 'checkRedirects' );
|
||||
$reflect = new ReflectionMethod( $classname, 'checkRedirects' );
|
||||
|
||||
/* Now store the data for this application that we need */
|
||||
$response[ mb_strtolower( $namespace ) ][ mb_strtolower( $application ) ][] = array(
|
||||
@@ -144,6 +155,6 @@ class _converters extends \IPS\Api\Controller
|
||||
/* Sort */
|
||||
ksort( $response );
|
||||
|
||||
return new \IPS\Api\Response( 200, $response );
|
||||
return new Response( 200, $response );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user