From da16b61ffb750af6e9f739fcb1bf21dd4090578d Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Wed, 13 Mar 2019 14:20:51 +0200 Subject: [PATCH] Trying to resolve the link issue in windows gh-231 --- README.md | 4 +-- admin/README.txt | 4 +-- admin/helpers/compiler/a_Get.php | 4 ++- admin/helpers/compiler/b_Structure.php | 22 ++++++++++++---- admin/helpers/componentbuilder.php | 36 +++++++++++++++++++++++++- componentbuilder.xml | 2 +- site/helpers/componentbuilder.php | 36 +++++++++++++++++++++++++- 7 files changed, 95 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index cafb1b361..dc21264fc 100644 --- a/README.md +++ b/README.md @@ -146,11 +146,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 9th March, 2019 ++ *Last Build*: 13th March, 2019 + *Version*: 2.9.13 + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **203581** ++ *Line count*: **203649** + *Field count*: **1114** + *File count*: **1337** + *Folder count*: **209** diff --git a/admin/README.txt b/admin/README.txt index cafb1b361..dc21264fc 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -146,11 +146,11 @@ TODO + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *First Build*: 30th April, 2015 -+ *Last Build*: 9th March, 2019 ++ *Last Build*: 13th March, 2019 + *Version*: 2.9.13 + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **203581** ++ *Line count*: **203649** + *Field count*: **1114** + *File count*: **1337** + *Folder count*: **209** diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php index c4afa32ce..34ea1ccbf 100644 --- a/admin/helpers/compiler/a_Get.php +++ b/admin/helpers/compiler/a_Get.php @@ -5807,7 +5807,7 @@ class Get $commentType = 0; // make sure we have the path correct (the script file is not in admin path for example) // there may be more... will nead to keep our eye on this... since files could be moved during install - $file = str_replace('./', '', $file); + $file = str_replace( './', '', $file); # TODO (windows path issues) if ($file !== 'script.php') { $path = $target . '/' . $file; @@ -5981,6 +5981,8 @@ class Get $hasharray = array_slice($fingerPrint, -$inFinger, $getFinger, true); $hasleng = count($hasharray); $hashtarget = $hasleng . '__' . md5(implode('', $hasharray)); + // for good practice + ComponentbuilderHelper::fixPath($path); // all new records we can do a buldk insert if ($i === 1 || !$id) { diff --git a/admin/helpers/compiler/b_Structure.php b/admin/helpers/compiler/b_Structure.php index a221b682c..07691d200 100644 --- a/admin/helpers/compiler/b_Structure.php +++ b/admin/helpers/compiler/b_Structure.php @@ -830,7 +830,8 @@ class Structure extends Get // 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); + $currentFullPath = (preg_match('/^[a-z]:/i', $item)) ? $item : $templatePath . '/' . $item; + $currentFullPath = str_replace('//', '/', $currentFullPath); $packageFullPath = str_replace('//', '/', $path . '/' . $new); $zipFullPath = str_replace('//', '/', $zipPath . '/' . $new); // now move the file @@ -1287,17 +1288,22 @@ class Structure extends Get $pointer_tracker = 'h'; foreach ($this->componentData->folders as $custom) { - // by default custom path is true - $customPath = 'custom'; + // for good practice + ComponentbuilderHelper::fixPath($custom, array('path', 'folder', 'folderpath')); // fix custom path if (isset($custom['path']) && ComponentbuilderHelper::checkString($custom['path'])) { $custom['path'] = trim($custom['path'], '/'); } + // by default custom path is true + $customPath = 'custom'; // set full path if this is a full path folder if (!isset($custom['folder']) && isset($custom['folderpath'])) { - $custom['folder'] = '/' . trim($custom['folderpath'], '/'); + // set the folder path with / if does not have a drive/windows full path + $custom['folder'] = (preg_match('/^[a-z]:/i', $custom['folderpath'])) + ? trim($custom['folderpath'], '/') + : '/' . trim($custom['folderpath'], '/'); // update the dynamic path $custom['folder'] = $this->updateDynamicPath($custom['folder']); // remove the file path @@ -1369,11 +1375,17 @@ class Structure extends Get $pointer_tracker = 'h'; foreach ($this->componentData->files as $custom) { + // for good practice + ComponentbuilderHelper::fixPath($custom, array('path', 'file', 'filepath')); + // by default custom path is true $customPath = 'custom'; // set full path if this is a full path file if (!isset($custom['file']) && isset($custom['filepath'])) { - $custom['file'] = '/' . trim($custom['filepath'], '/'); + // set the file path with / if does not have a drive/windows full path + $custom['file'] = (preg_match('/^[a-z]:/i', $custom['filepath'])) + ? trim($custom['filepath'], '/') + : '/' . trim($custom['filepath'], '/'); // update the dynamic path $custom['file'] = $this->updateDynamicPath($custom['file']); // remove the file path diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index 4c6e0095e..98efa2efa 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -407,7 +407,41 @@ abstract class ComponentbuilderHelper } return false; } - + + /** + * Fix the path to work in the JCB script <-- (main issue here) + * Since we need / slash in all paths, for the JCB script even if it is Windows + * and since MS works with both forward and back slashes + * we just convert all slashes to forward slashes + * + * THIS is just my hack (fix) if you know a better way! speak-up! + * + * @param mix $values the array of paths or the path as a string + * @param array $targets paths to target + * + * @return string + * + */ + public static function fixPath(&$values, $targets = array()) + { + // if multiple to gets searched and fixed + if (self::checkArray($values) && self::checkArray($targets)) + { + foreach ($targets as $target) + { + if (isset($values[$target]) && strpos($values[$target], '\\') !== false) + { + $values[$target] = str_replace('\\', '/', $values[$target]); + } + } + } + // if just a string + elseif (self::checkString($values) && strpos($values, '\\') !== false) + { + $values = str_replace('\\', '/', $values); + } + } + /** * get all the file paths in folder and sub folders * diff --git a/componentbuilder.xml b/componentbuilder.xml index 6fc1a8f9c..3ce3606bc 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 9th March, 2019 + 13th March, 2019 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index 942207647..95191b1fb 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -407,7 +407,41 @@ abstract class ComponentbuilderHelper } return false; } - + + /** + * Fix the path to work in the JCB script <-- (main issue here) + * Since we need / slash in all paths, for the JCB script even if it is Windows + * and since MS works with both forward and back slashes + * we just convert all slashes to forward slashes + * + * THIS is just my hack (fix) if you know a better way! speak-up! + * + * @param mix $values the array of paths or the path as a string + * @param array $targets paths to target + * + * @return string + * + */ + public static function fixPath(&$values, $targets = array()) + { + // if multiple to gets searched and fixed + if (self::checkArray($values) && self::checkArray($targets)) + { + foreach ($targets as $target) + { + if (isset($values[$target]) && strpos($values[$target], '\\') !== false) + { + $values[$target] = str_replace('\\', '/', $values[$target]); + } + } + } + // if just a string + elseif (self::checkString($values) && strpos($values, '\\') !== false) + { + $values = str_replace('\\', '/', $values); + } + } + /** * get all the file paths in folder and sub folders *