Version 4.3.0

This commit is contained in:
Neo committed 2025-12-19 05:47:12 -08:00
1 parent 96997ddd8e
commit fe1acf984a
1349 files changed
+116159 -67711

No files matched your search

+27 -18
View File
@@ -90,7 +90,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
}
$hook->type = $values['plugin_hook_type'];
$hook->class = ( $values['plugin_hook_type'] == 'C' ) ? ( '\IPS\\' . $values['plugin_hook_class'] ) : ( '\IPS\Theme\class_' . $values['plugin_hook_group'] );
$hook->filename = $values['plugin_hook_location'] ?: md5( uniqid() );
$hook->filename = $values['plugin_hook_location'] ?: md5( mt_rand() );
$hook->save();
$abstract = '';
@@ -116,6 +116,12 @@ class _Hook extends \IPS\Patterns\ActiveRecord
);
\file_put_contents( $hookDir . "/{$hook->filename}.php", $contents );
if ( $values['plugin_hook_type'] != 'C' )
{
$hook->writeThemeHookData( array() );
}
static::writeDataFile();
/* Write application json file automatically */
@@ -209,6 +215,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
}
$hooks = array();
$seen = array();
$stmt = \IPS\Db::i()->select(
'core_hooks.*, core_plugins.*, core_applications.*',
@@ -225,20 +232,22 @@ class _Hook extends \IPS\Patterns\ActiveRecord
foreach ( $stmt as $row )
{
if ( $row['plugin'] )
$overloadedClass = trim( $row['class'] );
$file = ( $row['plugin'] ) ? "plugins/{$row['plugin_location']}/hooks/{$row['filename']}.php" : "applications/{$row['app']}/hooks/{$row['filename']}.php";
$class = ( $row['plugin'] ) ? "hook{$row['id']}" : $row['app'] . '_hook_' . $row['filename'];
/* Duplicate rows cause WSOD as class is created twice by monkey patching */
if ( isset( $seen[ $overloadedClass ][ $file ][ $class ] ) )
{
$hooks[ trim( $row['class'] ) ][ $row['id'] ] = array(
'file' => "plugins/{$row['plugin_location']}/hooks/{$row['filename']}.php",
'class' => "hook{$row['id']}",
);
continue;
}
else
{
$hooks[ trim( $row['class'] ) ][ $row['id'] ] = array(
'file' => "applications/{$row['app']}/hooks/{$row['filename']}.php",
'class' => $row['app'] . '_hook_' . $row['filename'],
);
}
$seen[ $overloadedClass ][ $file ][ $class ] = true;
$hooks[ $overloadedClass ][ $row['id'] ] = array(
'file' => $file,
'class' => $class,
);
}
\file_put_contents( \IPS\ROOT_PATH . '/plugins/hooks.php', "<?php\nreturn " . var_export( $hooks, TRUE ) . ';' );
@@ -344,7 +353,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
}
$method->signature = json_encode( 'function ' . $method->name . '\(' );
$method->codeToInject = json_encode( "\n\t{$method->getDocComment()}\n\t" . ( $method->isFinal() ? 'final ' : '' ) . ( $method->isAbstract() ? 'abstract ' : '' ) . ( $method->isStatic() ? 'static ' : '' ) . ( $method->isPublic() ? 'public ' : 'protected ' ) . "function {$method->name}(" . ( empty( $parameters ) ? '' : ( ' ' . implode(', ', $parameters ) . ' ' ) ) . ")\n\t{\n\t\treturn call_user_func_array( 'parent::{$method->name}', func_get_args() );\n\t}\n" );
$method->codeToInject = json_encode( "\n\t{$method->getDocComment()}\n\t" . ( $method->isFinal() ? 'final ' : '' ) . ( $method->isAbstract() ? 'abstract ' : '' ) . ( $method->isStatic() ? 'static ' : '' ) . ( $method->isPublic() ? 'public ' : 'protected ' ) . "function {$method->name}(" . ( empty( $parameters ) ? '' : ( ' ' . implode( ', ', $parameters ) . ' ' ) ) . ")\n\t{\n\t\treturn parent::{$method->name}(" . ( empty( $parameters ) ? '' : ( ' ' . implode( ', ', array_map( function( $param ){ return str_replace( '&', '', $param ); }, $parameters ) ) . ' ' ) ) . ");\n\t}\n" );
$data[ $method->getDeclaringClass()->getName() ]['methods'][ $method->getName() ] = $method;
}
@@ -386,7 +395,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
unset( $hookData[ \IPS\Request::i()->template ] );
}
$this->_writeThemeHookData( $hookData );
$this->writeThemeHookData( $hookData );
/* Boink */
\IPS\Output::i()->redirect( $url->setQueryString( 'template', \IPS\Request::i()->template )->setQueryString( 'do', 'editHook' )->stripQueryString( 'delete' ) );
@@ -501,7 +510,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
}
/* Write */
$this->_writeThemeHookData( $hookData );
$this->writeThemeHookData( $hookData );
/* Write application json file automatically */
if( $this->app )
@@ -538,12 +547,12 @@ class _Hook extends \IPS\Patterns\ActiveRecord
* @param array $hookData Hook data
* @return void
*/
protected function _writeThemeHookData( $hookData )
public function writeThemeHookData( $hookData )
{
/* Build */
if( !count( $hookData ) )
{
$hookData = "/* !Hook Data - DO NOT REMOVE */\n\n/* End Hook Data */";
$hookData = "/* !Hook Data - DO NOT REMOVE */\npublic static function hookData() {\n return parent::hookData();\n}\n/* End Hook Data */";
}
else
{
+65 -15
View File
@@ -116,6 +116,50 @@ class _Plugin extends \IPS\Node\Model
return self::$multitons;
}
/**
* Get enabled plugins
*
* @return array
*/
public static function enabledPlugins()
{
$plugins = static::plugins();
$enabled = array();
foreach( $plugins as $key => $plugin )
{
if( $plugin->enabled )
{
$enabled[ $key ] = $plugin;
}
}
return $enabled;
}
/**
* Get the plugin from the file path
*
* @param string $path Path to a file for the plugin
* @return \IPS\Plugin
* @throws \OutOfRangeException
*/
public static function getPluginFromPath( $path )
{
if( preg_match( "/\/plugins\/(.+?)\//", $path, $matches ) )
{
foreach( static::plugins() as $plugin )
{
if( $plugin->location == $matches[1] )
{
return $plugin;
}
}
}
throw new \OutOfRangeException;
}
/**
* [Node] Does the currently logged in user have permission to add aa root node?
@@ -190,7 +234,7 @@ class _Plugin extends \IPS\Node\Model
{
if ( !$this->_id AND isset( $values['plugin_location'] ) )
{
$values['plugin_location'] = $values['plugin_location'] ?: ( 'p' . mb_substr( md5( uniqid() ), 0, 10 ) );
$values['plugin_location'] = $values['plugin_location'] ?: ( 'p' . mb_substr( md5( mt_rand() ), 0, 10 ) );
@\mkdir( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}" );
\file_put_contents( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/index.html", '' );
@@ -457,6 +501,8 @@ CODE;
\IPS\Db::i()->update( 'core_theme_css', array( 'css_hidden' => !$enabled ), array( 'css_plugin=?', $this->id ) );
\IPS\Theme::deleteCompiledCss( 'core', 'front', 'custom' );
}
\IPS\Db::i()->update( 'core_tasks', array( 'enabled' => (bool) $enabled ), array( "plugin=?", $this->id ) );
}
/**
@@ -488,22 +534,26 @@ CODE;
require_once \IPS\ROOT_PATH . '/plugins/' . $this->location . '/uninstall.php';
}
$iterator = new \RecursiveDirectoryIterator( \IPS\ROOT_PATH . '/plugins/' . $this->location, \FilesystemIterator::SKIP_DOTS );
foreach ( new \RecursiveIteratorIterator( $iterator, \RecursiveIteratorIterator::CHILD_FIRST ) as $file )
{
if ( $file->isDir() )
try
{
$iterator = new \RecursiveDirectoryIterator( \IPS\ROOT_PATH . '/plugins/' . $this->location, \FilesystemIterator::SKIP_DOTS );
foreach ( new \RecursiveIteratorIterator( $iterator, \RecursiveIteratorIterator::CHILD_FIRST ) as $file )
{
@rmdir( $file->getPathname() );
if ( $file->isDir() )
{
@rmdir( $file->getPathname() );
}
else
{
@unlink( $file->getPathname() );
}
}
else
{
@unlink( $file->getPathname() );
}
$dir = \IPS\ROOT_PATH . '/plugins/' . $this->location;
$handle = opendir( $dir );
closedir ( $handle );
@rmdir( $dir );
}
$dir = \IPS\ROOT_PATH . '/plugins/' . $this->location;
$handle = opendir( $dir );
closedir ( $handle );
@rmdir( $dir );
catch( \UnexpectedValueException $e ){}
}
/* Delete stuff */
@@ -544,7 +594,7 @@ CODE;
}
}
unset( \IPS\Data\Store::i()->settings );
\IPS\Settings::i()->clearCache();
/* Write the data file */
\IPS\Plugin\Hook::writeDataFile();