Version 4.5.0

This commit is contained in:
Neo committed 2025-12-19 05:51:58 -08:00
1 parent 1a0c7fd3c2
commit f79dcf067a
3791 files changed
+248032 -76372

No files matched your search

+89 -34
View File
@@ -11,7 +11,7 @@
namespace IPS\Output;
/* 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;
@@ -66,11 +66,11 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
{
$key = md5( $app . '-' . $location . '-' . $path . '-' . $name );
if ( !in_array( $key, static::$foundJsObjects ) )
if ( !\in_array( $key, static::$foundJsObjects ) )
{
$where = array( 'javascript_app=?', 'javascript_location=?', 'javascript_path=?', 'javascript_name=?' );
if ( ! is_string( $app ) )
if ( !\is_string( $app ) )
{
$where[] = 'javascript_plugin=?';
$bindings = array( 'core', 'plugins', '/', $name, $app );
@@ -101,13 +101,13 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
*/
protected function setAppOrPluginProperties()
{
if ( ( $this->app AND ! is_string( $this->app ) ) OR ( $this->plugin ) )
if ( ( $this->app AND !\is_string( $this->app ) ) OR ( $this->plugin ) )
{
$this->app = 'core';
$this->location = 'plugins';
$this->path = '/';
$this->type = 'plugin';
$this->plugin = ( ! is_string( $this->app ) ) ? $this->app : $this->plugin;
$this->plugin = ( !\is_string( $this->app ) ) ? $this->app : $this->plugin;
}
}
@@ -214,10 +214,12 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
/**
* Create an XML document
*
* @param string $app Application
* @return XML Object
* @param string $app Application
* @param array $current Details about current javascript.xml file. Used if $changes is desired to be tracked
* @param array $changes If set, will set details of any changes by reference
* @return object
*/
public static function createXml( $app )
public static function createXml( $app, $current = array(), &$changes = NULL )
{
static::importDev($app);
@@ -243,11 +245,12 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
{
/* Initiate the <template> tag */
$xml->startElement('file');
$attributes = array();
foreach( $js as $k => $v )
{
if ( in_array( \substr( $k, 11 ), array('app', 'location', 'path', 'name', 'type', 'version', 'position' ) ) )
if ( \in_array( \substr( $k, 11 ), array('app', 'location', 'path', 'name', 'type', 'version', 'position' ) ) )
{
$attributes[ $k ] = $v;
$xml->startAttribute( $k );
$xml->text( $v );
$xml->endAttribute();
@@ -266,16 +269,33 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
/* Close the <template> tag */
$xml->endElement();
/* Note it */
$k = "{$attributes['javascript_app']}/{$attributes['javascript_location']}/" . ( trim( $attributes['javascript_path'] ) ? "{$attributes['javascript_path']}/" : '' ) . "{$attributes['javascript_name']}";
if( $changes !== NULL )
{
if ( !isset( $current['files'][ $k ] ) )
{
$changes['files']['added'][] = $k;
}
elseif ( $current['files'][ $k ] != $js['javascript_content'] )
{
$changes['files']['edited'][] = $k;
}
}
unset( $current['files'][ $k ] );
}
if( count( static::$_orders ) )
if( \count( static::$_orders ) )
{
foreach( static::$_orders as $_app => $orderArray )
{
foreach( $orderArray as $order )
{
$xml->startElement('order');
$xml->startAttribute( 'app' );
$xml->text( $_app );
$xml->endAttribute();
@@ -287,6 +307,23 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
$xml->text( $order['contents'] );
$xml->endElement();
/* Note it */
$k = "{$_app}/{$order['path']}";
if( $changes !== NULL )
{
if ( !isset( $current['orders'][ $k ] ) )
{
$changes['orders']['added'][] = $k;
}
elseif ( $current['orders'][ $k ] != $order['contents'] )
{
$changes['orders']['edited'][] = $k;
}
}
unset( $current['orders'][ $k ] );
}
}
}
@@ -294,6 +331,12 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
/* Finish */
$xml->endDocument();
if( $changes !== NULL )
{
$changes['files']['removed'] = array_keys( $current['files'] );
$changes['orders']['removed'] = array_keys( $current['orders'] );
}
return $xml;
}
@@ -695,8 +738,8 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
\IPS\Theme::lock( $flagKey );
$map = ( isset( \IPS\Data\Store::i()->javascript_map ) and is_array( \IPS\Data\Store::i()->javascript_map ) ) ? \IPS\Data\Store::i()->javascript_map : array();
$files = ( isset( \IPS\Data\Store::i()->javascript_file_map ) and is_array( \IPS\Data\Store::i()->javascript_file_map ) ) ? \IPS\Data\Store::i()->javascript_file_map : array();
$map = ( isset( \IPS\Data\Store::i()->javascript_map ) and \is_array( \IPS\Data\Store::i()->javascript_map ) ) ? \IPS\Data\Store::i()->javascript_map : array();
$files = ( isset( \IPS\Data\Store::i()->javascript_file_map ) and \is_array( \IPS\Data\Store::i()->javascript_file_map ) ) ? \IPS\Data\Store::i()->javascript_file_map : array();
if ( $location === null and $file === null )
{
@@ -715,7 +758,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
if ( mb_substr( $file, 0, 8 ) === 'js_lang_' )
{
$langId = intval( mb_substr( $file, 8, -3 ) );
$langId = \intval( mb_substr( $file, 8, -3 ) );
if ( $langId > 0 )
{
@@ -785,10 +828,10 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
foreach ( \IPS\Db::i()->select( '*', 'core_plugins', 'plugin_enabled=1' ) as $row )
{
$ids[] = intval( $row['plugin_id'] );
$ids[] = \intval( $row['plugin_id'] );
}
if ( count( $ids ) )
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;
@@ -852,7 +895,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
}
/* Template only? */
if ( count( $templateOnlyKeys ) AND in_array( $key, $templateOnlyKeys ) )
if ( \count( $templateOnlyKeys ) AND \in_array( $key, $templateOnlyKeys ) )
{
foreach( $templates[ $key ] as $tmpl )
{
@@ -869,9 +912,10 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
}
\IPS\Data\Store::i()->javascript_map = $map;
\IPS\Settings::i()->changeValues( array( 'javascript_updated' => time() ) );
/* As the filename has changed, rebuild the JS map */
if ( ( $app !== 'global' and ( $location === NULL or in_array( $location, array( 'admin', 'front', 'global' ) ) ) ) )
if ( ( $app !== 'global' and ( $location === NULL or \in_array( $location, array( 'admin', 'front', 'global' ) ) ) ) )
{
\IPS\Output\Javascript::compile( 'global', 'root', 'map.js' );
}
@@ -893,14 +937,14 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
protected static function _writeJavascriptFromResultset( $files, $fileName, $app, $location )
{
$content = array();
$jsMap = ( isset( \IPS\Data\Store::i()->javascript_map ) and is_array( \IPS\Data\Store::i()->javascript_map ) ) ? \IPS\Data\Store::i()->javascript_map : array();
$jsMap = ( isset( \IPS\Data\Store::i()->javascript_map ) and \is_array( \IPS\Data\Store::i()->javascript_map ) ) ? \IPS\Data\Store::i()->javascript_map : array();
/* Try and remove any existing files */
try
{
$md5 = md5( $app . '-' . $location . '-' . $fileName );
if ( isset( $jsMap[ $app ] ) and in_array( $md5, array_keys( $jsMap[ $app ] ) ) )
if ( isset( $jsMap[ $app ] ) and \in_array( $md5, array_keys( $jsMap[ $app ] ) ) )
{
\IPS\File::get( 'core_Theme', $jsMap[ $app ][ $md5 ] )->delete();
}
@@ -908,7 +952,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
catch ( \InvalidArgumentException $e ) { }
if ( ! count( $files ) )
if ( ! \count( $files ) )
{
return null;
}
@@ -951,7 +995,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
*/
protected static function _writeJavascript( $content, $fileName, $app, $location )
{
return \IPS\File::create( 'core_Theme', $location . '_' . $fileName, $content, 'javascript_' . $app, TRUE );
return \IPS\File::create( 'core_Theme', $location . '_' . $fileName, $content, 'javascript_' . $app, TRUE, NULL, FALSE );
}
/**
@@ -1024,7 +1068,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
}
}
$json = version_compare( PHP_VERSION, '5.4.0' ) >= 0 ? json_encode( $map, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) : str_replace( '\\/', '/', json_encode( $map ) );
$json = json_encode( $map, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
return 'var ipsJavascriptMap = ' . $json . ';';
}
@@ -1085,7 +1129,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
return array();
}
if ( in_array( $file, \IPS\Output::$globalJavascript ) )
if ( \in_array( $file, \IPS\Output::$globalJavascript ) )
{
$app = 'global';
$location = '/';
@@ -1093,7 +1137,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
if ( mb_substr( $file, 0, 8 ) === 'js_lang_' )
{
return array( \IPS\Http\Url::baseUrl() . "/applications/core/interface/js/jslang.php?langId=" . intval( mb_substr( $file, 8, -3 ) ) );
return array( \IPS\Http\Url::baseUrl() . "/applications/core/interface/js/jslang.php?langId=" . \intval( mb_substr( $file, 8, -3 ) ) );
}
}
@@ -1126,7 +1170,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
{
$return = array();
if ( in_array( $file, \IPS\Output::$globalJavascript ) )
if ( \in_array( $file, \IPS\Output::$globalJavascript ) )
{
return static::_directoryJs( \IPS\ROOT_PATH . "/dev/js/" . mb_substr( $file, 0, -3 ) );
}
@@ -1191,10 +1235,20 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
}
}
$json = version_compare( PHP_VERSION, '5.4.0' ) >= 0 ? json_encode( $files, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) : str_replace( '\\/', '/', json_encode( $files ) );
$json = json_encode( $files, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
return 'var ipsJavascriptMap = ' . $json . ';';
}
/**
* Returns the cache bust key for javascript
*
* @return string
*/
public static function javascriptCacheBustKey()
{
return \IPS\CACHEBUST_KEY . \IPS\Settings::i()->javascript_updated;
}
/**
* Returns the component parts from a URL
*
@@ -1231,7 +1285,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
$models = array();
/* Only include if the app is enabled */
if( !in_array( $app, array_keys( \IPS\Application::enabledApplications() ) ) )
if( !\in_array( $app, array_keys( \IPS\Application::enabledApplications() ) ) )
{
return $models;
}
@@ -1257,6 +1311,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
* @param string $key Controller Key (messages, reports, etc)
* @param string $location Location (front, admin)
* @param string $app Application
* @return array
*/
protected static function _sectionJs( $key, $location, $app )
{
@@ -1314,7 +1369,7 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
}
}
if ( count( $contents ) )
if ( \count( $contents ) )
{
/* Check to see if 'ips.{dir}.js' exists and if so, put that first */
$parentDir = preg_replace( '#^(.*)/([^\/]+?)$#', '\2', $path );
@@ -1363,12 +1418,12 @@ class _Javascript extends \IPS\Patterns\ActiveRecord
}
}
if ( count( $reordered ) )
if ( \count( $reordered ) )
{
/* Add in items not specified in the order */
$diff = array_diff( $return, $reordered );
if ( count( $diff ) )
if ( \count( $diff ) )
{
foreach( $diff as $url )
{