Version 4.0.13.1
This commit is contained in:
1 parent
f9e857d255
commit
c6a86f0d9b
7517 files changed
+597400
-668041
No files matched your search
@@ -0,0 +1,538 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Hook Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 5 Aug 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\Plugin;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook Model
|
||||
*/
|
||||
class _Hook extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_hooks';
|
||||
|
||||
/**
|
||||
* Generate dev table
|
||||
*
|
||||
* @param $url
|
||||
* @param $appOrPluginId
|
||||
* @param $hookDir
|
||||
* @return \IPS\Helpers\Table\Db
|
||||
*/
|
||||
public static function devTable( $url, $appOrPluginId, $hookDir )
|
||||
{
|
||||
switch ( \IPS\Request::i()->hookTable )
|
||||
{
|
||||
/* Create Hook */
|
||||
case 'add':
|
||||
|
||||
/* Get the theme groups */
|
||||
$groups = array();
|
||||
foreach ( \IPS\Theme::load( \IPS\Theme::defaultTheme() )->getRawTemplates( null, null, null, \IPS\Theme::RETURN_ALL_NO_CONTENT ) as $app => $locations )
|
||||
{
|
||||
foreach ( $locations as $location => $_groups )
|
||||
{
|
||||
foreach ( $_groups as $group => $data )
|
||||
{
|
||||
$groups[ $app ][ $app . '_' . $location . '_' . $group ] = "{$location}: {$group}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Build Form */
|
||||
$form = new \IPS\Helpers\Form();
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'plugin_hook_type', NULL, TRUE, array(
|
||||
'options' => array( 'C' => 'plugin_hook_type_c', 'S' => 'plugin_hook_type_s' ),
|
||||
'toggles' => array( 'C' => array( 'plugin_hook_class' ), 'S' => array( 'plugin_hook_group' ) )
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_hook_class', NULL, FALSE, array(), function( $val )
|
||||
{
|
||||
if ( $val and !@class_exists( 'IPS\\' . $val ) )
|
||||
{
|
||||
throw new \DomainException('plugin_hook_class_err');
|
||||
}
|
||||
}, 'IPS\\', NULL, 'plugin_hook_class' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Select( 'plugin_hook_group', NULL, FALSE, array( 'options' => $groups, 'parse' => 'raw' ), NULL, NULL, NULL, 'plugin_hook_group' ) );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_hook_location', NULL, FALSE, array( 'maxLength' => 32, 'regex' => '/^[a-z0-9_]*$/i' ), NULL, NULL, '.php' ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$hook = new static;
|
||||
if ( is_int( $appOrPluginId ) )
|
||||
{
|
||||
$hook->plugin = $appOrPluginId;
|
||||
}
|
||||
else
|
||||
{
|
||||
$hook->app = $appOrPluginId;
|
||||
}
|
||||
$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->save();
|
||||
|
||||
$abstract = '';
|
||||
if ( $values['plugin_hook_type'] == 'C' )
|
||||
{
|
||||
$reflection = new \ReflectionClass( $hook->class );
|
||||
$abstract = $reflection->isAbstract() ? 'abstract ' : '';
|
||||
}
|
||||
|
||||
$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}" );
|
||||
static::writeDataFile();
|
||||
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
}
|
||||
|
||||
/* Display */
|
||||
return $form;
|
||||
|
||||
/* Delete Hook */
|
||||
case 'delete':
|
||||
|
||||
try
|
||||
{
|
||||
$hook = static::load( \IPS\Request::i()->hook )->delete();
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
{
|
||||
\IPS\Output::i()->error( 'node_error', '2C145/7', 404, '' );
|
||||
}
|
||||
|
||||
/* 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->langPrefix = 'plugin_hook_';
|
||||
$table->sortBy = $table->sortBy ?: 'class';
|
||||
|
||||
$table->rootButtons = array(
|
||||
'add' => array(
|
||||
'title' => 'plugin_create_hook',
|
||||
'icon' => 'plus',
|
||||
'link' => $url->setQueryString( 'hookTable', 'add' ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('plugin_create_hook') )
|
||||
)
|
||||
);
|
||||
|
||||
$table->rowButtons = function( $row ) use ( $url )
|
||||
{
|
||||
return array(
|
||||
'edit' => array(
|
||||
'title' => 'edit',
|
||||
'icon' => 'pencil',
|
||||
'link' => $url->setQueryString( 'do', 'editHook' )->setQueryString( 'hook', $row['id'] ),
|
||||
),
|
||||
'delete' => array(
|
||||
'title' => 'delete',
|
||||
'icon' => 'times-circle',
|
||||
'link' => $url->setQueryString( 'hookTable', 'delete' )->setQueryString( 'hook', $row['id'] ),
|
||||
'data' => array( 'delete' => '' )
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
return $table;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function writeDataFile()
|
||||
{
|
||||
if ( \IPS\NO_WRITES )
|
||||
{
|
||||
throw new \RuntimeException; // Everywhere that calls this method should check in advance, but this is here just in case
|
||||
}
|
||||
|
||||
$hooks = array();
|
||||
|
||||
$stmt = \IPS\Db::i()->select(
|
||||
'core_hooks.*, core_plugins.*, core_applications.*',
|
||||
'core_hooks',
|
||||
'core_plugins.plugin_enabled=1 OR core_applications.app_enabled=1',
|
||||
'plugin_order'
|
||||
)->join(
|
||||
'core_plugins',
|
||||
'core_hooks.plugin=core_plugins.plugin_id'
|
||||
)->join(
|
||||
'core_applications',
|
||||
'core_hooks.app=core_applications.app_directory '
|
||||
);
|
||||
|
||||
foreach ( $stmt as $row )
|
||||
{
|
||||
if ( $row['plugin'] )
|
||||
{
|
||||
$hooks[ $row['class'] ][ $row['id'] ] = array(
|
||||
'file' => "plugins/{$row['plugin_location']}/hooks/{$row['filename']}.php",
|
||||
'class' => "hook{$row['id']}",
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$hooks[ $row['class'] ][ $row['id'] ] = array(
|
||||
'file' => "applications/{$row['app']}/hooks/{$row['filename']}.php",
|
||||
'class' => $row['app'] . '_hook_' . $row['filename'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$json = json_encode( $hooks );
|
||||
$encrypted = '';
|
||||
$time = date( 'jny' );
|
||||
for ( $i = 0; $i < \strlen( $json ); $i++ )
|
||||
{
|
||||
$encrypted .= chr( ord( \substr( $json, $i, 1 ) ) + \substr( $time, ( $i % \strlen( $time ) ) - 1, 1 ) );
|
||||
}
|
||||
|
||||
\file_put_contents( \IPS\ROOT_PATH . '/plugins/hooks.txt', $encrypted );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filename
|
||||
*
|
||||
* @return string
|
||||
* @throws |Excepttion
|
||||
*/
|
||||
protected function getFilename()
|
||||
{
|
||||
if ( $this->plugin )
|
||||
{
|
||||
$plugin = \IPS\Plugin::load( $this->plugin );
|
||||
return \IPS\ROOT_PATH . "/plugins/{$plugin->location}/hooks/{$this->filename}.php";
|
||||
}
|
||||
else
|
||||
{
|
||||
return \IPS\ROOT_PATH . "/applications/{$this->app}/hooks/{$this->filename}.php";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit form
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
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') );
|
||||
}
|
||||
|
||||
/* Code Hooks */
|
||||
if ( $this->type === 'C' )
|
||||
{
|
||||
/* 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' ) ) );
|
||||
|
||||
/* Handle submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
\file_put_contents( $this->getFilename(), $values['code'] );
|
||||
static::writeDataFile();
|
||||
\IPS\Output::i()->redirect( $url );
|
||||
}
|
||||
|
||||
/* Create Sidebar */
|
||||
$reflection = new \ReflectionClass( $this->class );
|
||||
$data = array();
|
||||
$defaultProperties = $reflection->getDefaultProperties();
|
||||
foreach ( $reflection->getProperties() as $property )
|
||||
{
|
||||
$property->signature = json_encode( '^\s+?((public|protected|private|static)\s+)+?\$' . $property->name . '(\s+?=.+?)?;\s*$' );
|
||||
$val = $property->name === 'multitons' ? array() : $defaultProperties[ $property->name ]; // It will try to use the current values rather than array()
|
||||
$property->codeToInject = json_encode( "\n\t{$property->getDocComment()}\n\t" . ( $property->isPublic() ? 'public ' : 'protected ' ) . ( $property->isStatic() ? 'static ' : '' ) . '$' . $property->name . ( $defaultProperties[ $property->name ] !== NULL ? ( ' = ' . var_export( $val, TRUE ) ) : '' ) . ";\n" );
|
||||
$data[ $property->getDeclaringClass()->getName() ]['properties'][ $property->getName() ] = $property;
|
||||
}
|
||||
foreach ( $reflection->getMethods() as $method )
|
||||
{
|
||||
if ( !$method->isInternal() )
|
||||
{
|
||||
$parameters = array();
|
||||
foreach ( $method->getParameters() as $parameter )
|
||||
{
|
||||
$parameters[] = ( $parameter->getClass() ? ( '\\' . $parameter->getClass()->getName() . ' ' ) : '' ) . ( $parameter->isPassedByReference() ? '&' : '' ) . '$' . $parameter->name . ( $parameter->isOptional() ? ( '=' . var_export( $parameter->getDefaultValue(), TRUE ) ) : '' );
|
||||
}
|
||||
|
||||
$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" );
|
||||
|
||||
$data[ $method->getDeclaringClass()->getName() ]['methods'][ $method->getName() ] = $method;
|
||||
}
|
||||
}
|
||||
$form->addSidebar( \IPS\Theme::i()->getTemplate( 'applications' )->codeHookSidebar( $data ) );
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'applications' ), 'codeHookEditor' ) );
|
||||
}
|
||||
|
||||
/* Theme Hooks */
|
||||
else
|
||||
{
|
||||
/* Init */
|
||||
$tabbedContent = '';
|
||||
$form = NULL;
|
||||
|
||||
/* Get existing hook data */
|
||||
eval( "namespace IPS;\n\n" . str_replace( array( ' extends _HOOK_CLASS_', 'parent::hookData()' ), array( '', 'array()' ), file_get_contents( $this->getFilename() ) ) );
|
||||
$class = $this->app ? "\IPS\\{$this->app}_hook_{$this->filename}" : "\IPS\hook{$this->id}";
|
||||
$hookData = method_exists( $class, 'hookData' ) ? $class::hookData() : array();
|
||||
|
||||
/* Which template group are we looking at? */
|
||||
$exploded = explode( '_', $this->class );
|
||||
$bits = \IPS\Theme::load( \IPS\Theme::defaultTheme() )->getRawTemplates( $exploded[1], $exploded[2], $exploded[3], \IPS\Theme::RETURN_ALL | \IPS\Theme::RETURN_NATIVE );
|
||||
|
||||
/* If we have selected a template, show the form */
|
||||
if ( \IPS\Request::i()->template )
|
||||
{
|
||||
/* Deleting? */
|
||||
if ( isset( \IPS\Request::i()->delete ) )
|
||||
{
|
||||
unset( $hookData[ \IPS\Request::i()->template ][ \IPS\Request::i()->delete ] );
|
||||
|
||||
if( isset( $hookData[ \IPS\Request::i()->template ] ) AND !count( $hookData[ \IPS\Request::i()->template ] ) )
|
||||
{
|
||||
unset( $hookData[ \IPS\Request::i()->template ] );
|
||||
}
|
||||
|
||||
$this->_writeThemeHookData( $hookData );
|
||||
|
||||
/* Boink */
|
||||
\IPS\Output::i()->redirect( $url->setQueryString( 'template', \IPS\Request::i()->template )->setQueryString( 'do', 'editHook' )->stripQueryString( 'delete' ) );
|
||||
}
|
||||
|
||||
/* Build tabs of created hooks */
|
||||
$tabs = array( 'new' => 'add' );
|
||||
if ( isset( $hookData[ \IPS\Request::i()->template ] ) )
|
||||
{
|
||||
foreach ( $hookData[ \IPS\Request::i()->template ] as $i => $h )
|
||||
{
|
||||
$tabs[ 'sel' . $i ] = $h['selector'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Is this an edit? */
|
||||
$current = NULL;
|
||||
if ( isset( \IPS\Request::i()->tab ) and \IPS\Request::i()->tab != 'new' )
|
||||
{
|
||||
$current = $hookData[ \IPS\Request::i()->template ][ \substr( \IPS\Request::i()->tab, 3 ) ];
|
||||
}
|
||||
|
||||
$_idSuffix = $current ? md5( $current['selector'] ) : '';
|
||||
|
||||
/* Build form for current tab */
|
||||
$activeTab = ( isset( \IPS\Request::i()->tab ) and array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : '__new__';
|
||||
$form = new \IPS\Helpers\Form;
|
||||
if ( $current )
|
||||
{
|
||||
$form->addButton( 'delete', 'link', $url->setQueryString( 'do', 'editHook' )->setQueryString( 'template', \IPS\Request::i()->template )->setQueryString( 'delete', \substr( \IPS\Request::i()->tab, 3 ) ), 'ipsButton ipsButton_alternate' );
|
||||
}
|
||||
$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 ) );
|
||||
$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',
|
||||
'add_inside_start' => 'plugin_theme_hook_type_add_inside_start',
|
||||
'add_inside_end' => 'plugin_theme_hook_type_add_inside_end',
|
||||
'add_after' => 'plugin_theme_hook_type_add_after',
|
||||
'add_class' => 'plugin_theme_hook_type_add_class',
|
||||
'remove_class' => 'plugin_theme_hook_type_remove_class',
|
||||
'add_attribute' => 'plugin_theme_hook_type_add_attribute',
|
||||
'remove_attribute' => 'plugin_theme_hook_type_remove_attribute',
|
||||
'replace' => 'plugin_theme_hook_type_replace',
|
||||
),
|
||||
'toggles' => array(
|
||||
'add_before' => array( 'cm-' . \IPS\Request::i()->template . $_idSuffix ),
|
||||
'add_inside_start' => array( 'cm-' . \IPS\Request::i()->template . $_idSuffix ),
|
||||
'add_inside_end' => array( 'cm-' . \IPS\Request::i()->template . $_idSuffix ),
|
||||
'add_after' => array( 'cm-' . \IPS\Request::i()->template . $_idSuffix ),
|
||||
'add_class' => array( 'plugin_theme_hook_css_class' . $_idSuffix ),
|
||||
'remove_class' => array( 'plugin_theme_hook_css_class' . $_idSuffix ),
|
||||
'add_attribute' => array( 'plugin_theme_hook_attribute_keys' . $_idSuffix ),
|
||||
'remove_attribute' => array( 'plugin_theme_hook_attribute_names' . $_idSuffix ),
|
||||
'replace' => array( 'cm-' . \IPS\Request::i()->template . $_idSuffix ),
|
||||
),
|
||||
), NULL, NULL, NULL, 'plugin_theme_hook_type' . $_idSuffix ) );
|
||||
$options = array();
|
||||
if ( trim( $bits[ $exploded[1] ][ $exploded[2] ][ $exploded[3] ][ \IPS\Request::i()->template ]['template_data'] ) !== '' )
|
||||
{
|
||||
foreach( explode( ',', trim( $bits[ $exploded[1] ][ $exploded[2] ][ $exploded[3] ][ \IPS\Request::i()->template ]['template_data'] ) ) as $tag )
|
||||
{
|
||||
$tag = '{' . trim( preg_replace( '/^(.*)=.*$/', '$1', $tag ) ) . '}';
|
||||
$options['tags'][ $tag ] = $tag;
|
||||
}
|
||||
}
|
||||
$form->add( new \IPS\Helpers\Form\Codemirror( 'plugin_theme_hook_content', ( isset( $current['content'] ) ? $current['content'] : NULL ), NULL, $options, NULL, NULL, NULL, 'cm-' . \IPS\Request::i()->template . $_idSuffix ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'plugin_theme_hook_css_class', ( isset( $current['css_classes'] ) ? $current['css_classes'] : NULL ), NULL, array(), NULL, NULL, NULL, 'plugin_theme_hook_css_class' . $_idSuffix ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'plugin_theme_hook_attribute_keys', ( isset( $current['attributes_add'] ) ? $current['attributes_add'] : NULL ), NULL, array( 'stackFieldType' => 'KeyValue' ), NULL, NULL, NULL, 'plugin_theme_hook_attribute_keys' . $_idSuffix ) );
|
||||
$form->add( new \IPS\Helpers\Form\Stack( 'plugin_theme_hook_attribute_names', ( isset( $current['attributes_remove'] ) ? $current['attributes_remove'] : NULL ), NULL, array(), NULL, NULL, NULL, 'plugin_theme_hook_attribute_names' . $_idSuffix ) );
|
||||
|
||||
/* Handle Submissions */
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$template = \IPS\Request::i()->template;
|
||||
|
||||
/* Add */
|
||||
$save = array(
|
||||
'selector' => $values['plugin_theme_hook_selector'],
|
||||
'type' => $values['plugin_theme_hook_type'],
|
||||
);
|
||||
switch ( $values['plugin_theme_hook_type'] )
|
||||
{
|
||||
case 'add_before':
|
||||
case 'add_inside_start':
|
||||
case 'add_inside_end':
|
||||
case 'add_after':
|
||||
case 'replace':
|
||||
$save['content'] = $values['plugin_theme_hook_content'];
|
||||
break;
|
||||
case 'add_class':
|
||||
case 'remove_class':
|
||||
$save['css_classes'] = $values['plugin_theme_hook_css_class'];
|
||||
break;
|
||||
case 'add_attribute':
|
||||
$save['attributes_add'] = $values['plugin_theme_hook_attribute_keys'];
|
||||
break;
|
||||
case 'remove_attribute':
|
||||
$save['attributes_remove'] = $values['plugin_theme_hook_attribute_names'];
|
||||
break;
|
||||
}
|
||||
if ( isset( \IPS\Request::i()->tab ) and \IPS\Request::i()->tab != 'new' )
|
||||
{
|
||||
$hookData[ $template ][ \substr( \IPS\Request::i()->tab, 3 ) ] = $save;
|
||||
}
|
||||
else
|
||||
{
|
||||
$hookData[ $template ][] = $save;
|
||||
}
|
||||
|
||||
/* Write */
|
||||
$this->_writeThemeHookData( $hookData );
|
||||
|
||||
/* Boink */
|
||||
\IPS\Output::i()->redirect( $url->setQueryString( 'template', $template )->setQueryString( 'do', 'editHook' ) );
|
||||
}
|
||||
|
||||
/* Construct tab interface */
|
||||
if ( \IPS\Request::i()->isAjax() and isset( \IPS\Request::i()->tab ) )
|
||||
{
|
||||
\IPS\Output::i()->output = $form;
|
||||
return;
|
||||
}
|
||||
$tabbedContent = \IPS\Theme::i()->getTemplate( 'global' )->tabs( $tabs, $activeTab, $form, $url->setQueryString( 'do', 'editHook' )->setQueryString( 'template', \IPS\Request::i()->template ) );
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = $tabbedContent;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Display */
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->textBlock( \IPS\Member::loggedIn()->language()->addToStack( 'plugin_hook_info_' . $this->type, FALSE, array( 'sprintf' => array( $this->getFilename() ) ) ), 'info', NULL, FALSE ) . \IPS\Theme::i()->getTemplate( 'applications' )->themeHookEditor( $bits[ $exploded[1] ][ $exploded[2] ][ $exploded[3] ], $hookData, $this->id, \IPS\Request::i()->template, $tabbedContent, $url );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write theme hook data
|
||||
*
|
||||
* @param array $hookData Hook data
|
||||
* @return void
|
||||
*/
|
||||
protected function _writeThemeHookData( $hookData )
|
||||
{
|
||||
/* Build */
|
||||
if( !count( $hookData ) )
|
||||
{
|
||||
$hookData = "/* !Hook Data - DO NOT REMOVE */\n\n/* End Hook Data */\n\n";
|
||||
}
|
||||
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";
|
||||
}
|
||||
|
||||
/* Write */
|
||||
$contents = file_get_contents( $this->getFilename() );
|
||||
if ( \strpos( $contents, '/* !Hook Data - DO NOT REMOVE */' ) !== FALSE )
|
||||
{
|
||||
$contents = preg_replace( '/\/\* !Hook Data - DO NOT REMOVE \*\/.*\/\* End Hook Data \*\//s', $hookData, $contents );
|
||||
}
|
||||
else
|
||||
{
|
||||
$contents = preg_replace( '/(_HOOK_CLASS_\s+{)/', "$1\n\n" . $hookData, $contents );
|
||||
}
|
||||
|
||||
\file_put_contents( $this->getFilename(), $contents );
|
||||
static::writeDataFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate
|
||||
*
|
||||
* @param string $val Code
|
||||
* @return bool
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function validate( $val )
|
||||
{
|
||||
if ( eval( str_replace( 'extends _HOOK_CLASS_', '', $val ) ) === FALSE )
|
||||
{
|
||||
throw new \DomainException( 'plugin_hook_code_err_parse' );
|
||||
}
|
||||
|
||||
$classname = ( $this->plugin ) ? 'hook' . $this->id : $this->app . '_hook_' . $this->filename;
|
||||
if ( !class_exists( $classname , FALSE ) )
|
||||
{
|
||||
throw new \DomainException( \IPS\Member::loggedIn()->language()->addToStack('plugin_hook_code_err_class', FALSE, array( 'sprintf' => array( $classname ) ) ) );
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
parent::delete();
|
||||
@unlink( $this->getFilename() );
|
||||
static::writeDataFile();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,651 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Plugin Model
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @since 25 Jul 2013
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin Model
|
||||
*/
|
||||
class _Plugin extends \IPS\Node\Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons = array();
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_plugins';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'plugin_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'order';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'plugins';
|
||||
|
||||
/**
|
||||
* @brief [Node] Show forms modally?
|
||||
*/
|
||||
public static $modalForms = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Have fetched all?
|
||||
*/
|
||||
protected static $gotAll = FALSE;
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
* @code
|
||||
array(
|
||||
'app' => 'core', // The application key which holds the restrictrions
|
||||
'module' => 'foo', // The module key which holds the restrictions
|
||||
'map' => array( // [Optional] The key for each restriction - can alternatively use "prefix"
|
||||
'add' => 'foo_add',
|
||||
'edit' => 'foo_edit',
|
||||
'permissions' => 'foo_perms',
|
||||
'delete' => 'foo_delete'
|
||||
),
|
||||
'all' => 'foo_manage', // [Optional] The key to use for any restriction not provided in the map (only needed if not providing all 4)
|
||||
'prefix' => 'foo_', // [Optional] Rather than specifying each key in the map, you can specify a prefix, and it will automatically look for restrictions with the key "[prefix]_add/edit/permissions/delete"
|
||||
* @endcode
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
'app' => 'core',
|
||||
'module' => 'applications',
|
||||
'map' => array(
|
||||
'add' => 'plugins_install',
|
||||
'edit' => 'plugins_edit',
|
||||
'permissions' => 'plugins_edit',
|
||||
'delete' => 'plugins_uninstall'
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Get Plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function plugins()
|
||||
{
|
||||
if( self::$gotAll === FALSE )
|
||||
{
|
||||
if ( isset( \IPS\Data\Cache::i()->plugins ) )
|
||||
{
|
||||
$rows = \IPS\Data\Cache::i()->plugins;
|
||||
}
|
||||
else
|
||||
{
|
||||
$rows = iterator_to_array( \IPS\Db::i()->select( '*', 'core_plugins' ) );
|
||||
\IPS\Data\Cache::i()->plugins = $rows;
|
||||
}
|
||||
|
||||
foreach ( $rows as $row )
|
||||
{
|
||||
if ( !isset( self::$multitons[ $row['plugin_id'] ] ) )
|
||||
{
|
||||
self::$multitons[ $row['plugin_id'] ] = static::constructFromData( $row );
|
||||
}
|
||||
}
|
||||
|
||||
self::$gotAll = TRUE;
|
||||
}
|
||||
|
||||
return self::$multitons;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Does the currently logged in user have permission to add aa root node?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function canAddRoot()
|
||||
{
|
||||
return ( \IPS\IN_DEV ) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Does the currently logged in user have permission to add a child node to this node?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canAdd()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Does the currently logged in user have permission to copy this node?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canCopy()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Does the currently logged in user have permission to delete this node?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canDelete()
|
||||
{
|
||||
if( \IPS\NO_WRITES )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::canDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Add/Edit Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
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\Url( 'plugin_update_check', $this->update_check ) );
|
||||
|
||||
$form->addHeader( 'plugin_author_details' );
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_author', $this->author, FALSE, array( 'maxLength' => 255 ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Url( 'plugin_website', $this->website, FALSE, array( 'maxLength' => 255 ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Format form values from add/edit form for save
|
||||
*
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
{
|
||||
if ( !$this->_id AND isset( $values['plugin_location'] ) )
|
||||
{
|
||||
$values['plugin_location'] = $values['plugin_location'] ?: ( 'p' . mb_substr( md5( uniqid() ), 0, 10 ) );
|
||||
|
||||
@\mkdir( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}" );
|
||||
\file_put_contents( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/index.html", '' );
|
||||
@\chmod( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}", \IPS\IPS_FOLDER_PERMISSION );
|
||||
|
||||
$defaultSettings = <<<'CODE'
|
||||
//<?php
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Text( 'plugin_example_setting', \IPS\Settings::i()->plugin_example_setting ) );
|
||||
|
||||
if ( $values = $form->values() )
|
||||
{
|
||||
$form->saveAsSettings();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return $form;
|
||||
CODE;
|
||||
|
||||
foreach ( array( 'hooks', 'dev', 'dev/html', 'dev/css', 'dev/js', 'dev/resources', 'dev/setup' ) as $k )
|
||||
{
|
||||
@\mkdir( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/{$k}" );
|
||||
\file_put_contents( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/hooks/index.html", '' );
|
||||
@\chmod( \IPS\ROOT_PATH . "/plugins/{$values['plugin_location']}/hooks", \IPS\IPS_FOLDER_PERMISSION );
|
||||
}
|
||||
|
||||
\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/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/setup/install.php", preg_replace( '/(<\?php\s)\/*.+?\*\//s', '$1', str_replace(
|
||||
array(
|
||||
'{version_human} Upgrade',
|
||||
'{app}',
|
||||
'upg_{version_long}',
|
||||
'class Upgrade'
|
||||
),
|
||||
array(
|
||||
'Install',
|
||||
'plugins',
|
||||
'install',
|
||||
'class Install'
|
||||
),
|
||||
file_get_contents( \IPS\ROOT_PATH . "/applications/core/data/defaults/UpgradePlugin.txt" )
|
||||
) ) );
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* [ActiveRecord] Save Changed Columns
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$writeDataFile = FALSE;
|
||||
if ( array_key_exists( 'enabled', $this->changed ) )
|
||||
{
|
||||
$writeDataFile = TRUE;
|
||||
}
|
||||
|
||||
parent::save();
|
||||
|
||||
if ( $writeDataFile )
|
||||
{
|
||||
\IPS\Plugin\Hook::writeDataFile();
|
||||
|
||||
/* Clear templates to rebuild automatically */
|
||||
\IPS\Theme::deleteCompiledTemplate();
|
||||
|
||||
/* Clear javascript map to rebuild automatically */
|
||||
unset( \IPS\Data\Store::i()->javascript_file_map, \IPS\Data\Store::i()->javascript_map );
|
||||
}
|
||||
|
||||
unset( \IPS\Data\Cache::i()->plugins );
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get Node Title
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get__title()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get buttons to display in tree
|
||||
* Example code explains return value
|
||||
*
|
||||
* @code
|
||||
array(
|
||||
array(
|
||||
'icon' => array(
|
||||
'icon.png' // Path to icon
|
||||
'core' // Application icon belongs to
|
||||
),
|
||||
'title' => 'foo', // Language key to use for button's title parameter
|
||||
'link' => \IPS\Http\Url::internal( 'app=foo...' ) // URI to link to
|
||||
'class' => 'modalLink' // CSS Class to use on link (Optional)
|
||||
),
|
||||
... // Additional buttons
|
||||
);
|
||||
* @endcode
|
||||
* @param string $url Base URL
|
||||
* @param bool $subnode Is this a subnode?
|
||||
* @return array
|
||||
*/
|
||||
public function getButtons( $url, $subnode=FALSE )
|
||||
{
|
||||
$buttons = array();
|
||||
$defaultButtons = parent::getButtons( $url );
|
||||
|
||||
/* Add a settings button */
|
||||
if ( file_exists( \IPS\ROOT_PATH . '/plugins/' . $this->location . '/settings.php' ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'applications', 'plugins_edit' ) )
|
||||
{
|
||||
$buttons['settings'] = array(
|
||||
'icon' => 'pencil',
|
||||
'title' => 'edit',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=applications&controller=plugins&do=settings&id={$this->_id}" ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => $this->_title, 'ipsDialog-flashMessage' => \IPS\Member::loggedIn()->language()->addToStack('saved') )
|
||||
);
|
||||
}
|
||||
|
||||
/* Upgrade */
|
||||
if( \IPS\Member::loggedIn()->hasAcpRestriction( 'core', 'applications', 'plugins_install' ) )
|
||||
{
|
||||
$buttons['upgrade'] = array(
|
||||
'icon' => 'upload',
|
||||
'title' => 'theme_set_import',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=applications&controller=plugins&do=install&id={$this->_id}" ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('theme_set_import') ),
|
||||
);
|
||||
}
|
||||
|
||||
/* And an uninstall */
|
||||
if( isset( $defaultButtons['delete'] ) )
|
||||
{
|
||||
$buttons['uninstall'] = array(
|
||||
'icon' => 'times-circle',
|
||||
'title' => 'uninstall',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=applications&controller=plugins&do=delete&id={$this->_id}" ),
|
||||
'data' => array( 'delete' => '', 'delete-warning' => \IPS\Member::loggedIn()->language()->addToStack('plugin_uninstall_warning') ),
|
||||
);
|
||||
unset( $defaultButtons['delete'] );
|
||||
}
|
||||
|
||||
/* Add in default ones */
|
||||
$buttons = array_merge( $buttons, $defaultButtons );
|
||||
|
||||
/* Remove edit - it will be in the developer center */
|
||||
if ( isset( $buttons['edit'] ) )
|
||||
{
|
||||
unset( $buttons['edit'] );
|
||||
}
|
||||
|
||||
/* View Details */
|
||||
$buttons['details'] = array(
|
||||
'icon' => 'search',
|
||||
'title' => 'plugin_details',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=applications&controller=plugins&do=details&id={$this->_id}" ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack('plugin_details') )
|
||||
);
|
||||
|
||||
/* Specify developer mode */
|
||||
if( \IPS\IN_DEV )
|
||||
{
|
||||
$buttons['developer'] = array(
|
||||
'icon' => 'cogs',
|
||||
'title' => 'developer_mode',
|
||||
'link' => \IPS\Http\Url::internal( "app=core&module=applications&controller=plugins&do=developer&id={$this->_id}" ),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/* Return */
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the custom badge for each row
|
||||
*
|
||||
* @return NULL|array Null for no badge, or an array of badge data (0 => CSS class type, 1 => language string, 2 => optional raw HTML to show instead of language string)
|
||||
*/
|
||||
public function get__badge()
|
||||
{
|
||||
/* Is there an update to show? */
|
||||
$badge = NULL;
|
||||
|
||||
if( $this->update_check_data )
|
||||
{
|
||||
$data = json_decode( $this->update_check_data, TRUE );
|
||||
if( !empty( $data['longversion'] ) AND $data['longversion'] > $this->version_long )
|
||||
{
|
||||
$released = NULL;
|
||||
|
||||
if( $data['released'] AND intval( $data['released'] ) == $data['released'] AND \strlen( $data['released'] ) == 10 )
|
||||
{
|
||||
$released = (string) \IPS\DateTime::ts( $data['released'] )->localeDate();
|
||||
}
|
||||
else if( $data['released'] )
|
||||
{
|
||||
$released = $data['released'];
|
||||
}
|
||||
|
||||
$badge = array(
|
||||
0 => 'new',
|
||||
1 => '',
|
||||
2 => \IPS\Theme::i()->getTemplate( 'global', 'core' )->updatebadge( $data['version'], $data['updateurl'], $released )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $badge;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Get whether or not this node is enabled
|
||||
*
|
||||
* @note Return value NULL indicates the node cannot be enabled/disabled
|
||||
* @return bool|null
|
||||
*/
|
||||
protected function get__enabled()
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Node] Set whether or not this node is enabled
|
||||
*
|
||||
* @param bool|int $enabled Whether to set it enabled or disabled
|
||||
* @return void
|
||||
*/
|
||||
protected function set__enabled( $enabled )
|
||||
{
|
||||
$this->enabled = $enabled;
|
||||
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'core_theme_css', array( 'css_plugin=?', $this->id ) )->first() )
|
||||
{
|
||||
\IPS\Db::i()->update( 'core_theme_css', array( 'css_hidden' => !$enabled ), array( 'css_plugin=?', $this->id ) );
|
||||
\IPS\Theme::deleteCompiledCss( 'core', 'front', 'custom' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Record
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
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 );
|
||||
|
||||
/* Get which templates need recompiling */
|
||||
$recompileTemplates = array();
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_hooks', array( 'plugin=? AND type=?', $this->id, 'S' ) ) as $hook )
|
||||
{
|
||||
$recompileTemplates[ $hook['class'] ] = $hook['class'];
|
||||
}
|
||||
|
||||
/* Remove the plugin directory */
|
||||
if ( file_exists( \IPS\ROOT_PATH . '/plugins/' . $this->location ) )
|
||||
{
|
||||
if ( file_exists( \IPS\ROOT_PATH . '/plugins/' . $this->location . '/uninstall.php') )
|
||||
{
|
||||
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() )
|
||||
{
|
||||
@rmdir( $file->getPathname() );
|
||||
}
|
||||
else
|
||||
{
|
||||
@unlink( $file->getPathname() );
|
||||
}
|
||||
}
|
||||
$dir = \IPS\ROOT_PATH . '/plugins/' . $this->location;
|
||||
$handle = opendir( $dir );
|
||||
closedir ( $handle );
|
||||
@rmdir( $dir );
|
||||
}
|
||||
|
||||
/* Delete stuff */
|
||||
\IPS\Db::i()->delete( 'core_hooks', array( 'plugin=?', $this->id ) );
|
||||
\IPS\Db::i()->delete( 'core_sys_conf_settings', array( 'conf_plugin=?', $this->id ) );
|
||||
\IPS\Db::i()->delete( 'core_tasks', array( 'plugin=?', $this->id ) );
|
||||
$hasResources = \IPS\Db::i()->delete( 'core_theme_resources', array( 'resource_plugin=?', $this->id ) );
|
||||
$hasCss = \IPS\Db::i()->delete( 'core_theme_css', array( 'css_plugin=?', $this->id ) );
|
||||
$hasTemplates = \IPS\Db::i()->delete( 'core_theme_templates', array( 'template_plugin=?', $this->id ) );
|
||||
$hasJs = \IPS\Db::i()->delete( 'core_javascript', array( 'javascript_plugin=?', $this->id ) );
|
||||
\IPS\Db::i()->delete( 'core_sys_lang_words', array( 'word_plugin=?', $this->id ) );
|
||||
|
||||
/* Remove widgets */
|
||||
\IPS\Db::i()->delete( 'core_widgets', array( 'plugin=?', $this->id ) );
|
||||
|
||||
/* Remove widgets from page configurations */
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_widget_areas' ) as $area )
|
||||
{
|
||||
$widgets = json_decode( $area['widgets'], TRUE );
|
||||
$newWidgets = array();
|
||||
|
||||
foreach ( $widgets as $widget )
|
||||
{
|
||||
if( !isset( $widget['plugin'] ) or $widget['plugin'] != $this->id )
|
||||
{
|
||||
$newWidgets[] = $widget;
|
||||
}
|
||||
}
|
||||
\IPS\Db::i()->update( 'core_widget_areas', array( 'widgets' => json_encode( $newWidgets ) ), array( 'id=?', $area['id'] ) );
|
||||
}
|
||||
|
||||
unset( \IPS\Data\Store::i()->settings );
|
||||
|
||||
/* Write the data file */
|
||||
\IPS\Plugin\Hook::writeDataFile();
|
||||
|
||||
if ( $hasCss )
|
||||
{
|
||||
\IPS\Theme::deleteCompiledCss( 'core', 'front', 'custom' );
|
||||
}
|
||||
|
||||
/* Recompile Templates */
|
||||
foreach ( $recompileTemplates as $k )
|
||||
{
|
||||
$exploded = explode( '_', $k );
|
||||
\IPS\Theme::deleteCompiledTemplate( $exploded[1], $exploded[2], $exploded[3] );
|
||||
}
|
||||
if ( $hasTemplates )
|
||||
{
|
||||
\IPS\Theme::deleteCompiledTemplate( 'core', 'global', 'plugins' );
|
||||
}
|
||||
|
||||
/* Resources */
|
||||
if ( $hasResources )
|
||||
{
|
||||
\IPS\Theme::deleteCompiledResources( 'core', 'global', 'plugins' );
|
||||
}
|
||||
|
||||
/* Clear javascript map to rebuild automatically */
|
||||
if ( $hasJs )
|
||||
{
|
||||
unset( \IPS\Data\Store::i()->javascript_file_map, \IPS\Data\Store::i()->javascript_map );
|
||||
}
|
||||
|
||||
/* Finish */
|
||||
parent::delete();
|
||||
|
||||
unset( \IPS\Data\Cache::i()->plugins );
|
||||
}
|
||||
|
||||
/**
|
||||
* Search
|
||||
*
|
||||
* @param string $column Column to search
|
||||
* @param string $query Search query
|
||||
* @param string|null $order Column to order by
|
||||
* @param mixed $where Where clause
|
||||
* @return array
|
||||
*/
|
||||
public static function search( $column, $query, $order=NULL, $where=array() )
|
||||
{
|
||||
if ( $column === '_title' )
|
||||
{
|
||||
$column = 'plugin_name';
|
||||
}
|
||||
|
||||
if( $order == '_title' )
|
||||
{
|
||||
$order = 'plugin_name';
|
||||
}
|
||||
|
||||
return parent::search( $column, $query, $order, $where );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add try/catch statements to the contents of a hook file for distribution
|
||||
*
|
||||
* @param string $file The location of the hook file on disk
|
||||
* @return string Contents
|
||||
*/
|
||||
public static function addExceptionHandlingToHookFile( $file )
|
||||
{
|
||||
$contents = '';
|
||||
|
||||
$depth = 0;
|
||||
$inHereDoc = NULL;
|
||||
$inThemeHooks = FALSE;
|
||||
$fh = fopen( $file, 'r' );
|
||||
while ( $line = fgets( $fh ) )
|
||||
{
|
||||
if ( $inThemeHooks )
|
||||
{
|
||||
$inThemeHooks = !( trim( $line ) == '/* End Hook Data */' );
|
||||
}
|
||||
else
|
||||
{
|
||||
$inThemeHooks = ( trim( $line ) == '/* !Hook Data - DO NOT REMOVE */' );
|
||||
}
|
||||
|
||||
if ( !$inThemeHooks )
|
||||
{
|
||||
$openBraces = mb_substr_count( $line, '{' );
|
||||
$closeBraces = mb_substr_count( $line, '}' );
|
||||
|
||||
$depth += $openBraces;
|
||||
$depth -= $closeBraces;
|
||||
|
||||
$tabs = str_repeat( "\t", \substr_count( $line, "\t" ) + 1 );
|
||||
|
||||
if ( $depth == 2 and $closeBraces )
|
||||
{
|
||||
$contents .= "{$tabs}}\n{$tabs}catch ( \RuntimeException \$e )\n{$tabs}{\n{$tabs}\tif ( method_exists( get_parent_class(), __FUNCTION__ ) )\n{$tabs}\t{\n{$tabs}\t\treturn call_user_func_array( 'parent::' . __FUNCTION__, func_get_args() );\n{$tabs}\t}\n{$tabs}\telse\n{$tabs}\t{\n{$tabs}\t\tthrow \$e;\n{$tabs}\t}\n{$tabs}}\n";
|
||||
$depth--;
|
||||
}
|
||||
|
||||
if ( !$inHereDoc and $depth > 2 )
|
||||
{
|
||||
$contents .= "\t";
|
||||
}
|
||||
$contents .= $line;
|
||||
|
||||
if ( !$inHereDoc )
|
||||
{
|
||||
if ( preg_match( '/<<<\'?([A-Z][A-Z0-9_]+)\'?$/i', trim( $line ), $matches ) )
|
||||
{
|
||||
$inHereDoc = $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
if ( $depth == 2 and $openBraces )
|
||||
{
|
||||
$contents .= "{$tabs}try\n{$tabs}{\n";
|
||||
$depth++;
|
||||
}
|
||||
|
||||
if ( $inHereDoc and trim( $line ) == $inHereDoc . ';' )
|
||||
{
|
||||
$inHereDoc = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$contents .= $line;
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
}
|
||||
Whitespace-only changes.
Reference in new issue
Block a user