Jump to content

Issue ROOT_PATH and inDevJs


Go to solution Solved by bfarber,

Recommended Posts

	public static function inDevJs( $file, $app=NULL, $location=NULL )
	{
		/* 1: Is this the magic plugin JS */
		if ( $app === 'core' and $location === 'plugins' and $file === 'plugins.js' )
		{
			$return = array();
			
			foreach ( new \GlobIterator( \IPS\ROOT_PATH . '/plugins/*/dev/js/*' ) as $file )
			{
				try
				{
					$plugin = \IPS\Plugin::getPluginFromPath( $file );

					if( $plugin->enabled )
					{
						$url = str_replace( \IPS\ROOT_PATH, rtrim( \IPS\Settings::i()->base_url, '/' ), $file );
						$return[] = str_replace( '\\', '/', $url );
					}
				}
				catch( \OutOfRangeException $e ){}
			}
			
			return $return;
		}
	
		/* 2: Is it a named grouped collection? */
		if ( $app === NULL AND $location === NULL )
		{
			if ( $file === 'map.js' )
			{
				return array();
			}
			
			if ( \in_array( $file, \IPS\Output::$globalJavascript ) )
			{
				$app      = 'global';
				$location = '/';
			}
			
			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 ) ) );
			}
		}
	
		$app      = $app      ?: ( \IPS\Dispatcher::i()->application ? \IPS\Dispatcher::i()->application->directory : NULL );
		$location = $location ?: \IPS\Dispatcher::i()->controllerLocation;
		
		/* 3: App JS? */
		if ( $file == 'app.js' )
		{
			return static::_appJs( $app, $location );
		}
		
		/* 3: Is this a controller/template combo? */
		if ( mb_strstr( $file, '_') AND mb_substr( $file, -3 ) === '.js' )
		{
			list( $location, $key ) = explode( '_',  mb_substr( $file, 0, -3 ) );
			
			if ( ( $location == 'front' OR $location == 'admin' OR $location == 'global' ) AND ! empty( $key ) )
			{ 
				return static::_sectionJs( $key, $location, $app );
			}
		}
		
		/* 4: Is it in the interface directory? */
		if ( $location === 'interface' )
		{
			$path = \IPS\ROOT_PATH . "/applications/{$app}/interface/{$file}";
		}
		else if ( $app === 'global' )
		{
			$return = array();
			
			if ( \in_array( $file, \IPS\Output::$globalJavascript ) )
			{
				return static::_directoryJs( \IPS\ROOT_PATH . "/dev/js/" . mb_substr( $file, 0, -3 ) );
			}
			
			$path = \IPS\ROOT_PATH . "/dev/js";
		}
		else
		{
			$path = \IPS\ROOT_PATH . "/applications/{$app}/dev/js/{$location}/{$file}";
		}
		
		if ( is_dir( $path ) )
		{
			return static::_directoryJs( $path );
		}
		else
		{
			return array( str_replace( \IPS\ROOT_PATH, \IPS\Http\Url::baseUrl(), $path ) );
		}
	}

since my webroot is /app, this method will cause the url for some of my JS to be something like:

//dogwell.codingjungle.test//dogwell.codingjungle.testlications/toolbox/dev/js/front/controllers/profiler/ips.ui.toolbox.lorem.js 

instead of:

//dogwell.codingjungle.test/applications/toolbox/dev/js/front/controllers/profiler/ips.ui.toolbox.lorem.js

 

Link to comment
Share on other sites

Errr - use a different root then?

I mean, do you have a fix that works for you we can take a look at? I'm not really inclined to perform a new installation explicitly in "/app" to test right now, but if you have a suggested fix I'm happy to review it.

Link to comment
Share on other sites

11 minutes ago, bfarber said:

Errr - use a different root then?

I mean, do you have a fix that works for you we can take a look at? I'm not really inclined to perform a new installation explicitly in "/app" to test right now, but if you have a suggested fix I'm happy to review it.

http://sandbox.onlinephpfunctions.com/code/a305c2d09672d5775d2110c9bfc67847185bb63a

3ho6FWh.png

Link to comment
Share on other sites

4 hours ago, bfarber said:

Errr - use a different root then?

I mean, do you have a fix that works for you we can take a look at? I'm not really inclined to perform a new installation explicitly in "/app" to test right now, but if you have a suggested fix I'm happy to review it.

i was using lando, a wrapper for docker. from what i could tell there was no way to change /app to something else, that is why i posted it here. it was easier to use lando to replace mysql/php version than it was try to replace it in my distro (cause of the issues with mysql 8 and php 7.4 that i keep running into).

my only suggested fix, is where ever you use str_replace to turn paths into url's, to implement the count param:

$url = str_replace( \IPS\ROOT_PATH, rtrim( \IPS\Settings::i()->base_url, '/' ), $file );

to

$count = 1;
$url = str_replace( \IPS\ROOT_PATH, rtrim( \IPS\Settings::i()->base_url, '/' ), $file, $count );

 (this is used in several places, i haven't tested it myself. i used a hook on \IPS\Output::sendOutput, to look for dogwell.codingjungle.testlications in the $output param and replace it with applications, but that was a quick and dirty fix, as i would have to adapt it to all my local installations.)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...