Adding files and folder from anywhere (not just the custom folder) #231

Closed
opened 2018-02-16 14:57:39 +00:00 by Llewellyn · 42 comments
Owner

I have had the need to often grab files from other places then just the custom folder in JCB, so I would like to add the feature to add any path to a file or folder and be able to include it in any component upon the compilation.

I have had the need to often grab files from other places then just the custom folder in JCB, so I would like to add the feature to add any path to a file or folder and be able to include it in any component upon the compilation.
Author
Owner

Basically by just extending the Component Files & Folders concept, to have a basic (the old way) and advanced (the new way) tab with the related features to include files and folders.

Basically by just extending the **Component Files & Folders** concept, to have a **basic** (the old way) and **advanced** (the new way) tab with the related features to include files and folders.
fred-the-coder commented 2018-11-19 08:33:39 +00:00 (Migrated from github.com)
Author
Owner

I am afraid this feature is not working in Windows environment.
Indeed when using an absolute path as "F:\www\joom3..." as custom files or folders, I have an error at compilation time like "'The folder path: /F:\www\joom3... does not exist, and was not added!"

Maybe I have to use a different path syntax?

Thank you

I am afraid this feature is not working in Windows environment. Indeed when using an absolute path as "F:\www\joom3\..." as custom files or folders, I have an error at compilation time like "'The folder path: /F:\www\joom3\... does not exist, and was not added!" Maybe I have to use a different path syntax? Thank you
pdward commented 2019-01-23 16:09:14 +00:00 (Migrated from github.com)
Author
Owner

Unfortunately this issue is still ongoing in a Windows environment. Currently still testing solutions - apart from changing to linux ;)

Unfortunately this issue is still ongoing in a Windows environment. Currently still testing solutions - apart from changing to linux ;)
Author
Owner

Okay I will open this up again ,and lets see how we can resolve this...

Okay I will open this up again ,and lets see how we can resolve this...
Author
Owner

@peterpetrov Just please note these few comments as we start this:

http://us2.php.net/manual/en/ref.filesystem.php#73954
https://alanhogan.com/tips/php/directory-separator-not-necessary
https://dev.to/c33s/always-use--as-directory-seperator-in-php-43l7

This is why JCB only use the '/' everywhere as I learned the PHP on both systems resolves this correctly. Yet when I see the F:\www\joom3... or the C:\wamp64\www\kindredreadersdev\media\com_kr_books_books\images\authorpen I realize the drive name is what causes the problem, but is also what we can use to detect that the user is adding a path as a windows path.

Since @pdward correctly noted on the forum that the "bug" is in the b_Structure.php file on line Line 1376 where we insure a full path as understood on Linux is used. If we detect a : in the path (we know it is a Windows path, or am I wrong) I can leave off the Unix fix and let the path remain as set by the user, will that resolve the issue.

So there is two places to update, please try these fixes:

Line 1376

if (strpos($custom['filepath'], ':') === false)
{
	$custom['file'] = '/' . trim($custom['filepath'], '/');
}
else
{
	$custom['file'] = $custom['filepath'];
}

Line 1300

if (strpos($custom['folderpath'], ':') === false)
{
	$custom['folder'] = '/' . trim($custom['folderpath'], '/');
}
else
{
	$custom['folder'] = $custom['folderpath'];
}

This will be the first step in resolving this issue, but let see... like I said before, I don't know Windows that well, so if there is a better way to detect that it is a windows path... please tell me. The idea to use this instead was also on my mind:

