Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
+39
-18
@@ -11,7 +11,7 @@
|
||||
namespace IPS\Plugin;
|
||||
|
||||
/* 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;
|
||||
@@ -80,7 +80,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$hook = new static;
|
||||
if ( is_int( $appOrPluginId ) )
|
||||
if ( \is_int( $appOrPluginId ) )
|
||||
{
|
||||
$hook->plugin = $appOrPluginId;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
$abstract = $reflection->isAbstract() ? 'abstract ' : '';
|
||||
}
|
||||
|
||||
$classname = is_int( $appOrPluginId ) ? "hook{$hook->id}" : "{$appOrPluginId}_hook_{$hook->filename}";
|
||||
$classname = \is_int( $appOrPluginId ) ? "hook{$hook->id}" : "{$appOrPluginId}_hook_{$hook->filename}";
|
||||
|
||||
/* Work out the contents */
|
||||
$contents = str_replace(
|
||||
@@ -129,6 +129,10 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
\IPS\Application::load( $hook->app )->buildHooks();
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Plugin::load( $hook->plugin )->buildHooks();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
}
|
||||
@@ -159,7 +163,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
/* Table */
|
||||
default:
|
||||
$table = new \IPS\Helpers\Table\Db( static::$databaseTable, $url, ( is_string( $appOrPluginId ) ? array( 'app=?', $appOrPluginId ) : array( 'plugin=?', $appOrPluginId ) ) );
|
||||
$table = new \IPS\Helpers\Table\Db( static::$databaseTable, $url, ( \is_string( $appOrPluginId ) ? array( 'app=?', $appOrPluginId ) : array( 'plugin=?', $appOrPluginId ) ) );
|
||||
$table->include = array( 'filename', 'class' );
|
||||
$table->langPrefix = 'plugin_hook_';
|
||||
$table->sortBy = $table->sortBy ?: 'class';
|
||||
@@ -250,12 +254,21 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
);
|
||||
}
|
||||
|
||||
\file_put_contents( \IPS\ROOT_PATH . '/plugins/hooks.php', "<?php\nreturn " . var_export( $hooks, TRUE ) . ';' );
|
||||
|
||||
/* Clear zend opcache if enabled */
|
||||
if ( function_exists( 'opcache_invalidate' ) )
|
||||
$contents = "<?php\nreturn " . var_export( $hooks, TRUE ) . ';';
|
||||
|
||||
if ( \IPS\CIC2 )
|
||||
{
|
||||
@opcache_invalidate( \IPS\ROOT_PATH . '/plugins/hooks.php' );
|
||||
\IPS\Cicloud\file( 'hooks.php', $contents, 'plugins' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\file_put_contents( \IPS\ROOT_PATH . '/plugins/hooks.php', $contents );
|
||||
|
||||
/* Clear zend opcache if enabled */
|
||||
if ( \function_exists( 'opcache_invalidate' ) )
|
||||
{
|
||||
@opcache_invalidate( \IPS\ROOT_PATH . '/plugins/hooks.php' );
|
||||
}
|
||||
}
|
||||
|
||||
/* IPS Cloud Sync */
|
||||
@@ -273,11 +286,12 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
if ( $this->plugin )
|
||||
{
|
||||
$plugin = \IPS\Plugin::load( $this->plugin );
|
||||
return \IPS\ROOT_PATH . "/plugins/{$plugin->location}/hooks/{$this->filename}.php";
|
||||
|
||||
return \IPS\SITE_FILES_PATH . "/plugins/{$plugin->location}/hooks/{$this->filename}.php";
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\ROOT_PATH . "/applications/{$this->app}/hooks/{$this->filename}.php";
|
||||
return \IPS\SITE_FILES_PATH . "/applications/{$this->app}/hooks/{$this->filename}.php";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,7 +318,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
/* Build Form */
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'code', file_get_contents( $this->getFilename() ), TRUE, array( 'mode' => 'php' ), array( $this, 'validate' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'code', file_get_contents( $this->getFilename() ), TRUE, array( 'mode' => 'php', 'height' => 696 ), array( $this, 'validate' ) ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
@@ -347,13 +361,20 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
try
|
||||
{
|
||||
$parameters[] = ( $parameter->getClass() ? ( '\\' . $parameter->getClass()->getName() . ' ' ) : '' ) . ( $parameter->isPassedByReference() ? '&' : '' ) . '$' . $parameter->name . ( $parameter->isOptional() ? ( '=' . var_export( $parameter->getDefaultValue(), TRUE ) ) : '' );
|
||||
$parameters[] = ( $parameter->getClass() ? ( ( ( $parameter->allowsNull() ) ? '?' : '' ). '\\' . $parameter->getClass()->getName() . ' ' ) : '' ) . ( $parameter->isPassedByReference() ? '&' : '' ) . '$' . $parameter->name . ( $parameter->isOptional() ? ( '=' . var_export( $parameter->getDefaultValue(), TRUE ) ) : '' );
|
||||
}
|
||||
catch ( \ReflectionException $e ) {}
|
||||
}
|
||||
|
||||
|
||||
$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 parent::{$method->name}(" . ( empty( $parameters ) ? '' : ( ' ' . implode( ', ', array_map( function( $param ){ return '$' . $param->name; }, $method->getParameters() ) ) . ' ' ) ) . ");\n\t}\n" );
|
||||
|
||||
$returnType = '';
|
||||
if ( $method->getReturnType() )
|
||||
{
|
||||
$returnType = ( $method->getReturnType()->isBuiltin() ) ? ": " . $method->getReturnType()->getName() : ":\\" . $method->getReturnType()->getName();
|
||||
}
|
||||
|
||||
$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 ) . ' ' ) ) . ")" . $returnType . "\n\t{\n\t\treturn parent::{$method->name}(" . ( empty( $parameters ) ? '' : ( ' ' . implode( ', ', array_map( function( $param ){ return '$' . $param->name; }, $method->getParameters() ) ) . ' ' ) ) . ");\n\t}\n" );
|
||||
|
||||
$data[ $method->getDeclaringClass()->getName() ]['methods'][ $method->getName() ] = $method;
|
||||
}
|
||||
@@ -390,7 +411,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
unset( $hookData[ \IPS\Request::i()->template ][ \IPS\Request::i()->delete ] );
|
||||
|
||||
if( isset( $hookData[ \IPS\Request::i()->template ] ) AND !count( $hookData[ \IPS\Request::i()->template ] ) )
|
||||
if( isset( $hookData[ \IPS\Request::i()->template ] ) AND !\count( $hookData[ \IPS\Request::i()->template ] ) )
|
||||
{
|
||||
unset( $hookData[ \IPS\Request::i()->template ] );
|
||||
}
|
||||
@@ -550,7 +571,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
public function writeThemeHookData( $hookData )
|
||||
{
|
||||
/* Build */
|
||||
if( !count( $hookData ) )
|
||||
if( !\count( $hookData ) )
|
||||
{
|
||||
$hookData = "/* !Hook Data - DO NOT REMOVE */\npublic static function hookData() {\n return parent::hookData();\n}\n/* End Hook Data */";
|
||||
}
|
||||
@@ -585,7 +606,7 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( eval( str_replace( 'extends _HOOK_CLASS_', '', $val ) ) === FALSE )
|
||||
if ( eval( str_replace( 'extends _HOOK_CLASS_', 'extends Stdclass', $val ) ) === FALSE )
|
||||
{
|
||||
throw new \DomainException( 'plugin_hook_code_err_parse' );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user