Styles and scripts entered with an absolute reference

More
1 year 2 months ago #18734 by mion
Hi,
I have a problem with using your component in a "reverse proxy" architecture.
In particular, some resources, scripts and style sheets are absolutely referenced.

Eg:
<script src = "www.ca-mura.com/media/com_solidres/asset...uery.validate.min.js" type = "text / javascript">
<script src = "www.ca-mura.com/media/com_solidres/asset...ional-methods.min.js" type = "text / javascript">
<script src = "www.ca-mura.com/media/com_solidres/asset...on/messages_it-IT.js" type = "text / javascript">

This is the code:
lib_solidres\solidres\html\jquery.php
public static function validate()
{
	// Only load once
	if (!empty(static::$loaded[__METHOD__]))
	{
		return;
	}

	JHtml::_('jquery.framework');
	JHtml::_('script', SRURI_MEDIA . '/assets/js/validate/jquery.validate.min.js', false, false);
	JHtml::_('script', SRURI_MEDIA . '/assets/js/validate/additional-methods.min.js', false, false);

	$activeLanguageTag   = JFactory::getLanguage()->getTag();
	$allowedLanguageTags = array('ar-AA', 'bg-BG', 'ca-ES', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'es-AR', 'es-ES', 'et-EE',
		'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hr-HR', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lv-LV', 'nb-NO', 'nl-NL',
		'pl-PL', 'pt-BR', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-TW'
	);

	// English is bundled into the source therefore we don't have to load it.
	if (in_array($activeLanguageTag, $allowedLanguageTags))
	{
		JHtml::_('script', SRURI_MEDIA . '/assets/js/validate/localization/messages_' . $activeLanguageTag . '.js', false, false);
	}

	static::$loaded[__METHOD__] = true;

	return;
}

In other cases, however, a relative address is used correctly.
Eg:
<script src="/media/com_solidres/assets/js/site.min.js?5987b1692662860f8d3241d7d06a8ff8" type="text/javascript"></script>

This is the code:
lib_solidres\solidres\html\js.php
public static function site()
{
	// Only load once
	if (!empty(static::$loaded[__METHOD__]))
	{
		return;
	}

	JHtml::_('script', 'com_solidres/assets/site.min.js', array('version' => SRVersion::getHashVersion(), 'relative' => true));

	static::$loaded[__METHOD__] = true;

	return;
}

Could you change code and use:
public static function validate()
{
	// Only load once
	if (!empty(static::$loaded[__METHOD__]))
	{
		return;
	}
        $options = ['relative' => true, 'path_only' => false, 'detect_browser' => false];

	JHtml::_('jquery.framework');
	JHtml::_('script', SRURI_MEDIA . '/assets/js/validate/jquery.validate.min.js', $options);
	JHtml::_('script', SRURI_MEDIA . '/assets/js/validate/additional-methods.min.js', $options);
	[size=2][/size]
	$activeLanguageTag   = JFactory::getLanguage()->getTag();
	$allowedLanguageTags = array('ar-AA', 'bg-BG', 'ca-ES', 'cs-CZ', 'da-DK', 'de-DE', 'el-GR', 'es-AR', 'es-ES', 'et-EE',
		'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hr-HR', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lv-LV', 'nb-NO', 'nl-NL',
		'pl-PL', 'pt-BR', 'ro-RO', 'ru-RU', 'sk-SK', 'sr-RS', 'sv-SE', 'th-TH', 'tr-TR', 'uk-UA', 'vi-VN', 'zh-CN', 'zh-TW'
	);

	// English is bundled into the source therefore we don't have to load it.
	if (in_array($activeLanguageTag, $allowedLanguageTags))
	{
		JHtml::_('script', SRURI_MEDIA . '/assets/js/validate/localization/messages_' . $activeLanguageTag . '.js', false, false);
	}

	static::$loaded[__METHOD__] = true;

	return;
}

The same $options should also be used wherever the "relative" parameter is not used, eg:

lib_solidres\solidres\html\jquery.php:
public static function editable()
public static function ui()
public static function cookie()
...

Thanks for support

Please Log in or Create an account to join the conversation.

More
1 year 2 months ago #18741 by solidres
Hi,

Yes, we can confirm this issue, some code written long time ago used absolute URL.

We will update them in v2.12.6 (v2.12.5 has been released last weekend).

The correct use should be (no need to use const SRURI_MEDIA)

JHtml::_('script', 'com_solidres/assets/validate/jquery.validate.min.js', $options);

Regards,
The following user(s) said Thank You: joomleb

Please Log in or Create an account to join the conversation.

More
1 year 2 months ago #18742 by mion
Awesome!

Please Log in or Create an account to join the conversation.

Moderators: solidres
Powered by Kunena Forum

All the things you need to make your work easier. Did you like Solidres?