if (strpos($custom['folderpath'], '\') === false)
{
@peterpetrov Just please note these few comments as we start this: http://us2.php.net/manual/en/ref.filesystem.php#73954 https://alanhogan.com/tips/php/directory-separator-not-necessary https://dev.to/c33s/always-use--as-directory-seperator-in-php-43l7 This is why JCB only use the '/' everywhere as I learned the PHP on both systems resolves this correctly. Yet when I see the `F:\www\joom3...` or the `C:\wamp64\www\kindredreadersdev\media\com_kr_books_books\images\authorpen` I realize the drive name is what causes the problem, but is also what we can use to detect that the user is adding a path as a windows path. Since @pdward correctly noted on the forum that the "bug" is in the [b_Structure.php](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php) file on line Line [1376](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L1376) where we insure a full path as understood on Linux is used. If we detect a `:` in the path (we know it is a Windows path, or am I wrong) I can leave off the Unix fix and let the path remain as set by the user, will that resolve the issue. So there is two places to update, please try these fixes: Line [1376](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L1376) ```php if (strpos($custom['filepath'], ':') === false) { $custom['file'] = '/' . trim($custom['filepath'], '/'); } else { $custom['file'] = $custom['filepath']; } ``` Line [1300](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L1300) ```php if (strpos($custom['folderpath'], ':') === false) { $custom['folder'] = '/' . trim($custom['folderpath'], '/'); } else { $custom['folder'] = $custom['folderpath']; } ``` This will be the first step in resolving this issue, but let see... like I said before, I don't know Windows that well, so if there is a better way to detect that it is a windows path... please tell me. The idea to use this instead was also on my mind: ```php if (strpos($custom['folderpath'], '\') === false) { ```
Author
Owner

There are more places to change, and we will get to those, yet these first two are the most problematic once.

There are more places to change, and we will get to those, yet these first two are the most problematic once.
peterpetrov commented 2019-01-23 20:23:37 +00:00 (Migrated from github.com)
Author
Owner

I am going to install windows machine to be able to test all that. Also i think we should be using php to determine if it is running on windows or not. Something like that:

if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
whatever_we_need();
}

I am going to install windows machine to be able to test all that. Also i think we should be using php to determine if it is running on windows or not. Something like that: if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { whatever_we_need(); }
peterpetrov commented 2019-01-23 20:27:53 +00:00 (Migrated from github.com)
Author
Owner

The problem i forsee here is how people are using joomla on windows so i can replicate it. I am going to install IIS + PHP and WAMP on the other hand. If anyone has different setup please share it so i can make a test environment.

The problem i forsee here is how people are using joomla on windows so i can replicate it. I am going to install IIS + PHP and WAMP on the other hand. If anyone has different setup please share it so i can make a test environment.
Author
Owner

The reason I did not go for that was since the normal \pat\to\file/name.php will still work when targeting a file in the custom folder or the Joomla root. So no need to know the environment one every case, just where the drive is also mentioned, as a full path. That is why I asked you to read the comments of those links, as they leave the idea that you only in some cases need to bend backward to catch the path variations. Tell me if I am wrong, but if we start with strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' we are going to seriously have to change many aspects of the JCB structure builder. But if we only target the breaking points, the change will be minor and still work.

The reason I did not go for that was since the normal `\pat\to\file/name.php` will still work when targeting a file in the custom folder or the Joomla root. So no need to know the environment one every case, just where the drive is also mentioned, as a full path. That is why I asked you to read the comments of those links, as they leave the idea that you only in some cases need to bend backward to catch the path variations. Tell me if I am wrong, but if we start with `strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'` we are going to seriously have to change many aspects of the JCB structure builder. But if we only target the breaking points, the change will be minor and still work.
fred-the-coder commented 2019-01-23 20:30:29 +00:00 (Migrated from github.com)
Author
Owner

@peterpetrov thank you for taking care....
Even redhat is now available on windows!!!
On windows, you can use EasyPhp https://www.easyphp.org/. It's coming with Apache, MySql and a PHP...

@peterpetrov thank you for taking care.... Even redhat is now available on windows!!! On windows, you can use EasyPhp https://www.easyphp.org/. It's coming with Apache, MySql and a PHP...
Author
Owner

My thoughts are we are come to the code with strings place into the JCB GUI, and those string could be Linux based, and still run on Windows. This because we have JCB packages with those values moving between developers on various environments, so Just asking on what system are we, without actually looking at the string (path) is not ideal.

My thoughts are we are come to the code with strings place into the JCB GUI, and those string could be Linux based, and still run on Windows. This because we have JCB packages with those values moving between developers on various environments, so Just asking on what system are we, without actually looking at the string (path) is not ideal.
Author
Owner

I for one would recommend using Joomla file paths as the one to deal with the root path, so like for example if we have a file at:

C:\wamp64\www\kindredreadersdev\media\com_kr_books_books\images\authorpen

The the correct way to add it to the GUI is:

JPATH_ROOT/media/com_kr_books_books/images/authorpen

This should then just work on Windows and Linux. This is best practice and this should already work according to my understanding.

@cpaschen can you test the above if it is true? or anyone else?

I for one would recommend using Joomla file paths as the one to deal with the root path, so like for example if we have a file at: ``` C:\wamp64\www\kindredreadersdev\media\com_kr_books_books\images\authorpen ``` The the correct way to add it to the GUI is: ``` JPATH_ROOT/media/com_kr_books_books/images/authorpen ``` This should then just work on Windows and Linux. This is best practice and this should already work according to my understanding. @cpaschen can you test the above if it is true? or anyone else?
peterpetrov commented 2019-01-23 20:40:22 +00:00 (Migrated from github.com)
Author
Owner

Yep, actually i agree on that last comment. I am setting it up now and will test it as well.

Yep, actually i agree on that last comment. I am setting it up now and will test it as well.
fred-the-coder commented 2019-01-23 20:44:28 +00:00 (Migrated from github.com)
Author
Owner

There should be a php PATH function, getting rid of this...It should be in Joomla actually?
Having a quick look to JPath class:

/**
	 * Searches the directory paths for a given file.
	 *
	 * @param   mixed   $paths  An path string or array of path strings to search in
	 * @param   string  $file   The file name to look for.
	 *
	 * @return  mixed   The full path and file name for the target file, or boolean false if the file is not found in any of the paths.
	 *
	 * @since   11.1
	 */
	public static function find($paths, $file)
	{
		// Force to array
		if (!is_array($paths) && !($paths instanceof Iterator))
		{
			settype($paths, 'array');
		}

		// Start looping through the path set
		foreach ($paths as $path)
		{
			// Get the path to the file
			$fullname = $path . '/' . $file;

			// Is the path based on a stream?
			if (strpos($path, '://') === false)
			{
				// Not a stream, so do a realpath() to avoid directory
				// traversal attempts on the local file system.

				// Needed for substr() later
				$path = realpath($path);
				$fullname = realpath($fullname);
			}

			/*
			 * The substr() check added to make sure that the realpath()
			 * results in a directory registered so that
			 * non-registered directories are not accessible via directory
			 * traversal attempts.
			 */
			if (file_exists($fullname) && substr($fullname, 0, strlen($path)) == $path)
			{
				return $fullname;
			}
		}

		// Could not find the file in the set of paths
		return false;
	}

Hope it helps...

There should be a php PATH function, getting rid of this...It should be in Joomla actually? Having a quick look to JPath class: ``` /** * Searches the directory paths for a given file. * * @param mixed $paths An path string or array of path strings to search in * @param string $file The file name to look for. * * @return mixed The full path and file name for the target file, or boolean false if the file is not found in any of the paths. * * @since 11.1 */ public static function find($paths, $file) { // Force to array if (!is_array($paths) && !($paths instanceof Iterator)) { settype($paths, 'array'); } // Start looping through the path set foreach ($paths as $path) { // Get the path to the file $fullname = $path . '/' . $file; // Is the path based on a stream? if (strpos($path, '://') === false) { // Not a stream, so do a realpath() to avoid directory // traversal attempts on the local file system. // Needed for substr() later $path = realpath($path); $fullname = realpath($fullname); } /* * The substr() check added to make sure that the realpath() * results in a directory registered so that * non-registered directories are not accessible via directory * traversal attempts. */ if (file_exists($fullname) && substr($fullname, 0, strlen($path)) == $path) { return $fullname; } } // Could not find the file in the set of paths return false; } ``` Hope it helps...
mwweb commented 2019-01-23 22:16:10 +00:00 (Migrated from github.com)
Author
Owner

Honestly, I've tried using JCB on Windows, and although it would work 95% of the time, there were some things that just didn't function right, and it was mainly during compile.

I've tried WAMP, XAMPP, even Windows Subsystem for Linux (WSL) using Ubuntu.

I think the biggest issue that I saw was with saving of files. Linux and Windows are so very different, and regardless of whether you use WAMP, XAMPP, WSL, or other configuration, files are still saved to the Windows file system, which is where I saw the issues.

The only solution that I found that has, so far, worked "flawlessly" is Vagrant. There is something with the Vagrant system in the communication with the "box" running in VirtualBox that processes everything fine. https://www.joomlatools.com/developer/tools/vagrant/

Speed-wise, WSL was phenomenal.

Honestly, I've tried using JCB on Windows, and although it would work 95% of the time, there were some things that just didn't function right, and it was mainly during compile. I've tried WAMP, XAMPP, even Windows Subsystem for Linux (WSL) using Ubuntu. I think the biggest issue that I saw was with saving of files. Linux and Windows are so very different, and regardless of whether you use WAMP, XAMPP, WSL, or other configuration, files are still saved to the Windows file system, which is where I saw the issues. The only solution that I found that has, so far, worked "flawlessly" is Vagrant. There is something with the Vagrant system in the communication with the "box" running in VirtualBox that processes everything fine. [https://www.joomlatools.com/developer/tools/vagrant/](url) Speed-wise, WSL was phenomenal.
pdward commented 2019-01-24 10:39:18 +00:00 (Migrated from github.com)
Author
Owner

The following has worked for me (Windows - Bitnami wampstack-7.1.24-00) for adding custom files (not tried folders yet)

b_Structure.phpafter Line 835 $zipFullPath = str_replace('//', '/', $zipPath . '/' . $new);

if(isset($details->custom) && $details->custom == 'full') { $currentFullPath = ltrim($currentFullPath, '/'); $packageFullPath = str_replace('//', '/', $path . '/' . basename($details->newName)); }

The following has worked for me (Windows - Bitnami wampstack-7.1.24-00) for adding custom files (not tried folders yet) b_Structure.phpafter Line 835 _$zipFullPath = str_replace('//', '/', $zipPath . '/' . $new);_ ` if(isset($details->custom) && $details->custom == 'full') { $currentFullPath = ltrim($currentFullPath, '/'); $packageFullPath = str_replace('//', '/', $path . '/' . basename($details->newName)); }`
pdward commented 2019-01-24 11:52:43 +00:00 (Migrated from github.com)
Author
Owner

This is the output of dumping the $details array and the resulting $currentFullPath, $packageFullPath and $zipFullPath in b_Structure.php->setStatic() at line 835 for some of files already included in component compile:

stdClass Object
(
[naam] => headercheck_admin.php
[path] => c0mp0n3nt/admin/helpers
[rename] => new
[newName] => headercheck.php
[type] => file
)

$currentFullPath: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/joomla_3/headercheck_admin.php
$packageFullPath: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/com_SwapDoc_v0_0_18__J3/admin/helpers/headercheck.php
$zipFullPath: admin/helpers/headercheck.php

stdClass Object
(
[naam] => headercheck.php
[path] => c0mp0n3nt/site/helpers
[rename] =>
[type] => file
)

$currentFullPath: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/joomla_3/headercheck.php
$packageFullPath: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/com_SwapDoc_v0_0_18__J3/site/helpers/headercheck.php
$zipFullPath: site/helpers/headercheck.php

This is the output of dumping the $details array and the resulting $currentFullPath, $packageFullPath and $zipFullPath in b_Structure.php->setStatic() at line 835 for some of files already included in component compile: stdClass Object ( [naam] => headercheck_admin.php [path] => c0mp0n3nt/admin/helpers [rename] => new [newName] => headercheck.php [type] => file ) **$currentFullPath**: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/joomla_3/headercheck_admin.php **$packageFullPath**: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/com_SwapDoc_v0_0_18__J3/admin/helpers/headercheck.php **$zipFullPath**: admin/helpers/headercheck.php stdClass Object ( [naam] => headercheck.php [path] => c0mp0n3nt/site/helpers [rename] => [type] => file ) **$currentFullPath**: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/joomla_3/headercheck.php **$packageFullPath**: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/com_SwapDoc_v0_0_18__J3/site/helpers/headercheck.php **$zipFullPath**: site/helpers/headercheck.php
pdward commented 2019-01-24 11:56:13 +00:00 (Migrated from github.com)
Author
Owner

The same for an Advance Adding Files (File Path: JPATH_ROOT\components\com_swapdoc\views\shift\tmpl\modal.php, Target Path: /site/views/shift/tmpl) which causes errors in File::exists($currentFullPath) and $packageFullPath0nly = str_replace(basename($packageFullPath), '', $packageFullPath); further down the function.

stdClass Object
(
[naam] => /C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php
[path] => c0mp0n3nt/site/views/shift/tmpl
[rename] => new
[newName] => C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php
[type] => file
[custom] => full
)

$currentFullPath: /C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php
$packageFullPath: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/com_SwapDoc_v0_0_18__J3/site/views/shift/tmpl/C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php
$zipFullPath: site/views/shift/tmpl/C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php

The same for an Advance Adding Files (_File Path: JPATH_ROOT\components\com_swapdoc\views\shift\tmpl\modal.php, Target Path: /site/views/shift/tmpl_) which causes errors in _File::exists($currentFullPath)_ and _$packageFullPath0nly = str_replace(basename($packageFullPath), '', $packageFullPath);_ further down the function. stdClass Object ( [naam] => /C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php [path] => c0mp0n3nt/site/views/shift/tmpl [rename] => new [newName] => C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php [type] => file [custom] => full ) **$currentFullPath**: /C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php **$packageFullPath**: C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\administrator/components/com_componentbuilder/compiler/com_SwapDoc_v0_0_18__J3/site/views/shift/tmpl/C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php **$zipFullPath**: site/views/shift/tmpl/C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs\components\com_swapdoc\views\shift\tmpl\modal.php
pdward commented 2019-01-24 11:59:25 +00:00 (Migrated from github.com)
Author
Owner

Note this is without the fixes proposed by myself or @Llewellynvdm earlier

Note this is without the fixes proposed by myself or @Llewellynvdm earlier
Author
Owner

I must say I am sorry I did not realize sooner that the Windows guys are not able to see JCB in action... but I am sure we can improve this dramatically, it is not that major really.

Please keep sending more ideas and feedback on this topic.

I must say I am sorry I did not realize sooner that the Windows guys are not able to see JCB in action... but I am sure we can improve this dramatically, it is not that major really. Please keep sending more ideas and feedback on this topic.
peterpetrov commented 2019-01-24 20:09:20 +00:00 (Migrated from github.com)
Author
Owner

I have to apologize I was unable to do any tests for the last day. I am about to use another machine which runs on Windows. My virtual options are not great at the moment as my hosting provider couldn’t run properly windows server. I will get back to you later tomorrow I hope.

Peter

From: "((ewe))yn" notifications@github.com
Reply-To: vdm-io/Joomla-Component-Builder reply@reply.github.com
Date: 24, January,Thursday -2019, 22:07
To: vdm-io/Joomla-Component-Builder Joomla-Component-Builder@noreply.github.com
Cc: Peter Petrov ppetrov@taktix.eu, Mention mention@noreply.github.com
Subject: Re: [vdm-io/Joomla-Component-Builder] Adding files and folder from anywhere (not just the custom folder) (#231)

I must say I am sorry I did not realize sooner that the Windows guys are not able to see JCB in action... but I am sure we can improve this dramatically, it is not that major really.

Please keep sending more ideas and feedback on this topic.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com/vdm-io/Joomla-Component-Builder/issues/231#issuecomment-457338052, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACqF-jva6mLbzHzQ1Amo2uBEjQdI05pJks5vGhJkgaJpZM4SIcyc.

I have to apologize I was unable to do any tests for the last day. I am about to use another machine which runs on Windows. My virtual options are not great at the moment as my hosting provider couldn’t run properly windows server. I will get back to you later tomorrow I hope. Peter From: "((ewe))yn" <notifications@github.com> Reply-To: vdm-io/Joomla-Component-Builder <reply@reply.github.com> Date: 24, January,Thursday -2019, 22:07 To: vdm-io/Joomla-Component-Builder <Joomla-Component-Builder@noreply.github.com> Cc: Peter Petrov <ppetrov@taktix.eu>, Mention <mention@noreply.github.com> Subject: Re: [vdm-io/Joomla-Component-Builder] Adding files and folder from anywhere (not just the custom folder) (#231) I must say I am sorry I did not realize sooner that the Windows guys are not able to see JCB in action... but I am sure we can improve this dramatically, it is not that major really. Please keep sending more ideas and feedback on this topic. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub<https://github.com/vdm-io/Joomla-Component-Builder/issues/231#issuecomment-457338052>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ACqF-jva6mLbzHzQ1Amo2uBEjQdI05pJks5vGhJkgaJpZM4SIcyc>.
Author
Owner

I understand completely, thanks!

I understand completely, thanks!
ro-ot commented 2019-01-27 17:45:07 +00:00 (Migrated from github.com)
Author
Owner

I agree with @mwweb stop trying to fix things that are not broken. Instead use the tools that fixes Windows! they are what is broken.

I agree with @mwweb stop trying to fix things that are not broken. Instead use the tools that fixes Windows! they are what is broken.
Author
Owner

I can only smile at that... but I would like to still improve JCB to work on both. I know this will add extra load, but trust it will not be to much. We can try and move it all into one function. I will try to be as discreet as I can to avoid messing with the core flow. This cleanup will just do us all good in the long run, since little refactoring never hurt anyone.

I can only smile at that... but I would like to still improve JCB to work on both. I know this will add extra load, but trust it will not be to much. We can try and move it all into one function. I will try to be as discreet as I can to avoid messing with the core flow. This cleanup will just do us all good in the long run, since little refactoring never hurt anyone.
pjdevries commented 2019-03-12 14:06:59 +00:00 (Migrated from github.com)
Author
Owner

These are my thoughts:

First of all I believe Llewell thinks in the right direction by checking the filename for Windowness. If it were up to me, I would not simply check for the occurrence of a ':' though. A ':' is sort of a reserved character for uri's in general. Since we don't know what JCB has in store for us, I don't think it's wise to check for the occurence of a single character. However, we do know that a drive letter always consists of a single letter followed by a colon. We also know these are always the first two characters of the filename. So a preg_match('/^[a-z]:/i', $path) would do the trick.

Secondly I would definitely implement filename handling in a dedicated class within a general purpose library. All file and folder name manipulation within JCB should then go through standard methods to always return a normalized version of the file or folder name for a specific situation.

P.S. I am using Linux from before it was even called Linux but Unix and Windows almost from day one. Both have their pro's and cons. So does MacOS. It's a bit unfortunate that discussions about incompatibilities get contaminated with useless discussions about which OS is the best or flawed the most. Not very productive :(

These are my thoughts: First of all I believe Llewell thinks in the right direction by checking the filename for Windowness. If it were up to me, I would not simply check for the occurrence of a ':' though. A ':' is sort of a reserved character for uri's in general. Since we don't know what JCB has in store for us, I don't think it's wise to check for the occurence of a single character. However, we do know that a drive letter always consists of a single letter followed by a colon. We also know these are always the first two characters of the filename. So a `preg_match('/^[a-z]:/i', $path)` would do the trick. Secondly I would definitely implement filename handling in a dedicated class within a general purpose library. All file and folder name manipulation within JCB should then go through standard methods to always return a normalized version of the file or folder name for a specific situation. P.S. I am using Linux from before it was even called Linux but Unix and Windows almost from day one. Both have their pro's and cons. So does MacOS. It's a bit unfortunate that discussions about incompatibilities get contaminated with useless discussions about which OS is the best or flawed the most. Not very productive :(
Author
Owner

@pdward can you run some test, with the latest changes I made to fix this issue?

@pdward can you run some test, with the latest changes I made to fix this issue?
Author
Owner

I don't have a MS box, so hard to see if this resolves the issue. I need some to test this, as I think we should be in the clear for the most part.

I don't have a MS box, so hard to see if this resolves the issue. I need some to test this, as I think we should be in the clear for the most part.
pjdevries commented 2019-03-12 20:07:58 +00:00 (Migrated from github.com)
Author
Owner

I see that you do yet another translation of backward slashes into forward slashes in the new ComponentbuilderHelper::fixPath() methode. My findings are that the slashes are not the culprit but the drive letter is. You did not take that into account. Why is that?

I also found that the code around line 831 needs to be fixed in order for it to work with Windows drive letters.

I see that you do yet another translation of backward slashes into forward slashes in the new `ComponentbuilderHelper::fixPath()` methode. My findings are that the slashes are not the culprit but the drive letter is. You did not take that into account. Why is that? I also found that the code around line 831 needs to be fixed in order for it to work with Windows drive letters.
Author
Owner

Okay the changes I made was to remove lines that added a / in front of the drive like mentioned here:

/C:\path\to\where_ever

So that it will now look like this:

C:/path/to/where_ever

I did this to insure that scripts that target the / will behave correctly.

So my question is have you test the last changes, and does it still give issues, and can you explain more about those issues.

See I agree it is not the slashes that is the culprit, but the / being added in front of the drive path. This was removed on line 1300 and line 1378

Okay the changes I made was to remove lines that added a `/` in front of the drive like mentioned here: ``` /C:\path\to\where_ever ``` So that it will now look like this: ``` C:/path/to/where_ever ``` I did this to insure that scripts that target the `/` will behave correctly. So my question is have you test the last changes, and does it still give issues, and can you explain more about those issues. See I agree it is not the slashes that is the culprit, but the `/` being added in front of the drive path. This was removed on [line 1300](https://github.com/vdm-io/Joomla-Component-Builder/commit/289ba29e68ab74166fed26bad2c0add15b3548e9#diff-720c6f42c40b33f2cc3306b5ef5b8845L1300) and [line 1378](https://github.com/vdm-io/Joomla-Component-Builder/commit/289ba29e68ab74166fed26bad2c0add15b3548e9#diff-720c6f42c40b33f2cc3306b5ef5b8845R1378)
Author
Owner

I looked at line 831 and well it does not really add a / in front of the drive, or am I missing something?

$templatePath = (isset($details->custom) && $details->custom) ? (($details->custom !== 'full') ? $this->templatePathCustom . '/' : '') : $this->templatePath . '/';

It uses a global path $this->templatePath that is already correct. So it checks if it this loop is not a custom (folder) or custom (file) set of values. If it is custom set, then it checks if it is a full path. Then if it is set to a full folder or full file path we leave the $templatePath with an empty string, which is the correct action.

Because all full paths should already have the drive set, by either using the Joomla! path place holders, like JPATH_BASE (which is the recommended) or by using the full path with the drive as part of the path.

I looked at [line 831](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L831) and well it does not really add a `/` in front of the drive, or am I missing something? ```php $templatePath = (isset($details->custom) && $details->custom) ? (($details->custom !== 'full') ? $this->templatePathCustom . '/' : '') : $this->templatePath . '/'; ``` It uses a global path `$this->templatePath` that is already correct. So it checks if it this loop is not a [custom (folder)](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L1347) or [custom (file)](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L1430) set of values. If it is custom set, then it checks if it is a full path. Then if it is set to a [full folder](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L1307) or [full file](https://github.com/vdm-io/Joomla-Component-Builder/blob/staging/admin/helpers/compiler/b_Structure.php#L1385) path we leave the `$templatePath` with an empty string, which is the correct action. Because all full paths should already have the drive set, by either using the Joomla! path place holders, like `JPATH_BASE` (which is the recommended) or by using the full path with the drive as part of the path.
pdward commented 2019-03-13 00:19:30 +00:00 (Migrated from github.com)
Author
Owner

On windows line 833 is effectively prepending a '/' to the $item (which is correct) as $templatePath is empty.

If I remove the prepended '/' then the custom files are found.

However there is a new bug due to the compile/componentfolder not existing
e.g. /administrator/components/com_componentbuilder/compiler/com_SwapDoc_v0_0_22__J3/

Haven't checked with custom folders

On windows [line 833](https://github.com/vdm-io/Joomla-Component-Builder/blob/289ba29e68ab74166fed26bad2c0add15b3548e9/admin/helpers/compiler/b_Structure.php#L833) is effectively prepending a '/' to the $item (which is correct) as $templatePath is empty. If I remove the prepended '/' then the custom files are found. However there is a new bug due to the compile/componentfolder not existing e.g. /administrator/components/com_componentbuilder/compiler/com_SwapDoc_v0_0_22__J3/ Haven't checked with custom folders
pjdevries commented 2019-03-13 07:46:51 +00:00 (Migrated from github.com)
Author
Owner

I did this to insure that scripts that target the / will behave correctly.
I am not sure how to read this. Whether you mean any slashes in de designated path or whether you mean the single / at the beginning of a path, making it an absolute path.

If it is the former, I believe translation of \ into / is not necessary. PHP handles them correctly on Windows. Even when you mix the two within one and the same filename. However, I do agree it is good practice to standardize on always using /.

If it is the latter, I think you must also take Windows drive letters into account. Before you pushed the latest changes regarding this matter, this is what I did on my Windows development system:

I changed lines 830-834

// set the template folder path
$templatePath = (isset($details->custom) && $details->custom) ? (($details->custom !== 'full') ? $this->templatePathCustom . '/' : '') : $this->templatePath . '/';
// set the final paths
$currentFullPath = str_replace('//', '/', $templatePath . '/' . $item);

into

// set the template folder path
$templatePath = (isset($details->custom) && $details->custom) ? (($details->custom !== 'full') ? $this->templatePathCustom . '/' : '') : $this->templatePath . '/';
if (preg_match('/^[a-z]:/i', $item) === false)
{
    $templatePath .= '/';
}
// set the final paths
$currentFullPath = str_replace('//', '/', $templatePath . $item);

line 1300

$custom['folder'] = '/' . trim($custom['folderpath'], '/');

into

$custom['folder'] = preg_match('/^[a-z]:/i', $custom['folderpath']) === false
    ? '/' . trim($custom['folderpath'], '/')
    : trim($custom['folderpath'], '/');

and line 1376

$custom['file'] = '/' . trim($custom['filepath'], '/');

into

$custom['file'] = preg_match('/^[a-z]:/i', $custom['filepath']) === false
    ? '/' . trim($custom['filepath'], '/')
    : trim($custom['filepath'], '/');

Not my preferred way of coding because there is a lot of duplicate code. But it's merely a proof of concept. Better would be to move the drive check to a library function.

It also does not incorporate your fixPath() method (yet), but it solves the Windows problem I encountered with Component Files & Folders Advanced (using full system paths). I'm quite confident it will also solve the Windows problem in other places with similar logic.

> I did this to insure that scripts that target the `/` will behave correctly. I am not sure how to read this. Whether you mean any slashes in de designated path or whether you mean the single `/` at the beginning of a path, making it an absolute path. If it is the former, I believe translation of `\` into `/` is not necessary. PHP handles them correctly on Windows. Even when you mix the two within one and the same filename. However, I do agree it is good practice to standardize on always using `/`. If it is the latter, I think you must also take Windows drive letters into account. Before you pushed the latest changes regarding this matter, this is what I did on my Windows development system: I changed lines 830-834 ``` // set the template folder path $templatePath = (isset($details->custom) && $details->custom) ? (($details->custom !== 'full') ? $this->templatePathCustom . '/' : '') : $this->templatePath . '/'; // set the final paths $currentFullPath = str_replace('//', '/', $templatePath . '/' . $item); ``` into ``` // set the template folder path $templatePath = (isset($details->custom) && $details->custom) ? (($details->custom !== 'full') ? $this->templatePathCustom . '/' : '') : $this->templatePath . '/'; if (preg_match('/^[a-z]:/i', $item) === false) { $templatePath .= '/'; } // set the final paths $currentFullPath = str_replace('//', '/', $templatePath . $item); ``` line 1300 ``` $custom['folder'] = '/' . trim($custom['folderpath'], '/'); ``` into ``` $custom['folder'] = preg_match('/^[a-z]:/i', $custom['folderpath']) === false ? '/' . trim($custom['folderpath'], '/') : trim($custom['folderpath'], '/'); ``` and line 1376 ``` $custom['file'] = '/' . trim($custom['filepath'], '/'); ``` into ``` $custom['file'] = preg_match('/^[a-z]:/i', $custom['filepath']) === false ? '/' . trim($custom['filepath'], '/') : trim($custom['filepath'], '/'); ``` Not my preferred way of coding because there is a lot of duplicate code. But it's merely a proof of concept. Better would be to move the drive check to a library function. It also does not incorporate your `fixPath()` method (yet), but it solves the Windows problem I encountered with Component Files & Folders Advanced (using full system paths). I'm quite confident it will also solve the Windows problem in other places with similar logic.
pjdevries commented 2019-03-13 08:23:45 +00:00 (Migrated from github.com)
Author
Owner

I rolled back my drive letter fix to test your latest changes. It brings back the errors I had before, showing paths with drive letters and a leading /. Adding the fix for lines 830-834 I mentioned above, fixes the problem with the Windows drive letter for this specific instance.

I also get the compiler warnings @peterpetrov mentions about files not found and not being copied. Undoing the ComponentbuilderHelper::fixPath() method, solves that.

@Llewellynvdm : My suggestion is to rollback that latest change, since it does not seem to solve anything and even introduces new issues.

@peterpetrov : Apparently you are testing another situation than I am. Can you let me know what so I can try to reproduce and fix that?

I rolled back my drive letter fix to test your latest changes. It brings back the errors I had before, showing paths with drive letters and a leading `/`. Adding the fix for lines 830-834 I mentioned above, fixes the problem with the Windows drive letter for this specific instance. I also get the compiler warnings @peterpetrov mentions about files not found and not being copied. Undoing the `ComponentbuilderHelper::fixPath()` method, solves that. @Llewellynvdm : My suggestion is to rollback that latest change, since it does not seem to solve anything and even introduces new issues. @peterpetrov : Apparently you are testing another situation than I am. Can you let me know what so I can try to reproduce and fix that?
Author
Owner

Okay I am trying to fix something I can't see.

I have rolled back the changes, I am going to try again.

Okay I am trying to fix something I can't see. I have rolled back the changes, I am going to try again.
pjdevries commented 2019-03-13 10:50:07 +00:00 (Migrated from github.com)
Author
Owner

Let me try. I know a thing or two about PHP and Joomla! and have a Windows system. Just tell me where the problem area's are, apart from the ones I already found.

Let me try. I know a thing or two about PHP and Joomla! and have a Windows system. Just tell me where the problem area's are, apart from the ones I already found.
Author
Owner

Okay take two... I have adapted the fix to include your proposed fix. Please test and let me know.

Okay take two... I have adapted the fix to include your proposed fix. Please test and let me know.
pdward commented 2019-03-13 14:02:12 +00:00 (Migrated from github.com)
Author
Owner

Still not quite working.

The PHP_OS method worked for me
if(strtoupper(substr(PHP_OS, 0, 3)) === "WIN") { $currentFullPath = ltrim($currentFullPath, '/'); }


I'm using BITNAMI WAMP Stack 7.1.24 on Windows 10

In my component I'm adding Advanced (full path) Custom Files and folders:
File Path: JPATH_ROOT/components/com_swapdoc/views/shift/tmpl/modal.php
Target Path: /site/views/shift/tmpl

Folder Path: JPATH_ROOT/images/sampledata/fruitshop
Target Path: /site/images

With the @Llewellynvdm latests changes (ignoring my hack) I get error on $currentFullPath:
/C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs/components/com_swapdoc/views/shift/tmpl/modal.php

Note - Adding Basic custom files worked for me previously but haven't tried this now

Still not quite working. The PHP_OS method worked for me ` if(strtoupper(substr(PHP_OS, 0, 3)) === "WIN") { $currentFullPath = ltrim($currentFullPath, '/'); }` ------ I'm using BITNAMI WAMP Stack 7.1.24 on Windows 10 In my component I'm adding Advanced (full path) Custom Files and folders: File Path: JPATH_ROOT/components/com_swapdoc/views/shift/tmpl/modal.php Target Path: /site/views/shift/tmpl Folder Path: JPATH_ROOT/images/sampledata/fruitshop Target Path: /site/images With the @Llewellynvdm latests changes (ignoring my hack) I get error on $currentFullPath: /C:\Bitnami\wampstack-7.1.24-0\apps\joomla\htdocs/components/com_swapdoc/views/shift/tmpl/modal.php Note - Adding Basic custom files worked for me previously but haven't tried this now
pdward commented 2019-03-13 14:22:11 +00:00 (Migrated from github.com)
Author
Owner

I think the problem is because I'm using JPATH_ROOT instead of C:
Hence the regex ('/^[a-z]:/i') on line 1304 isn't applicable

I think the problem is because I'm using JPATH_ROOT instead of C:\ Hence the regex ('/^[a-z]:/i') on [line 1304](https://github.com/vdm-io/Joomla-Component-Builder/blob/da16b61ffb750af6e9f739fcb1bf21dd4090578d/admin/helpers/compiler/b_Structure.php#L1304) isn't applicable
pdward commented 2019-03-13 14:30:20 +00:00 (Migrated from github.com)
Author
Owner

Updating the dynamic path before checking for a drive/windows full path works

Updating the dynamic path before checking for a drive/windows full path works
Author
Owner

Okay let me also change that, should not be a big deal.

Okay let me also change that, should not be a big deal.
Author
Owner

@pdward please confirm that this issue is resolved for you?

@pdward please confirm that this issue is resolved for you?
pdward commented 2019-03-14 20:22:06 +00:00 (Migrated from github.com)
Author
Owner

Yes - the latest staging version works for me for advanced files / folders on windows

Yes - the latest staging version works for me for advanced files / folders on windows
Sign in to join this conversation.
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#231
No description provided.