Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -27,6 +27,7 @@ class _converters extends \IPS\Api\Controller
|
||||
* GET /convert/converters
|
||||
* Get list of converter applications and what can be converted from each application
|
||||
*
|
||||
* @apiclientonly
|
||||
* @apiparam string applications Comma-delimited list of applications to filter by
|
||||
* @return array
|
||||
*/
|
||||
@@ -54,7 +55,7 @@ class _converters extends \IPS\Api\Controller
|
||||
foreach( new \DirectoryIterator( $directory->getPathname() ) as $softwares )
|
||||
{
|
||||
/* Skip ../ and any non-files */
|
||||
if( $softwares->isDot() OR !$softwares->isFile() )
|
||||
if( $softwares->isDot() OR !$softwares->isFile() OR mb_substr( $softwares->getFilename(), -3 ) !== 'php' )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -70,6 +71,12 @@ class _converters extends \IPS\Api\Controller
|
||||
continue;
|
||||
}
|
||||
|
||||
/* A work around for an odd-case */
|
||||
if( mb_strtolower( $namespace ) == 'xenfororm' )
|
||||
{
|
||||
$namespace = 'xenforo';
|
||||
}
|
||||
|
||||
/* Initialize this application's array if necessary */
|
||||
if( !isset( $response[ mb_strtolower( $namespace ) ] ) )
|
||||
{
|
||||
@@ -80,9 +87,25 @@ class _converters extends \IPS\Api\Controller
|
||||
$rawConvert = array_keys( $classname::canConvert() );
|
||||
$canConvert = array();
|
||||
|
||||
/* Get extra_steps */
|
||||
$extraSteps = array();
|
||||
foreach( $classname::canConvert() as $convert )
|
||||
{
|
||||
if( isset( $convert['extra_steps'] ) )
|
||||
{
|
||||
$extraSteps = array_merge( $extraSteps, $convert['extra_steps'] );
|
||||
}
|
||||
}
|
||||
|
||||
/* Get lang strings for what we can convert */
|
||||
foreach( $rawConvert as $convertType )
|
||||
{
|
||||
/* Skip extra steps */
|
||||
if( in_array( $convertType, $extraSteps ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$canConvert[] = \IPS\Lang::load( \IPS\Lang::defaultLanguage() )->addToStack(
|
||||
preg_replace_callback( "/([A-Z])/", function( $match ){
|
||||
return "_" . mb_strtolower( $match[1] );
|
||||
@@ -90,15 +113,37 @@ class _converters extends \IPS\Api\Controller
|
||||
);
|
||||
}
|
||||
|
||||
/* Reflect the class to figure out if redirects are enabled */
|
||||
$reflect = new \ReflectionMethod( $classname, 'checkRedirects' );
|
||||
|
||||
/* Now store the data for this application that we need */
|
||||
$response[ mb_strtolower( $namespace ) ][ mb_strtolower( $application ) ] = array(
|
||||
$response[ mb_strtolower( $namespace ) ][ mb_strtolower( $application ) ][] = array(
|
||||
'name' => $classname::softwareName(),
|
||||
'key' => $classname::softwareKey(),
|
||||
'canConvert' => $canConvert
|
||||
'canConvert' => $canConvert,
|
||||
'redirections' => ( str_replace( '\_', '\\', $reflect->getDeclaringClass()->getName() ) === mb_substr( $classname, 1 ) )
|
||||
);
|
||||
|
||||
if( mb_strtolower( $application ) == 'core' )
|
||||
{
|
||||
$response[ mb_strtolower( $namespace ) ]['@name'] = $classname::softwareName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Make sure a name is defined */
|
||||
foreach( $response as $software => $data )
|
||||
{
|
||||
if( !isset( $data['@name'] ) )
|
||||
{
|
||||
$first = array_shift( $data );
|
||||
$response[ $software ]['@name'] = $first[0]['name'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Sort */
|
||||
ksort( $response );
|
||||
|
||||
return new \IPS\Api\Response( 200, $response );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user