Version 4.1.2
This commit is contained in:
1 parent
3ba79295ee
commit
28bd025b35
1131 files changed
+63658
-20579
No files matched your search
@@ -623,6 +623,67 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a compiled JS file
|
||||
*
|
||||
* @param string $app Application
|
||||
* @param string|null $location Location (front, global, etc)
|
||||
* @param string|null $file File to remove
|
||||
* @return boolean|null
|
||||
*/
|
||||
public static function deleteCompiled( $app, $location=null, $file=null )
|
||||
{
|
||||
$map = ( isset( \IPS\Data\Store::i()->javascript_map ) ) ? \IPS\Data\Store::i()->javascript_map : array();
|
||||
$files = ( isset( \IPS\Data\Store::i()->javascript_file_map ) ) ? \IPS\Data\Store::i()->javascript_file_map : array();
|
||||
|
||||
if ( $location === NULL and $file === NULL )
|
||||
{
|
||||
if ( isset( $map[ $app ] ) )
|
||||
{
|
||||
foreach( $map[ $app ] as $hash => $path )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'core_Theme', $path )->delete();
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
}
|
||||
|
||||
$map[ $app ] = array();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( isset( $map[ $app ] ) )
|
||||
{
|
||||
foreach( $map[ $app ] as $hash => $path )
|
||||
{
|
||||
if ( $file === NULL )
|
||||
{
|
||||
$lookFor = 'javascript_' . $app . '/' . $location . '_';
|
||||
}
|
||||
else
|
||||
{
|
||||
$lookFor = 'javascript_' . $app . '/' . $location . '_' . $file;
|
||||
}
|
||||
|
||||
if ( mb_substr( $path, 0, mb_strlen( $lookFor ) ) === $lookFor )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\File::get( 'core_Theme', $path )->delete();
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
|
||||
unset( $map[ $app ][ $hash ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\IPS\Data\Store::i()->javascript_map = $map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles JS into fewer minified files suitable for non IN_DEV use.
|
||||
* Imports the fewer files into a database for writing out.
|
||||
@@ -733,9 +794,18 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
if ( $file === null OR $file === 'plugins.js' )
|
||||
{
|
||||
$obj = static::_writeJavascriptFromResultset( \IPS\Db::i()->select( '*', 'core_javascript', array( 'javascript_app=? AND javascript_location=? AND javascript_type=?', 'core', 'plugins', 'plugin' ), 'javascript_app, javascript_location, javascript_position' )->setKeyField('javascript_id'), 'plugins.js', 'core', 'plugins' );
|
||||
$ids = array();
|
||||
|
||||
$map[ $app ][ md5( 'core-plugins-plugins.js' ) ] = $obj ? (string) $obj : null;
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_plugins', 'plugin_enabled=1' ) as $row )
|
||||
{
|
||||
$ids[] = intval( $row['plugin_id'] );
|
||||
}
|
||||
|
||||
if ( count( $ids ) )
|
||||
{
|
||||
$obj = static::_writeJavascriptFromResultset( \IPS\Db::i()->select( '*', 'core_javascript', array( array( 'javascript_app=? AND javascript_location=? AND javascript_type=? AND javascript_plugin IN(' . implode( ',', array_values( $ids ) ) . ')', 'core', 'plugins', 'plugin' ) ), 'javascript_app, javascript_location, javascript_position' )->setKeyField('javascript_id'), 'plugins.js', 'core', 'plugins' );
|
||||
$map[ $app ][ md5( 'core-plugins-plugins.js' ) ] = $obj ? (string) $obj : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -893,15 +963,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
protected static function _writeJavascript( $content, $fileName, $app, $location )
|
||||
{
|
||||
$header = <<<EOF
|
||||
/**
|
||||
* IPS Social Suite 4
|
||||
* (c) 2013 Invision Power Services - http://www.invisionpower.com
|
||||
* This file contains minified javascript and is not directly editable
|
||||
*/
|
||||
EOF;
|
||||
|
||||
return \IPS\File::create( 'core_Theme', $location . '_' . $fileName, $header . "\n\n" . $content, 'javascript_' . $app, TRUE );
|
||||
return \IPS\File::create( 'core_Theme', $location . '_' . $fileName, $content, 'javascript_' . $app, TRUE );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -980,20 +1042,17 @@ EOF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minifies javascript if IPS created
|
||||
* Minifies javascript
|
||||
*
|
||||
* @param string $js Javascript code
|
||||
* @return string
|
||||
*/
|
||||
protected static function _minify( $js )
|
||||
{
|
||||
require_once( \IPS\ROOT_PATH . '/system/3rd_party/Minify/lib/JSMin.php' );
|
||||
|
||||
if ( mb_stristr( mb_substr( $js, 0, 1000 ), '* IPS Social Suite 4' ) )
|
||||
{
|
||||
$js = \JSMin::minify( $js );
|
||||
}
|
||||
require_once( \IPS\ROOT_PATH . '/system/3rd_party/JShrink/Minifier.php' );
|
||||
|
||||
$js = \JShrink\Minifier::minify( $js, array( 'flaggedComments' => false ) );
|
||||
|
||||
return $js;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user