Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
+91
-12
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Hook Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 5 Aug 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -102,8 +102,28 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
|
||||
$classname = is_int( $appOrPluginId ) ? "hook{$hook->id}" : "{$appOrPluginId}_hook_{$hook->filename}";
|
||||
\file_put_contents( $hookDir . "/{$hook->filename}.php", "//<?php\n\n{$abstract}class {$classname} extends _HOOK_CLASS_\n{\n\n\n}" );
|
||||
|
||||
/* Work out the contents */
|
||||
$contents = str_replace(
|
||||
array(
|
||||
'{abstract}',
|
||||
'{classname}',
|
||||
),
|
||||
array(
|
||||
$abstract,
|
||||
$classname,
|
||||
),
|
||||
\file_get_contents( \IPS\ROOT_PATH . '/applications/core/data/defaults/Hook.txt' )
|
||||
);
|
||||
|
||||
\file_put_contents( $hookDir . "/{$hook->filename}.php", $contents );
|
||||
static::writeDataFile();
|
||||
|
||||
/* Write application json file automatically */
|
||||
if( $hook->app )
|
||||
{
|
||||
\IPS\Application::load( $hook->app )->buildHooks();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
}
|
||||
@@ -116,7 +136,15 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
try
|
||||
{
|
||||
$hook = static::load( \IPS\Request::i()->hook )->delete();
|
||||
$hook = static::load( \IPS\Request::i()->hook );
|
||||
$hook->delete();
|
||||
|
||||
/* Write application json file automatically */
|
||||
if( $hook->app )
|
||||
{
|
||||
\IPS\Application::load( $hook->app )->buildHooks();
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
@@ -127,9 +155,17 @@ 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->include = array( 'class' );
|
||||
$table->include = array( 'filename', 'class' );
|
||||
$table->langPrefix = 'plugin_hook_';
|
||||
$table->sortBy = $table->sortBy ?: 'class';
|
||||
|
||||
/* Custom parsers */
|
||||
$table->parsers = array(
|
||||
'filename' => function( $val, $row )
|
||||
{
|
||||
return $val . '.php';
|
||||
}
|
||||
);
|
||||
|
||||
$table->rootButtons = array(
|
||||
'add' => array(
|
||||
@@ -207,6 +243,15 @@ 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' ) )
|
||||
{
|
||||
@opcache_invalidate( \IPS\ROOT_PATH . '/plugins/hooks.php' );
|
||||
}
|
||||
|
||||
/* IPS Cloud Sync */
|
||||
\IPS\IPS::resyncIPSCloud();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -236,13 +281,14 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
public function editForm( $url )
|
||||
{
|
||||
$url = $url->setQueryString( 'tab', NULL )->setQueryString( 'hook', $this->id );
|
||||
|
||||
|
||||
if( !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'system/plugins.css' ) );
|
||||
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'controllers/system' ) );
|
||||
\IPS\Output::i()->title = $this->class;
|
||||
\IPS\Output::i()->breadcrumb[] = array( $url, \IPS\Member::loggedIn()->language()->addToStack('plugin_hooks') );
|
||||
\IPS\Output::i()->breadcrumb[] = array( NULL, $this->filename . '.php' );
|
||||
}
|
||||
|
||||
/* Code Hooks */
|
||||
@@ -256,7 +302,20 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\file_put_contents( $this->getFilename(), $values['code'] );
|
||||
|
||||
/* Write application json file automatically */
|
||||
if( $this->app )
|
||||
{
|
||||
\IPS\Application::load( $this->app )->buildHooks();
|
||||
}
|
||||
|
||||
static::writeDataFile();
|
||||
|
||||
if( isset( \IPS\Request::i()->save_and_reload ) AND !\IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->redirect( \IPS\Request::i()->url(), 'saved' );
|
||||
}
|
||||
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
}
|
||||
|
||||
@@ -278,7 +337,11 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
$parameters = array();
|
||||
foreach ( $method->getParameters() as $parameter )
|
||||
{
|
||||
$parameters[] = ( $parameter->getClass() ? ( '\\' . $parameter->getClass()->getName() . ' ' ) : '' ) . ( $parameter->isPassedByReference() ? '&' : '' ) . '$' . $parameter->name . ( $parameter->isOptional() ? ( '=' . var_export( $parameter->getDefaultValue(), TRUE ) ) : '' );
|
||||
try
|
||||
{
|
||||
$parameters[] = ( $parameter->getClass() ? ( '\\' . $parameter->getClass()->getName() . ' ' ) : '' ) . ( $parameter->isPassedByReference() ? '&' : '' ) . '$' . $parameter->name . ( $parameter->isOptional() ? ( '=' . var_export( $parameter->getDefaultValue(), TRUE ) ) : '' );
|
||||
}
|
||||
catch ( \ReflectionException $e ) {}
|
||||
}
|
||||
|
||||
$method->signature = json_encode( 'function ' . $method->name . '\(' );
|
||||
@@ -288,6 +351,8 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
}
|
||||
$form->addSidebar( \IPS\Theme::i()->getTemplate( 'applications' )->codeHookSidebar( $data ) );
|
||||
|
||||
$form->canSaveAndReload = true;
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'applications' ), 'codeHookEditor' ) );
|
||||
@@ -356,7 +421,8 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
$form->class = 'ipsForm_vertical';
|
||||
$form->attributes['data-controller'] = 'core.admin.system.themeHook';
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_theme_hook_selector', ( $current ? $current['selector'] : NULL ), TRUE, array( 'placeholder' => '#element' ), NULL, NULL, "<a href='#' data-ipsDialog data-ipsDialog-fixed data-ipsDialog-url='" . \IPS\Http\Url::internal( 'app=core&module=applications&controller=plugins&do=templateTree&class=' . urlencode( $this->class ) . "&template=" . urlencode( \IPS\Request::i()->template ) ) . "' data-ipsDialog-title='". \IPS\Member::loggedIn()->language()->addToStack('plugin_theme_hook_select') ."' class='ipsButton ipsButton_light ipsButton_small ipsHide' data-action='showTemplate'>" . \IPS\Member::loggedIn()->language()->addToStack('plugin_theme_hook_select') . "</a>", 'plugin_theme_hook_selector' . $_idSuffix ) );
|
||||
$dialogUrl = \IPS\Http\Url::internal( 'app=core&module=applications&controller=plugins&do=templateTree' )->setQueryString( array( 'class' => $this->class, 'template' => \IPS\Request::i()->template ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_theme_hook_selector', ( $current ? $current['selector'] : NULL ), TRUE, array( 'placeholder' => '#element' ), NULL, NULL, "<a href='#' data-ipsDialog data-ipsDialog-fixed data-ipsDialog-url='" . $dialogUrl . "' data-ipsDialog-title='". \IPS\Member::loggedIn()->language()->addToStack('plugin_theme_hook_select') ."' class='ipsButton ipsButton_light ipsButton_small ipsHide' data-action='showTemplate'>" . \IPS\Member::loggedIn()->language()->addToStack('plugin_theme_hook_select') . "</a>", 'plugin_theme_hook_selector' . $_idSuffix ) );
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'plugin_theme_hook_type', ( $current ? $current['type'] : NULL ), TRUE, array(
|
||||
'options' => array(
|
||||
'add_before' => 'plugin_theme_hook_type_add_before',
|
||||
@@ -436,9 +502,15 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
|
||||
/* Write */
|
||||
$this->_writeThemeHookData( $hookData );
|
||||
|
||||
/* Write application json file automatically */
|
||||
if( $this->app )
|
||||
{
|
||||
\IPS\Application::load( $this->app )->buildHooks();
|
||||
}
|
||||
|
||||
/* Boink */
|
||||
\IPS\Output::i()->redirect( $url->setQueryString( 'template', $template )->setQueryString( 'do', 'editHook' ) );
|
||||
\IPS\Output::i()->redirect( $url->setQueryString( array( 'hookApp' => $this->app, 'hookFilename' => $this->filename, 'template' => $template, 'do' => 'editHook' ) ) );
|
||||
}
|
||||
|
||||
/* Construct tab interface */
|
||||
@@ -471,11 +543,11 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
/* Build */
|
||||
if( !count( $hookData ) )
|
||||
{
|
||||
$hookData = "/* !Hook Data - DO NOT REMOVE */\n\n/* End Hook Data */\n\n";
|
||||
$hookData = "/* !Hook Data - DO NOT REMOVE */\n\n/* End Hook Data */";
|
||||
}
|
||||
else
|
||||
{
|
||||
$hookData = "/* !Hook Data - DO NOT REMOVE */\npublic static function hookData() {\n return array_merge_recursive( " . var_export( $hookData, TRUE ) . ", parent::hookData() );\n}\n/* End Hook Data */\n\n";
|
||||
$hookData = "/* !Hook Data - DO NOT REMOVE */\npublic static function hookData() {\n return array_merge_recursive( " . var_export( $hookData, TRUE ) . ", parent::hookData() );\n}\n/* End Hook Data */";
|
||||
}
|
||||
|
||||
/* Write */
|
||||
@@ -502,7 +574,14 @@ class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function validate( $val )
|
||||
{
|
||||
if ( eval( str_replace( 'extends _HOOK_CLASS_', '', $val ) ) === FALSE )
|
||||
try
|
||||
{
|
||||
if ( eval( str_replace( 'extends _HOOK_CLASS_', '', $val ) ) === FALSE )
|
||||
{
|
||||
throw new \DomainException( 'plugin_hook_code_err_parse' );
|
||||
}
|
||||
}
|
||||
catch ( \ParseError $e )
|
||||
{
|
||||
throw new \DomainException( 'plugin_hook_code_err_parse' );
|
||||
}
|
||||
|
||||
+62
-15
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Plugin Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @since 25 Jul 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
@@ -172,8 +172,8 @@ class _Plugin extends \IPS\Node\Model
|
||||
public function form( &$form )
|
||||
{
|
||||
$form->addHeader( 'plugin_details' );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_name', $this->name, TRUE, array( 'maxLength' => 255 ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_location', $this->location, FALSE, array( 'disabled' => $this->_id ? TRUE : FALSE, 'maxLength' => 32, 'regex' => '/^[a-z0-9]*$/i' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_name', $this->name, TRUE, array( 'maxLength' => 32 ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_location', $this->location, FALSE, array( 'disabled' => $this->_id ? TRUE : FALSE, 'maxLength' => 32, 'regex' => '/^[a-z][a-z0-9]*$/i' ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'plugin_update_check', $this->update_check ) );
|
||||
|
||||
$form->addHeader( 'plugin_author_details' );
|
||||
@@ -221,7 +221,7 @@ CODE;
|
||||
\file_put_contents( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/settings.rename.php", $defaultSettings );
|
||||
\file_put_contents( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/dev/jslang.php", "<?php\n\n\$lang = array(\n\n\n\n);\n" );
|
||||
\file_put_contents( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/dev/lang.php", "<?php\n\n\$lang = array(\n\n\n\n);\n" );
|
||||
\file_put_contents( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/dev/versions.json", json_encode( array( '10000' => '1.0.0' ) ) );
|
||||
\file_put_contents( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/dev/versions.json", json_encode( array() ) );
|
||||
\file_put_contents( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/dev/setup/install.php", preg_replace( '/(<\?php\s)\/*.+?\*\//s', '$1', str_replace(
|
||||
array(
|
||||
'{version_human} Upgrade',
|
||||
@@ -264,6 +264,9 @@ CODE;
|
||||
/* Clear templates to rebuild automatically */
|
||||
\IPS\Theme::deleteCompiledTemplate();
|
||||
|
||||
/* Make all disk template caches stale */
|
||||
\IPS\Theme::resetAllCacheKeys();
|
||||
|
||||
/* Clear javascript map to rebuild automatically */
|
||||
unset( \IPS\Data\Store::i()->javascript_file_map, \IPS\Data\Store::i()->javascript_map );
|
||||
}
|
||||
@@ -367,6 +370,12 @@ CODE;
|
||||
'title' => 'developer_mode',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=applications&controller=plugins&do=developer&id={$this->_id}" ),
|
||||
);
|
||||
|
||||
$buttons['download'] = array(
|
||||
'icon' => 'download',
|
||||
'title' => 'download',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=applications&controller=plugins&do=download&id={$this->_id}" ),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -446,9 +455,12 @@ CODE;
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
\IPS\Theme::removeTemplates( 'core', 'global', 'plugins', $this->id );
|
||||
\IPS\Theme::removeCss( 'core', 'front', 'custom', $this->id );
|
||||
\IPS\Theme::removeResources( 'core', 'global', 'plugins', $this->id );
|
||||
\IPS\Theme::removeTemplates( 'core', 'global', 'plugins', $this->id, TRUE );
|
||||
\IPS\Theme::removeCss( 'core', 'front', 'custom', $this->id, TRUE );
|
||||
\IPS\Theme::removeResources( 'core', 'global', 'plugins', $this->id, TRUE );
|
||||
|
||||
/* Make all disk template caches stale */
|
||||
\IPS\Theme::resetAllCacheKeys();
|
||||
|
||||
/* Get which templates need recompiling */
|
||||
$recompileTemplates = array();
|
||||
@@ -512,6 +524,15 @@ CODE;
|
||||
\IPS\Db::i()->update( 'core_widget_areas', array( 'widgets' => json_encode( $newWidgets ) ), array( 'id=?', $area['id'] ) );
|
||||
}
|
||||
|
||||
/* Call onOtherUninstall so that other applications may perform any necessary cleanup */
|
||||
foreach( \IPS\Application::allExtensions( 'core', 'Uninstall', FALSE ) as $extension )
|
||||
{
|
||||
if( method_exists( $extension, 'onOtherUninstall' ) )
|
||||
{
|
||||
$extension->onOtherUninstall( NULL, $this->id );
|
||||
}
|
||||
}
|
||||
|
||||
unset( \IPS\Data\Store::i()->settings );
|
||||
|
||||
/* Write the data file */
|
||||
@@ -585,12 +606,15 @@ CODE;
|
||||
{
|
||||
$contents = '';
|
||||
|
||||
$depth = 0;
|
||||
$inHereDoc = NULL;
|
||||
$inThemeHooks = FALSE;
|
||||
$depth = 0;
|
||||
$inHereDoc = NULL;
|
||||
$inThemeHooks = FALSE;
|
||||
$inComments = FALSE;
|
||||
|
||||
$fh = fopen( $file, 'r' );
|
||||
while ( $line = fgets( $fh ) )
|
||||
{
|
||||
/* Are we inside a theme hook? */
|
||||
if ( $inThemeHooks )
|
||||
{
|
||||
$inThemeHooks = !( trim( $line ) == '/* End Hook Data */' );
|
||||
@@ -599,11 +623,34 @@ CODE;
|
||||
{
|
||||
$inThemeHooks = ( trim( $line ) == '/* !Hook Data - DO NOT REMOVE */' );
|
||||
}
|
||||
|
||||
if ( !$inThemeHooks )
|
||||
|
||||
/* Are we inside comments? */
|
||||
$skipLastLine = FALSE;
|
||||
if ( $inComments )
|
||||
{
|
||||
$openBraces = mb_substr_count( $line, '{' );
|
||||
$closeBraces = mb_substr_count( $line, '}' );
|
||||
$inComments = !( mb_substr( rtrim( $line ), -2 ) == '*/' );
|
||||
|
||||
if( mb_substr( rtrim( $line ), -2 ) == '*/' )
|
||||
{
|
||||
$skipLastLine = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$inComments = ( mb_substr( ltrim( $line ), 0, 2 ) == '/*' AND mb_substr( rtrim( $line ), -2 ) != '*/');
|
||||
}
|
||||
|
||||
/* If this line is commented out, we should ignore it */
|
||||
if( mb_substr( ltrim( $line ), 0, 2 ) == '//' OR $inComments OR $skipLastLine )
|
||||
{
|
||||
$contents .= $line;
|
||||
}
|
||||
else if ( !$inThemeHooks )
|
||||
{
|
||||
/* Remove anything in quotes as they may contain braces as this confuses the open/close brace count */
|
||||
$bracesCheck = preg_replace( '#([\'"])(?:(?!\1|\\\).|\\\.)+?\1#', '', $line );
|
||||
$openBraces = mb_substr_count( $bracesCheck, '{' );
|
||||
$closeBraces = mb_substr_count( $bracesCheck, '}' );
|
||||
|
||||
$depth += $openBraces;
|
||||
$depth -= $closeBraces;
|
||||
|
||||
Reference in new issue
Block a user