From abb046f6716c7685971ab744b0b1470f0738fbf9 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Fri, 31 Aug 2018 23:11:23 +0200 Subject: [PATCH] Fixed gh-334 to insure that we always have a path/string in the default value. Made other improvements in the compiler and the bcmath methods. --- README.md | 4 +-- admin/README.txt | 4 +-- admin/helpers/componentbuilder.php | 52 ++++++++++++++++++++++++++---- admin/models/ajax.php | 2 +- componentbuilder.xml | 2 +- site/helpers/componentbuilder.php | 52 ++++++++++++++++++++++++++---- 6 files changed, 98 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c3d6191d2..0bbad6784 100644 --- a/README.md +++ b/README.md @@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *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*: 30th August, 2018 ++ *Last Build*: 31st August, 2018 + *Version*: 2.9.0 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **192879** ++ *Line count*: **192959** + *Field count*: **1081** + *File count*: **1273** + *Folder count*: **201** diff --git a/admin/README.txt b/admin/README.txt index c3d6191d2..0bbad6784 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -125,11 +125,11 @@ Watch the [proposed development workflow](https://vdm.bz/proposed-development-wo + *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*: 30th August, 2018 ++ *Last Build*: 31st August, 2018 + *Version*: 2.9.0 + *Copyright*: Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **192879** ++ *Line count*: **192959** + *Field count*: **1081** + *File count*: **1273** + *Folder count*: **201** diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index 7edbf62af..09fd5b40e 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -2338,6 +2338,11 @@ abstract class ComponentbuilderHelper */ public static function getFilePath($type = 'path', $target = 'filepath', $fileType = null, $key = '', $default = JPATH_SITE . '/images/', $createIfNotSet = true) { + // make sure to always have a string/path + if(!self::checkString($default)) + { + $default = JPATH_SITE . '/images/'; + } // get the global settings if (!self::checkObject(self::$params)) { @@ -2407,6 +2412,11 @@ abstract class ComponentbuilderHelper */ public static function getFolderPath($type = 'path', $target = 'folderpath', $default = JPATH_SITE . '/images/', $createIfNotSet = true) { + // make sure to always have a string/path + if(!self::checkString($default)) + { + $default = JPATH_SITE . '/images/'; + } // get the global settings if (!self::checkObject(self::$params)) { @@ -2523,7 +2533,7 @@ abstract class ComponentbuilderHelper { // build function name $function = 'bc' . $type; - // use the bcmath function of available + // use the bcmath function if available if (function_exists($function)) { return $function($val1, $val2, $scale); @@ -2559,6 +2569,32 @@ abstract class ComponentbuilderHelper return false; } + /** + * Basic sum of an array with more precision + * + * @param array $array The values to sum + * @param int $scale The scale value + * + * @return float + * + */ + public static function bcsum($array, $scale = 4) + { + // use the bcadd function if available + if (function_exists('bcadd')) + { + // set the start value + $value = 0.0; + // loop the values and run bcadd + foreach($array as $val) + { + $value = bcadd($value, $val, $scale); + } + return $value; + } + // fall back on array sum + return array_sum($array); + } /** * the locker @@ -3599,12 +3635,13 @@ abstract class ComponentbuilderHelper } /** - * Get the edit button + * Get an edit button * * @param int $item The item to edit * @param string $view The type of item to edit * @param string $views The list view controller name * @param string $ref The return path + * @param string $component The component these views belong to * @param string $headsup The message to show on click of button * * @return string On success the full html edit button @@ -3639,7 +3676,7 @@ abstract class ComponentbuilderHelper // check that there is a check message if (self::checkString($headsup)) { - $href = 'onclick="UIkit.modal.confirm(\''.JText::_($headsup).'\', function(){ window.location.href = \'' . $url . '\' })" href="javascript:void(0)"'; + $href = 'onclick="UIkit2.modal.confirm(\''.JText::_($headsup).'\', function(){ window.location.href = \'' . $url . '\' })" href="javascript:void(0)"'; } else { @@ -3664,9 +3701,12 @@ abstract class ComponentbuilderHelper /** * Get the edit URL * - * @param int $item The item to edit - * @param string $view The type of item to edit - * @param string $ref The return path + * @param int $item The item to edit + * @param string $view The type of item to edit + * @param string $views The list view controller name + * @param string $ref The return path + * @param string $component The component these views belong to + * @param bool $jRoute The switch to add use JRoute or not * * @return string On success the edit url * diff --git a/admin/models/ajax.php b/admin/models/ajax.php index a79cab4ac..f4deb2a8f 100644 --- a/admin/models/ajax.php +++ b/admin/models/ajax.php @@ -342,7 +342,7 @@ class ComponentbuilderModelAjax extends JModelList // only load referral if not new item. $ref = '&ref=' . $values['a_view'] . '&refid=' . $values['a_id'] . '&return=' . urlencode(base64_encode($return_url)); // get item id - if ($id = ComponentbuilderHelper::getVar($type, $values['a_id'], $values['a_view'], 'id')) + if (($id = ComponentbuilderHelper::getVar($type, $values['a_id'], $values['a_view'], 'id')) !== false && $id > 0) { $buttonText = JText::sprintf('COM_COMPONENTBUILDER_EDIT_S_FOR_THIS_S', ComponentbuilderHelper::safeString($type, 'w'), ComponentbuilderHelper::safeString($values['a_view'], 'w')); $buttonTextSmall = JText::_('COM_COMPONENTBUILDER_EDIT'); diff --git a/componentbuilder.xml b/componentbuilder.xml index f3c86c5e4..b393d1792 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 30th August, 2018 + 31st August, 2018 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index b7d95799b..ca86947af 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -2338,6 +2338,11 @@ abstract class ComponentbuilderHelper */ public static function getFilePath($type = 'path', $target = 'filepath', $fileType = null, $key = '', $default = JPATH_SITE . '/images/', $createIfNotSet = true) { + // make sure to always have a string/path + if(!self::checkString($default)) + { + $default = JPATH_SITE . '/images/'; + } // get the global settings if (!self::checkObject(self::$params)) { @@ -2407,6 +2412,11 @@ abstract class ComponentbuilderHelper */ public static function getFolderPath($type = 'path', $target = 'folderpath', $default = JPATH_SITE . '/images/', $createIfNotSet = true) { + // make sure to always have a string/path + if(!self::checkString($default)) + { + $default = JPATH_SITE . '/images/'; + } // get the global settings if (!self::checkObject(self::$params)) { @@ -2523,7 +2533,7 @@ abstract class ComponentbuilderHelper { // build function name $function = 'bc' . $type; - // use the bcmath function of available + // use the bcmath function if available if (function_exists($function)) { return $function($val1, $val2, $scale); @@ -2559,6 +2569,32 @@ abstract class ComponentbuilderHelper return false; } + /** + * Basic sum of an array with more precision + * + * @param array $array The values to sum + * @param int $scale The scale value + * + * @return float + * + */ + public static function bcsum($array, $scale = 4) + { + // use the bcadd function if available + if (function_exists('bcadd')) + { + // set the start value + $value = 0.0; + // loop the values and run bcadd + foreach($array as $val) + { + $value = bcadd($value, $val, $scale); + } + return $value; + } + // fall back on array sum + return array_sum($array); + } /** * the locker @@ -3599,12 +3635,13 @@ abstract class ComponentbuilderHelper } /** - * Get the edit button + * Get an edit button * * @param int $item The item to edit * @param string $view The type of item to edit * @param string $views The list view controller name * @param string $ref The return path + * @param string $component The component these views belong to * @param string $headsup The message to show on click of button * * @return string On success the full html edit button @@ -3639,7 +3676,7 @@ abstract class ComponentbuilderHelper // check that there is a check message if (self::checkString($headsup)) { - $href = 'onclick="UIkit.modal.confirm(\''.JText::_($headsup).'\', function(){ window.location.href = \'' . $url . '\' })" href="javascript:void(0)"'; + $href = 'onclick="UIkit2.modal.confirm(\''.JText::_($headsup).'\', function(){ window.location.href = \'' . $url . '\' })" href="javascript:void(0)"'; } else { @@ -3664,9 +3701,12 @@ abstract class ComponentbuilderHelper /** * Get the edit URL * - * @param int $item The item to edit - * @param string $view The type of item to edit - * @param string $ref The return path + * @param int $item The item to edit + * @param string $view The type of item to edit + * @param string $views The list view controller name + * @param string $ref The return path + * @param string $component The component these views belong to + * @param bool $jRoute The switch to add use JRoute or not * * @return string On success the edit url *