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

+47 -37
View File
@@ -11,16 +11,26 @@
namespace IPS\File;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Db;
use IPS\File;
use IPS\Http\Url;
use IPS\Member;
use LogicException;
use UnderflowException;
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;
}
/**
* File Handler: Database
*/
class _Database extends \IPS\File
class Database extends File
{
/* !ACP Configuration */
@@ -30,7 +40,7 @@ class _Database extends \IPS\File
* @param array $configuration Configuration if editing a setting, or array() if creating a setting.
* @return array
*/
public static function settings( $configuration=array() )
public static function settings( array $configuration=array() ) : array
{
return array();
}
@@ -40,9 +50,9 @@ class _Database extends \IPS\File
*
* @param array $values The submitted values
* @return void
* @throws \LogicException
* @throws LogicException
*/
public static function testSettings( &$values )
public static function testSettings( array &$values ) : void
{
}
@@ -53,9 +63,9 @@ class _Database extends \IPS\File
* @param array $settings Configuration settings
* @return string
*/
public static function displayName( $settings )
public static function displayName( array $settings ) : string
{
return \IPS\Member::loggedIn()->language()->addToStack('filehandler__Database');
return Member::loggedIn()->language()->addToStack('filehandler__Database');
}
/* !File Handling */
@@ -63,14 +73,14 @@ class _Database extends \IPS\File
/**
* Is this URL valid for this engine?
*
* @param \IPS\Http\Url $url URL
* @param Url $url URL
* @param array $configuration Specific configuration for this method
* @return bool
*/
public static function isValidUrl( $url, $configuration )
public static function isValidUrl( Url $url, array $configuration ) : bool
{
$check = \IPS\Http\Url::internal( "applications/core/interface/file/index.php", 'none', NULL, array(), \IPS\Http\Url::PROTOCOL_RELATIVE );
if ( mb_substr( $url, 0, mb_strlen( $check ) ) === $check )
$check = Url::internal( "applications/core/interface/file/index.php", 'none', NULL, array(), Url::PROTOCOL_RELATIVE );
if ( mb_substr( (string)$url, 0, mb_strlen( $check ) ) === $check )
{
return TRUE;
}
@@ -84,7 +94,7 @@ class _Database extends \IPS\File
* @param array $configuration Storage configuration
* @return void
*/
public function __construct( $configuration )
public function __construct( array $configuration )
{
$this->container = 'monthly_' . date( 'Y' ) . '_' . date( 'm' );
parent::__construct( $configuration );
@@ -95,9 +105,9 @@ class _Database extends \IPS\File
*
* @return string
*/
public function baseUrl()
public function baseUrl() : string
{
return (string) \IPS\Http\Url::internal( "applications/core/interface/file/index.php?file=", 'none', NULL, array(), \IPS\Http\Url::PROTOCOL_RELATIVE );
return (string) Url::internal( "applications/core/interface/file/index.php?file=", 'none', NULL, array(), Url::PROTOCOL_RELATIVE );
}
/**
@@ -106,9 +116,9 @@ class _Database extends \IPS\File
* @param string $filename The filename
* @return string
*/
public function encodeFileUrl( $filename )
public function encodeFileUrl( string $filename ) : string
{
return \IPS\Http\Url::encodeComponent( \IPS\Http\Url::COMPONENT_QUERY_VALUE, $filename );
return Url::encodeComponent( Url::COMPONENT_QUERY_VALUE, $filename );
}
/**
@@ -116,7 +126,7 @@ class _Database extends \IPS\File
*
* @return void
*/
public function load()
public function load() : void
{
parent::load();
@@ -130,15 +140,15 @@ class _Database extends \IPS\File
{
try
{
$record = \IPS\Db::i()->select( '*', 'core_files', array( 'id=? AND salt=?', $this->url->queryString['id'], $this->url->queryString['salt'] ) )->first();
$record = Db::i()->select( '*', 'core_files', array( 'id=? AND salt=?', $this->url->queryString['id'], $this->url->queryString['salt'] ) )->first();
$this->contents = $record['contents'];
$this->filename = $record['filename'];
$this->originalFilename = $this->unObscureFilename( $this->filename );
$this->container = $record['container'];
}
catch( \UnderflowException $ex )
catch( UnderflowException $ex )
{
throw new \IPS\File\Exception( $this->container . '/' . $this->filename, \IPS\File\Exception::DOES_NOT_EXIST, $this->originalFilename );
throw new Exception( $this->container . '/' . $this->filename, Exception::DOES_NOT_EXIST, $this->originalFilename );
}
}
}
@@ -149,18 +159,18 @@ class _Database extends \IPS\File
* @param bool $refresh If TRUE, will fetch again
* @return string
*/
public function contents( $refresh=FALSE )
public function contents( bool $refresh=FALSE ) : string
{
if ( $this->contents === NULL or $refresh === TRUE )
{
try
{
$record = \IPS\Db::i()->select( '*', 'core_files', array( 'filename=? AND container=?', $this->filename, $this->container ) )->first();
$record = Db::i()->select( '*', 'core_files', array( 'filename=? AND container=?', $this->filename, $this->container ) )->first();
$this->contents = $record['contents'];
}
catch( \UnderflowException $ex )
catch( UnderflowException $ex )
{
throw new \IPS\File\Exception( $this->container . '/' . $this->filename, \IPS\File\Exception::DOES_NOT_EXIST, $this->originalFilename );
throw new Exception( $this->container . '/' . $this->filename, Exception::DOES_NOT_EXIST, $this->originalFilename );
}
}
return $this->contents;
@@ -172,10 +182,10 @@ class _Database extends \IPS\File
* @param string $contents New contents
* @return void
*/
public function replace( $contents )
public function replace( string $contents ) : void
{
/* Ensure any existing files with this name are removed otherwise the wrong file may be selected from the database as it will store multiple copies when replace() is used */
\IPS\Db::i()->delete( 'core_files', array( 'filename=? and container=?', $this->filename, $this->container ) );
Db::i()->delete( 'core_files', array( 'filename=? and container=?', $this->filename, $this->container ) );
parent::replace( $contents );
}
@@ -185,18 +195,18 @@ class _Database extends \IPS\File
*
* @return void
*/
public function save()
public function save() : void
{
$salt = md5( mt_rand() );
$id = \IPS\Db::i()->insert( 'core_files', array(
$id = Db::i()->insert( 'core_files', array(
'filename' => $this->filename,
'salt' => $salt,
'contents' => $this->contents(),
'container' => $this->container
) );
$this->url = \IPS\Http\Url::internal( "applications/core/interface/file/index.php?file={$this->container}/{$this->filename}", 'none', NULL, array(), \IPS\Http\Url::PROTOCOL_RELATIVE );
$this->url = Url::internal( "applications/core/interface/file/index.php?file={$this->container}/{$this->filename}", 'none', NULL, array(), Url::PROTOCOL_RELATIVE );
}
/**
@@ -204,15 +214,15 @@ class _Database extends \IPS\File
*
* @return void
*/
public function delete()
public function delete() : void
{
\IPS\Db::i()->delete( 'core_files', array( 'filename=? AND container=?', $this->filename, $this->container ) );
Db::i()->delete( 'core_files', array( 'filename=? AND container=?', $this->filename, $this->container ) );
/* Log deletion request */
$immediateCaller = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 1 );
$debug = array_map( function( $row ) {
return array_filter( $row, function( $key ) {
return \in_array( $key, array( 'class', 'function', 'line' ) );
return in_array( $key, array( 'class', 'function', 'line' ) );
}, ARRAY_FILTER_USE_KEY );
}, debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) );
$this->log( "file_deletion", 'delete', $debug, 'log' );
@@ -224,9 +234,9 @@ class _Database extends \IPS\File
* @param string $container Key
* @return void
*/
public function deleteContainer( $container )
public function deleteContainer( string $container ) : void
{
\IPS\Db::i()->delete( 'core_files', array( 'container=?', $container ) );
Db::i()->delete( 'core_files', array( 'container=?', $container ) );
/* Log deletion request */
$realContainer = $this->container;
@@ -242,7 +252,7 @@ class _Database extends \IPS\File
* @param array $engines All file storage engine extension objects
* @return array
*/
public function removeOrphanedFiles( $fileIndex, $engines )
public function removeOrphanedFiles( int $fileIndex, array $engines ) : array
{
/* Start off our results array */
$results = array(
@@ -254,7 +264,7 @@ class _Database extends \IPS\File
$checked = 0;
/* Loop over files */
foreach( \IPS\Db::i()->select( '*', 'core_files', array(), 'id ASC', array( $fileIndex, 100 ) ) as $file )
foreach( Db::i()->select( '*', 'core_files', array(), 'id ASC', array( $fileIndex, 100 ) ) as $file )
{
$checked++;