Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

@@ -61,7 +61,7 @@
}
counter++;
}, 1000 );
};
}
/**
* Starts our main loop, which posts messages to the parent frame as needed
@@ -168,12 +168,25 @@
ips.utils.log( e.origin + ' does not equal ' + _origin );
return;
}
if (typeof e.data !== "string") {
return;
}
let pmData;
try {
pmData = JSON.parse(e.data);
if (typeof pmData !== 'object') {
return;
}
} catch (e) {
return; // we don't log here because the message could have come from somewhere else
}
try {
var pmData = JSON.parse( e.data );
var method = pmData.method;
var method = pmData.method;
} catch (err) {
ips.utils.error("iframe: invalid data.");
ips.utils.error(err.message)
return;
}
@@ -183,7 +196,7 @@
} else {
ips.utils.log("Method " + method + " doesn't exist");
}
};
}
ips.utils.contentLoaded( window, function () {
@@ -43,14 +43,6 @@
_initialHeight = ips.utils.getObjHeight( _div );
// Do we have a specified maxWidth here?
var maxWidthElem = document.querySelector('[data-embedInfo-maxSize]');
if( maxWidthElem ){
_embedMaxWidth = maxWidthElem.getAttribute('data-embedInfo-maxSize');
maxWidthElem.style.maxWidth = ( maxWidthElem.getAttribute('data-embedInfo-maxSize').indexOf('%') == -1 ) ? parseInt( _embedMaxWidth ) + "px" : _embedMaxWidth + '%';
}
// Check for any truncated text
var truncated = document.querySelectorAll('[data-truncate]');
@@ -221,6 +213,7 @@
var method = pmData.method;
} catch (err) {
ips.utils.error("iframe: invalid data.");
Debug.error(err.message)
return;
}
+13 -19
View File
@@ -8,12 +8,16 @@
* @since 1 Aug 2013
*/
use IPS\Http\Url;
use IPS\Output;
use IPS\Request;
define('REPORT_EXCEPTIONS', TRUE);
require_once '../../../../init.php';
function loadResource ($url)
{
$response = \IPS\Http\Url::external( $url )->request()->get();
$response = Url::external( $url )->request()->get();
if ( strpos( $response->httpHeaders['Content-Type'], 'javascript' ) !== FALSE )
{
return $response . "\n\n\n\n";
@@ -24,11 +28,11 @@ function loadResource ($url)
}
}
if ( \IPS\Request::i()->src )
if ( Request::i()->src )
{
$output = '';
foreach ( explode( ',', \IPS\Request::i()->src ) as $src )
foreach ( explode( ',', Request::i()->src ) as $src )
{
if ( mb_substr( $src, -3 ) !== '.js' )
{
@@ -54,38 +58,28 @@ if ( \IPS\Request::i()->src )
$output .= file_get_contents( \IPS\ROOT_PATH . '/applications/' . $app . '/interface/' . implode( '/', $exploded ) ) . "\n\n\n\n";
}
}
elseif ( \IPS\IN_DEV && $exploded[0] == 'ckeditor' && $exploded[1] == 'ckeditor.js' )
{
$output .= file_get_contents( \IPS\ROOT_PATH . '/applications/core/dev/ckeditor/ckeditor.js' ) . "\n\n\n\n";
}
else
{
foreach ( \IPS\Output::i()->js( implode( '/', $exploded ), $app, $location ) as $url )
foreach ( Output::i()->js( implode( '/', $exploded ), $app, $location ) as $url )
{
/* If we are in_dev, ckeditor comes from the /dev/ directory instead */
if ( \IPS\IN_DEV && $exploded[0] == 'ckeditor' && $exploded[1] == 'ckeditor.js' )
{
continue;
}
try
{
/* Make sure we have a protocol defined. \IPS\Http\Url::external() does not like protocol relative URL's */
if ( mb_substr( $url, 0, 2 ) == '//' )
{
$url = ( \IPS\Request::i()->isSecure() ) ? 'https:' . $url : 'http:' . $url;
$url = ( Request::i()->isSecure() ) ? 'https:' . $url : 'http:' . $url;
}
$output .= loadResource( $url );
}
catch ( \Exception $e )
catch (Exception $e )
{
\IPS\Output::i()->sendOutput( '', 500, 'text/javascript' );
Output::i()->sendOutput( '', 500, 'text/javascript' );
}
}
}
}
$cacheHeaders = ( \IPS\IN_DEV !== true AND \IPS\Theme::designersModeEnabled() !== true ) ? \IPS\Output::getCacheHeaders( time(), 360 ) : array();
$cacheHeaders = ( \IPS\IN_DEV !== true ) ? Output::getCacheHeaders( time(), 360 ) : array();
\IPS\Output::i()->sendOutput( $output, 200, 'text/javascript', $cacheHeaders );
Output::i()->sendOutput( $output, 200, 'text/javascript', $cacheHeaders );
}
+14 -20
View File
@@ -8,43 +8,37 @@
* @since 18 Feb 2013
*/
use IPS\Application;
use IPS\Db;
use IPS\Lang;
use IPS\Output;
use IPS\Request;
define('REPORT_EXCEPTIONS', TRUE);
require_once '../../../../init.php';
\IPS\Output::setCacheTime( false );
Output::i()->pageCaching = FALSE;
$langId = \intval( \IPS\Request::i()->langId );
$langId = intval( Request::i()->langId );
$_lang = array();
foreach ( \IPS\Db::i()->select( '*', 'core_sys_lang_words', array( 'lang_id=? AND word_js=?', $langId, TRUE ) ) as $row )
foreach ( Db::i()->select( '*', 'core_sys_lang_words', array( 'lang_id=? AND word_js=?', $langId, TRUE ) ) as $row )
{
$_lang[ $row['word_key'] ] = $row['word_custom'] ?: $row['word_default'];
}
if ( \IPS\IN_DEV )
{
foreach ( \IPS\Application::applications() as $app )
foreach ( Application::applications() as $app )
{
if( \IPS\Application::appIsEnabled( $app->directory ) )
if( Application::appIsEnabled( $app->directory ) )
{
if ( file_exists( \IPS\ROOT_PATH . "/applications/{$app->directory}/dev/jslang.php" ) )
{
require \IPS\ROOT_PATH . "/applications/{$app->directory}/dev/jslang.php";
$_lang = array_merge( $_lang, $lang );
}
}
}
foreach ( \IPS\Plugin::plugins() as $plugin )
{
if ( file_exists( \IPS\ROOT_PATH . "/plugins/{$plugin->location}/dev/jslang.php" ) )
{
require \IPS\ROOT_PATH . "/plugins/{$plugin->location}/dev/jslang.php";
$_lang = array_merge( $_lang, $lang );
$_lang = array_merge( $_lang, Lang::readLangFiles( $app->directory, true ) );
}
}
}
$cacheHeaders = ( \IPS\IN_DEV !== true AND \IPS\Theme::designersModeEnabled() !== true ) ? \IPS\Output::getCacheHeaders( time(), 360 ) : array();
$cacheHeaders = ( \IPS\IN_DEV !== true ) ? Output::getCacheHeaders( time(), 360 ) : array();
/* Display */
\IPS\Output::i()->sendOutput( 'ips.setString( ' . json_encode( $_lang ) . ')', 200, 'text/javascript', $cacheHeaders );
Output::i()->sendOutput( 'ips.setString( ' . json_encode( $_lang ) . ')', 200, 'text/javascript', $cacheHeaders );
+67 -20
View File
@@ -194,24 +194,6 @@ self.addEventListener("notificationclick", (e) => {
self.addEventListener("fetch", (e) => {
const { request } = e;
// test the offline page
const offlineResponse = () => {
const response = new Response(OFFLINE_PAGE, {
headers: {
"Content-Type": "text/html",
"Content-Length": OFFLINE_PAGE_SIZE
},
status: 200,
statusText: "OK"
});
return response;
}
// Leaving this in but commented out for now; It could be useful
// if ((new URL(request.url).searchParams.has('forceOfflinePage'))) {
// e.respondWith(offlineResponse());
// }
// We test /admin/ first and then a fallback for the deprecated custom admin directory name feature
if (request.url.startsWith(BASE_URL + "admin/") || e.currentTarget.location.href.match(/type=admin/)) {
log("In ACP, nothing to do...");
@@ -222,16 +204,81 @@ self.addEventListener("fetch", (e) => {
return;
}
// We intercept fetch requests in the following situation:
// We intercept fetch requests in the following situations:
// 1: GET requests where we're offline
// Show a cached offline page instead
// 2: POST requests when we're a guest
// We need to wrap POST requests in an additional call to get the correct csrf token first
// Situation 1: offline GET requests
if (request.mode === "navigate" && request.method === "GET" && !navigator.onLine) {
e.respondWith(
fetch(request).catch((err) => {
return offlineResponse();
return caches.open(CACHE_NAME).then((cache) => {
console.log(`Browser appears to be offline: ${request.url}`);
return cache.match(OFFLINE_URL);
});
})
);
return;
}
let matches = e.currentTarget.location.href.match(/loggedIn=(true|false)/);
const loggedIn = matches[1];
// If we're logged in, we need none of this
if (loggedIn == 'true') {
log("Logged in, nothing to do...");
return;
}
e.respondWith(
new Promise((resolve, reject) => {
log(`On navigation, logged_in is ${loggedIn}`);
// Situation 2: POST requests when we're a guest
if (loggedIn == 'false' && request.method === "POST") {
// Clone current request because we can't use it after reading headers later
const curRequest = request.clone();
log("Intercepting guest post request");
// Grab the path so we can check in PHP if it's an admin URL
let url = new URL(curRequest.url);
let path = url.pathname;
// First get the current csrf key from the server
fetch(`${BASE_URL}index.php?app=core&module=system&controller=ajax&do=getCsrfKey&path=${path}`)
.then((response) => response.json())
.then((response) => {
log(`Got new csrf key: ${response.key}`);
// Create new header object starting with existing headers and adding csrf
const headers = new Headers(curRequest.headers);
headers.set("X-Csrf-Token", response.key);
const newRequest = new Request(curRequest, {
headers,
credentials: curRequest.credentials,
referrer: curRequest.referrer,
});
// Send cloned request
resolve(fetch(newRequest));
})
.catch((err) => {
console.log(err);
reject(err);
});
return;
}
resolve(fetch(request));
}).catch((err) => {
console.log(err);
})
);
});
// ------------------------------------------------