Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+55 -37
View File
@@ -12,16 +12,32 @@
namespace IPS\convert;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use BadMethodCallException;
use Exception;
use InvalidArgumentException;
use IPS\Data\Store;
use IPS\Db;
use IPS\Db\Select;
use IPS\Http\Url;
use IPS\Log;
use IPS\Member;
use function defined;
use function get_class;
use function in_array;
use function is_null;
use function is_string;
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;
}
/**
* Converter Software Class
*/
abstract class _Software
abstract class Software
{
/**
* @brief \IPS\convert\App instance
@@ -46,12 +62,12 @@ abstract class _Software
/**
* Constructor
*
* @param \IPS\convert\App $app The application to reference for database and other information.
* @param App $app The application to reference for database and other information.
* @param bool $needDB If the database is needed or not.
* @return void
* @throws \InvalidArgumentException
* @throws InvalidArgumentException
*/
public function __construct( \IPS\convert\App $app, $needDB=TRUE )
public function __construct(App $app, $needDB=TRUE )
{
$this->app = $app;
@@ -90,19 +106,19 @@ abstract class _Software
{
try
{
$this->db = \IPS\Db::i( 'convert_' . $this->app->app_id, $connectionSettings );
$this->db = Db::i( 'convert_' . $this->app->app_id, $connectionSettings );
/* Are we utf8? */
if ( !\in_array( $this->app->db_charset, array( 'utf8', 'utf8mb4' ) ) )
if ( !in_array( $this->app->db_charset, array( 'utf8', 'utf8mb4' ) ) )
{
/* Get all db charsets */
$charsets = static::getDatabaseCharsets( $this->db );
/* Set a flag that the data is not UTF8... we need to convert it to UTF8 at conversion time. */
if ( !\in_array( mb_strtolower( $this->app->db_charset ), $charsets ) )
if ( !in_array( mb_strtolower( $this->app->db_charset ), $charsets ) )
{
/* @todo We need to use a comprehensive conversion system like the UTF8 Converter... or maybe we can provide instructions on how to use it on non-IPS databases if MB can't do it? */
throw new \InvalidArgumentException( 'invalid_charset' );
throw new InvalidArgumentException( 'invalid_charset' );
}
$this->isUtfEight = FALSE;
@@ -111,7 +127,7 @@ abstract class _Software
}
catch( \IPS\Db\Exception $e )
{
throw new \InvalidArgumentException( "Database Connection Failed: " . $e->getMessage() );
throw new InvalidArgumentException( "Database Connection Failed: " . $e->getMessage() );
}
}
}
@@ -136,7 +152,7 @@ abstract class _Software
}
else
{
\IPS\Log::log( "Call to undefined method in " . \get_class( $this ) . "::{$name}", 'converters' );
Log::log( "Call to undefined method in " . get_class( $this ) . "::{$name}", 'converters' );
return NULL;
}
}
@@ -221,24 +237,24 @@ abstract class _Software
* Software Name
*
* @return string
* @throws \BadMethodCallException
* @throws BadMethodCallException
*/
public static function softwareName()
{
/* Child classes must override this method */
throw new \BadMethodCallException( 'no_name' );
throw new BadMethodCallException( 'no_name' );
}
/**
* Software Key
*
* @return string
* @throws \BadMethodCallException
* @throws BadMethodCallException
*/
public static function softwareKey()
{
/* Child classes must override this method */
throw new \BadMethodCallException( 'no_key' );
throw new BadMethodCallException( 'no_key' );
}
/**
@@ -275,12 +291,12 @@ abstract class _Software
* Content we can convert from this software.
*
* @return array|NULL
* @throws \BadMethodCallException
* @throws BadMethodCallException
*/
public static function canConvert()
{
/* Child classes must override this method */
throw new \BadMethodCallException( 'nothing_to_convert' );
throw new BadMethodCallException( 'nothing_to_convert' );
}
/**
@@ -376,7 +392,7 @@ abstract class _Software
* @param array|NULL $where WHERE clause to only count specific rows, or NULL to count all.
* @param bool $recache Skip cache and pull directly (updating cache)
* @return integer
* @throws \IPS\convert\Exception
* @throws Exception
*/
public function countRows( $table, $where=NULL, $recache=FALSE )
{
@@ -384,16 +400,16 @@ abstract class _Software
{
$cacheKey = 'convert_' . $this->app->app_id . '_' . md5( $table . json_encode( $where ) );
if( !isset( \IPS\Data\Store::i()->$cacheKey ) OR $recache === TRUE )
if( !isset( Store::i()->$cacheKey ) OR $recache === TRUE )
{
\IPS\Data\Store::i()->$cacheKey = $this->db->select( 'COUNT(*)', $table, $where )->first();
Store::i()->$cacheKey = $this->db->select( 'COUNT(*)', $table, $where )->first();
}
return \IPS\Data\Store::i()->$cacheKey;
return Store::i()->$cacheKey;
}
catch( \Exception $e )
catch( Exception $e )
{
throw new \IPS\convert\Exception( sprintf( \IPS\Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
throw new Exception( sprintf( Member::loggedIn()->language()->get( 'could_not_count_rows' ), $table ) );
}
}
@@ -401,18 +417,18 @@ abstract class _Software
* Get Library Class
*
* @param string|NULL $library Specific library to fetch
* @return \IPS\convert\Library
* @throws \InvalidArgumentException
* @return Library
* @throws InvalidArgumentException
*/
public function getLibrary( $library=NULL )
{
$library = $library ?: $this->app->sw;
$classname = \IPS\convert\Library::libraries()[ $library ];
$classname = Library::libraries()[ $library ];
if ( ! class_exists( $classname ) )
{
throw new \InvalidArgumentException( 'invalid_library' );
throw new InvalidArgumentException( 'invalid_library' );
}
return new $classname( $this );
@@ -445,7 +461,7 @@ abstract class _Software
* @param string $idColumn The ID column to sort on, when not using keys.
* @param string|array|NULL $where WHERE clause for specific data to fetch.
* @param string $what What to fetch
* @return \IPS\Db\Select An \IPS\Db\Select object that can be further manipulated if necessary (e.g. joins)
* @return Select An \IPS\Db\Select object that can be further manipulated if necessary (e.g. joins)
*/
public function fetch( $table, $idColumn='id', $where=NULL, $what='*' )
{
@@ -464,9 +480,9 @@ abstract class _Software
$whereClause = array();
$whereClause[] = array( $libraryClass::$currentKeyName . '>?', $_SESSION['currentKeyValue'] );
if ( !\is_null( $where ) )
if ( !is_null( $where ) )
{
if ( \is_string( $where ) )
if ( is_string( $where ) )
{
$whereClause[] = array( $where );
}
@@ -492,12 +508,14 @@ abstract class _Software
}
/**
* Updates Posted Content to work with the parser.
* Pre-process content for the Invision Community text parser
*
* @param string $post The post
* @return string The converted post
* @param string The post
* @param string|null Content Classname passed by post-conversion rebuild
* @param int|null Content ID passed by post-conversion rebuild
* @return string The converted post
*/
public static function fixPostData( $post )
public static function fixPostData( string $post, ?string $className=null, ?int $contentId=null ): string
{
return $post;
}
@@ -505,7 +523,7 @@ abstract class _Software
/**
* Get database charsets
*
* @param \IPS\Db $database Database connection
* @param Db $database Database connection
* @return array
*/
public static function getDatabaseCharsets( $database )
@@ -524,7 +542,7 @@ abstract class _Software
/**
* Check if we can redirect the legacy URLs from this software to the new locations
*
* @return NULL|\IPS\Http\Url
* @return NULL|Url
*/
public function checkRedirects()
{