Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

@@ -1,20 +1,33 @@
<?php
/**
* @brief Converter: Manage conversions
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
* @copyright (c) Invision Power Services, Inc.
* @license https://www.invisioncommunity.com/legal/standards/
* @package Invision Community
* @subpackage convert
* @since 21 Jan 2015
*/
namespace IPS\convert\modules\admin\manage;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
{
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* manage
* Converter overview
*/
class _manage extends \IPS\Dispatcher\Controller
{
{
/**
* @brief Has been CSRF-protected
*/
public static $csrfProtected = TRUE;
/**
* Execute
*
@@ -22,6 +35,11 @@ class _manage extends \IPS\Dispatcher\Controller
*/
public function execute()
{
if ( \IPS\DEMO_MODE === TRUE )
{
\IPS\Output::i()->error( 'demo_mode_function_blocked', '2V407/1', 403, '' );
}
\IPS\Output::i()->responsive = FALSE;
\IPS\Dispatcher::i()->checkAcpPermission( 'manage_manage' );
parent::execute();
@@ -41,66 +59,75 @@ class _manage extends \IPS\Dispatcher\Controller
}
/* Remind the user that they must configure permissions after the conversion is complete */
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( 'convert_configure_permissions', 'warning' );
\IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate( 'global', 'core' )->message( 'convert_configure_permissions', 'info' );
/* Create the table */
$table = new \IPS\Helpers\Table\Db( 'convert_apps', \IPS\Http\Url::internal( 'app=convert&module=manage&controller=manage' ) );
$table = new \IPS\Helpers\Table\Db( 'convert_apps', \IPS\Http\Url::internal( 'app=convert&module=manage&controller=manage' ), array( 'parent=?', 0 ) );
$table->langPrefix = 'convert_';
$table->include = array( 'sw', 'app_key', 'name', 'parent', 'finished' );
$table->include = array( 'app_key', 'sw', 'start_date', 'finished' );
$table->parsers = array(
'sw' => function( $val, $row )
{
switch( $val )
$translate = function( $app )
{
case 'board':
$val = 'forums';
break;
case 'ccs':
$val = 'cms';
break;
switch( $app )
{
case 'board':
$app = 'forums';
break;
case 'ccs':
$app = 'cms';
break;
}
return $app;
};
/* The main row will always be the core application (except for legacy conversions) */
$applications = array( \IPS\Application::load( $translate( $val ) )->_title );
foreach( \IPS\Db::i()->select( '*', 'convert_apps', array( 'parent=?', $row['app_id'] ) ) as $software )
{
/* Translate the software key, if required */
$software['sw'] = $translate( $software['sw'] );
try
{
if ( \IPS\CONVERTERS_DEV_UI === TRUE )
{
$continueUrl = \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$software['app_id']}&continue=1" )->csrf();
$applications[] = "<a href='{$continueUrl}'>" . \IPS\Application::load( $software['sw'] )->_title . "</a>";
continue;
}
$applications[] = \IPS\Application::load( $software['sw'] )->_title;
}
catch( \OutOfRangeException $e )
{
$applications[] = mb_ucfirst( $software );
}
}
try
{
return \IPS\Application::load( $val )->_title;
}
catch( \OutOfRangeException $e )
{
return ucwords( $val );
}
return \IPS\Member::loggedIn()->language()->formatList( $applications );
},
'app_key' => function( $val, $row )
{
$app = \IPS\convert\App::constructFromData( $row );
try
{
$classname = get_class( $app->getSource() );
$classname = \get_class( $app->getSource() );
return $classname::softwareName();
}
catch( \Exception $ex )
{
return $app->name;
return $val;
}
},
'parent' => function( $val, $row )
'start_date' => function( $val )
{
try
{
if ( ! $val )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'convert_no_parent' );
}
else
{
return \IPS\convert\App::load( $val )->name;
}
}
catch( \OutOfRangeException $e )
{
return \IPS\Member::loggedIn()->language()->addToStack( 'convert_cannot_parent' );
}
return (string) \IPS\DateTime::ts( $val );
},
'finished' => function( $val )
{
@@ -146,43 +173,35 @@ class _manage extends \IPS\Dispatcher\Controller
\IPS\Application::load( $row['sw'] );
/* Try to load the app class - if exception, the converter no longer exists */
get_class( \IPS\convert\App::constructFromData( $row )->getSource() );
\IPS\convert\App::constructFromData( $row )->getSource();
$return = array();
if ( !$row['finished'] )
if ( !$row['finished'] OR \IPS\CONVERTERS_DEV_UI === TRUE )
{
$return[] = array(
'icon' => 'chevron-circle-right',
'title' => 'continue',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$row['app_id']}" )
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&id={$row['app_id']}&continue=1" )->csrf()
);
if ( $row['parent'] == 0 )
if( \IPS\CONVERTERS_DEV_UI === TRUE AND !$row['finished'] )
{
$return[] = array(
'icon' => 'check',
'title' => 'finish',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=finish&id={$row['app_id']}" ),
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=convert&do=finish&id={$row['app_id']}" )->csrf(),
'data' => array(
'confirm' => '', 'confirmSubMessage' => \IPS\Member::loggedIn()->language()->get( 'convert_finish_confirm' )
)
);
}
$return[] = array(
'icon' => 'pencil',
'title' => 'edit',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage&do=edit&id={$row['app_id']}" ),
);
$return[] = array(
'icon' => 'times-circle',
'title' => 'delete',
'link' => \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage&do=delete&id={$row['app_id']}" ),
'data' => array( 'delete' => '' ),
);
}
return $return;
@@ -217,23 +236,45 @@ class _manage extends \IPS\Dispatcher\Controller
$form = new \IPS\Helpers\Form;
$form->add( new \IPS\Helpers\Form\Text( 'classname', NULL, TRUE ) );
$apps = array();
foreach( new \DirectoryIterator( \IPS\ROOT_PATH . '/applications/convert/sources/Library' ) as $file )
{
if ( !$file->isDir() AND !$file->isDot() AND ( \substr( $file->getFilename(), -4 ) == '.php' ) AND $file->getFilename() != 'Board.php' AND $file->getFilename() != 'Ccs.php' )
{
$apps[ str_replace( '.php', '', $file->getFilename() ) ] = str_replace( '.php', '', $file->getFilename() );
}
}
$form->add( new \IPS\Helpers\Form\Select( 'library', NULL, FALSE, array( 'options' => $apps ) ) );
if ( $values = $form->values() )
{
$default = file_get_contents( \IPS\ROOT_PATH . '/applications/convert/data/defaults/Software.txt' );
$code = str_replace( array( '<#CLASS#>', '<#APP#>', '<#CLASS_LOWER#>' ), array( $values['classname'], $values['library'], mb_strtolower( $values['classname'] ) ), $default );
\file_put_contents( \IPS\ROOT_PATH . '/applications/convert/sources/Software/' . $values['library'] . '/' . $values['classname'] . '.php', $code );
/* Get the default code */
$default = file_get_contents( \IPS\ROOT_PATH . '/applications/convert/data/defaults/Software.txt' );
/* Explode the entered class name to figure out the file path and namespace */
$exploded = explode( '\\', ltrim( $values['classname'], '\\' ) );
/* Copy the exploded array to generate the path */
$copied = $exploded;
/* Shift off IPS from the namespace */
array_shift( $copied );
/* Get our application key */
$application = array_shift( $copied );
/* Generate our path */
$filepath = \IPS\ROOT_PATH . "/applications/{$application}/sources/" . implode( '/', $copied ) . ".php";
/* Now figure out our namespace, class, and default code with replacements */
$classname = array_pop( $exploded );
$namespace = implode( '\\', $exploded );
$code = str_replace( array( '<#NAMESPACE#>', '<#CLASS#>', '<#CLASS_LOWER#>' ), array( $namespace, $classname, mb_strtolower( $classname ) ), $default );
/* Check if we need to create a folder */
if( \count( $copied ) > 1 )
{
$folder = \IPS\ROOT_PATH . "/applications/{$application}/sources/" . $copied[0];
if( !file_exists( $folder ) )
{
@mkdir( $folder );
@chmod( $folder, \IPS\FOLDER_PERMISSION_NO_WRITE );
}
}
/* Generate the file */
\file_put_contents( $filepath, $code );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage" ), 'saved' );
}
@@ -259,9 +300,42 @@ class _manage extends \IPS\Dispatcher\Controller
if ( $values = $form->values() )
{
$default = file_get_contents( \IPS\ROOT_PATH . '/applications/convert/data/defaults/Library.txt' );
$code = str_replace( array( '<#CLASS#>', '<#CLASS_LOWER#>' ), array( $values['classname'], mb_strtolower( $values['classname'] ) ), $default );
\file_put_contents( \IPS\ROOT_PATH . '/applications/convert/sources/Library/' . $values['classname'] . '.php', $code );
/* Get the default code */
$default = file_get_contents( \IPS\ROOT_PATH . '/applications/convert/data/defaults/Library.txt' );
/* Explode the entered class name to figure out the file path and namespace */
$exploded = explode( '\\', ltrim( $values['classname'], '\\' ) );
/* Copy the exploded array to generate the path */
$copied = $exploded;
/* Shift off IPS from the namespace */
array_shift( $copied );
/* Get our application key */
$application = array_shift( $copied );
/* Generate our path */
$filepath = \IPS\ROOT_PATH . "/applications/{$application}/sources/" . implode( '/', $copied ) . ".php";
/* Now figure out our namespace, class, and default code with replacements */
$classname = array_pop( $exploded );
$namespace = implode( '\\', $exploded );
$code = str_replace( array( '<#NAMESPACE#>', '<#CLASS#>', '<#CLASS_LOWER#>' ), array( $namespace, $classname, mb_strtolower( $classname ) ), $default );
/* Check if we need to create a folder */
if( \count( $copied ) > 1 )
{
$folder = \IPS\ROOT_PATH . "/applications/{$application}/sources/" . $copied[0];
if( !file_exists( $folder ) )
{
@mkdir( $folder );
@chmod( $folder, \IPS\FOLDER_PERMISSION_NO_WRITE );
}
}
/* Generate the file */
\file_put_contents( $filepath, $code );
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=convert&module=manage&controller=manage' ), 'saved' );
}
@@ -332,12 +406,12 @@ class _manage extends \IPS\Dispatcher\Controller
$db = \IPS\Db::i( 'convertertest', $connectionSettings );
/* Now test the charset */
if ( $values['db_charset'] AND !in_array( $values['db_charset'], array( 'utf8', 'utf8mb4' ) ) )
if ( $values['db_charset'] AND !\in_array( $values['db_charset'], array( 'utf8', 'utf8mb4' ) ) )
{
/* Get all db charsets and make sure the one we entered is valid */
$charsets = \IPS\convert\Software::getDatabaseCharsets( $db );
if ( !in_array( mb_strtolower( $values['db_charset'] ), $charsets ) )
if ( !\in_array( mb_strtolower( $values['db_charset'] ), $charsets ) )
{
throw new \InvalidArgumentException( 'invalid_charset' );
}
@@ -383,50 +457,29 @@ class _manage extends \IPS\Dispatcher\Controller
}
$app->db_host = $values['db_host'];
$app->db_port = $values['db_port'];
$app->db_port = $values['db_port'];
$app->db_db = $values['db_db'];
$app->db_user = $values['db_user'];
$app->db_pass = $values['db_pass'];
$app->db_prefix = $values['db_prefix'];
$app->db_charset = $values['db_charset'];
$app->save();
foreach( $app->children() as $child )
{
$child->db_host = $values['db_host'];
$child->db_port = $values['db_port'];
$child->db_db = $values['db_db'];
$child->db_user = $values['db_user'];
$child->db_pass = $values['db_pass'];
$child->db_prefix = $values['db_prefix'];
$child->db_charset = $values['db_charset'];
$child->save();
}
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "app=convert&module=manage&controller=manage" ), 'saved' );
}
\IPS\Output::i()->output = $form;
}
/**
* Delete a Conversion
*
* @return void
*/
public function delete()
{
if ( !isset( \IPS\Request::i()->id ) )
{
\IPS\Output::i()->error( 'no_conversion_app', '2V100/5' );
}
try
{
$app = \IPS\convert\App::load( \IPS\Request::i()->id );
/* Check for children */
try
{
\IPS\DB::i()->select( '*', 'convert_apps', array( 'parent=?', $app->app_id ) )->first();
\IPS\Output::i()->error( 'conversion_app_has_children', '2V100/6' );
}
catch( \UnderflowException $ex ) { }
$app->delete();
\IPS\Output::i()->redirect( \IPS\Http\Url::internal( 'app=convert&module=manage&controller=manage' ), 'conversion_deleted' );
}
catch( \OutOfRangeException $e )
{
\IPS\Output::i()->error( 'conversion_app_not_found', '2V100/6', 404 );
}
}
}