From 9e4a6e0c5326362541810e367c0a78f036abed0f Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sat, 11 Jun 2022 19:11:00 +0200 Subject: [PATCH] Moved urlExist to file helper class. --- README.md | 4 +- admin/README.txt | 4 +- admin/config.xml | 4 -- admin/helpers/componentbuilder.php | 43 --------------- componentbuilder.xml | 2 +- .../jcb_powers/VDM.Joomla/src/Utilities.php | 16 ++++++ .../VDM.Joomla/src/Utilities/FileHelper.php | 52 +++++++++++++++++++ script.php | 2 +- site/helpers/componentbuilder.php | 43 --------------- 9 files changed, 74 insertions(+), 96 deletions(-) diff --git a/README.md b/README.md index 4baaf8163..096f091e6 100644 --- a/README.md +++ b/README.md @@ -143,11 +143,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*: 2nd June, 2022 ++ *Last Build*: 11th June, 2022 + *Version*: 2.13.1 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **287278** ++ *Line count*: **287256** + *Field count*: **1581** + *File count*: **1853** + *Folder count*: **261** diff --git a/admin/README.txt b/admin/README.txt index 4baaf8163..096f091e6 100644 --- a/admin/README.txt +++ b/admin/README.txt @@ -143,11 +143,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*: 2nd June, 2022 ++ *Last Build*: 11th June, 2022 + *Version*: 2.13.1 + *Copyright*: Copyright (C) 2015 Vast Development Method. All rights reserved. + *License*: GNU General Public License version 2 or later; see LICENSE.txt -+ *Line count*: **287278** ++ *Line count*: **287256** + *Field count*: **1581** + *File count*: **1853** + *Folder count*: **261** diff --git a/admin/config.xml b/admin/config.xml index 097cdb7ac..2643f5541 100644 --- a/admin/config.xml +++ b/admin/config.xml @@ -140,13 +140,9 @@ name="github_access_token" label="COM_COMPONENTBUILDER_CONFIG_GITHUB_ACCESS_TOKEN_LABEL" size="128" - default="secret" description="COM_COMPONENTBUILDER_CONFIG_GITHUB_ACCESS_TOKEN_DESCRIPTION" message="Error! Please add token here." class="text_area" - readonly="false" - disabled="false" - required="false" filter="STRING" hint="COM_COMPONENTBUILDER_CONFIG_GITHUB_ACCESS_TOKEN_HINT" autocomplete="off" diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php index c5ac3563a..06ecf63b5 100644 --- a/admin/helpers/componentbuilder.php +++ b/admin/helpers/componentbuilder.php @@ -3705,49 +3705,6 @@ abstract class ComponentbuilderHelper } - /** - * Check if the url exist - * - * @param string $url The url to check - * - * @return bool If exist true - * - */ - public static function urlExists($url) - { - $exists = false; - // check if we can use curl - if (function_exists('curl_version')) - { - // initiate curl - $ch = curl_init($url); - // CURLOPT_NOBODY (do not return body) - curl_setopt($ch, CURLOPT_NOBODY, true); - // make call - $result = curl_exec($ch); - // check return value - if ($result !== false) - { - // get the http CODE - $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if ($statusCode !== 404) - { - $exists = true; - } - } - // close the connection - curl_close($ch); - } - elseif ($headers = @get_headers($url)) - { - if(isset($headers[0]) && is_string($headers[0]) && strpos($headers[0],'404') === false) - { - $exists = true; - } - } - return $exists; - } - /** * Get the file path or url * diff --git a/componentbuilder.xml b/componentbuilder.xml index f56a95287..1c464e318 100644 --- a/componentbuilder.xml +++ b/componentbuilder.xml @@ -1,7 +1,7 @@ COM_COMPONENTBUILDER - 2nd June, 2022 + 11th June, 2022 Llewellyn van der Merwe llewellyn@joomlacomponentbuilder.com http://www.joomlacomponentbuilder.com diff --git a/libraries/jcb_powers/VDM.Joomla/src/Utilities.php b/libraries/jcb_powers/VDM.Joomla/src/Utilities.php index 53a87760f..798266b35 100644 --- a/libraries/jcb_powers/VDM.Joomla/src/Utilities.php +++ b/libraries/jcb_powers/VDM.Joomla/src/Utilities.php @@ -627,6 +627,22 @@ trait Utilities return FileHelper::getPath($type, $target, $fileType, $key, $default, $createIfNotSet); } + /** + * Check if file exist + * + * @param string $path The url/path to check + * + * @return bool If exist true + * + * @since 3.0.9 + * + * @deprecated 4.0 - Use FileHelper::exists($path); + */ + public static function urlExists($path) + { + return FileHelper::exists($path); + } + /** * Set the component option * diff --git a/libraries/jcb_powers/VDM.Joomla/src/Utilities/FileHelper.php b/libraries/jcb_powers/VDM.Joomla/src/Utilities/FileHelper.php index 37f1081f4..f9b630788 100644 --- a/libraries/jcb_powers/VDM.Joomla/src/Utilities/FileHelper.php +++ b/libraries/jcb_powers/VDM.Joomla/src/Utilities/FileHelper.php @@ -312,6 +312,58 @@ abstract class FileHelper // sanitize the path return '/' . trim( $filePath, '/' ) . '/' . $fileName; } + + /** + * Check if file exist + * + * @param string $path The url/path to check + * + * @return bool If exist true + * + * @since 3.0.9 + */ + public static function exists($path) + { + $exists = false; + // if this is a local path + if (strpos($path, 'http:') === false && strpos($path, 'https:') === false) + { + if (file_exists($path)) + { + $exists = true; + } + } + // check if we can use curl + elseif (function_exists('curl_version')) + { + // initiate curl + $ch = curl_init($path); + // CURLOPT_NOBODY (do not return body) + curl_setopt($ch, CURLOPT_NOBODY, true); + // make call + $result = curl_exec($ch); + // check return value + if ($result !== false) + { + // get the http CODE + $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + if ($statusCode !== 404) + { + $exists = true; + } + } + // close the connection + curl_close($ch); + } + elseif ($headers = @get_headers($path)) + { + if(isset($headers[0]) && is_string($headers[0]) && strpos($headers[0],'404') === false) + { + $exists = true; + } + } + return $exists; + } } diff --git a/script.php b/script.php index a85a7f99d..e49a0b823 100644 --- a/script.php +++ b/script.php @@ -6616,7 +6616,7 @@ class com_componentbuilderInstallerScript $query = $db->getQuery(true); // Field to update. $fields = array( - $db->quoteName('params') . ' = ' . $db->quote('{"autorName":"Llewellyn van der Merwe","autorEmail":"llewellyn@joomlacomponentbuilder.com","subform_layouts":"default","editor":"none","github_access_token":"secret","manage_jcb_package_directories":"2","set_browser_storage":"1","storage_time_to_live":"global","builder_gif_size":"480-272","add_menu_prefix":"1","menu_prefix":"»","minify":"0","language":"en-GB","percentagelanguageadd":"30","assets_table_fix":"2","compiler_field_builder_type":"2","field_name_builder":"1","type_name_builder":"1","import_guid_only":"1","export_language_strings":"1","development_method":"1","expansion":"0","return_options_build":"2","cronjob_backup_type":"1","cronjob_backup_server":"0","backup_package_name":"JCB_Backup_[YEAR]_[MONTH]_[DAY]","export_license":"GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html","export_copyright":"Copyright (C) 2015. All Rights Reserved","check_in":"-1 day","save_history":"1","history_limit":"10","uikit_load":"1","uikit_min":"","uikit_style":""}'), + $db->quoteName('params') . ' = ' . $db->quote('{"autorName":"Llewellyn van der Merwe","autorEmail":"llewellyn@joomlacomponentbuilder.com","subform_layouts":"default","editor":"none","manage_jcb_package_directories":"2","set_browser_storage":"1","storage_time_to_live":"global","builder_gif_size":"480-272","add_menu_prefix":"1","menu_prefix":"»","minify":"0","language":"en-GB","percentagelanguageadd":"30","assets_table_fix":"2","compiler_field_builder_type":"2","field_name_builder":"1","type_name_builder":"1","import_guid_only":"1","export_language_strings":"1","development_method":"1","expansion":"0","return_options_build":"2","cronjob_backup_type":"1","cronjob_backup_server":"0","backup_package_name":"JCB_Backup_[YEAR]_[MONTH]_[DAY]","export_license":"GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html","export_copyright":"Copyright (C) 2015. All Rights Reserved","check_in":"-1 day","save_history":"1","history_limit":"10","uikit_load":"1","uikit_min":"","uikit_style":""}'), ); // Condition. $conditions = array( diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php index 846900cb0..05ded752b 100644 --- a/site/helpers/componentbuilder.php +++ b/site/helpers/componentbuilder.php @@ -3702,49 +3702,6 @@ abstract class ComponentbuilderHelper } - /** - * Check if the url exist - * - * @param string $url The url to check - * - * @return bool If exist true - * - */ - public static function urlExists($url) - { - $exists = false; - // check if we can use curl - if (function_exists('curl_version')) - { - // initiate curl - $ch = curl_init($url); - // CURLOPT_NOBODY (do not return body) - curl_setopt($ch, CURLOPT_NOBODY, true); - // make call - $result = curl_exec($ch); - // check return value - if ($result !== false) - { - // get the http CODE - $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - if ($statusCode !== 404) - { - $exists = true; - } - } - // close the connection - curl_close($ch); - } - elseif ($headers = @get_headers($url)) - { - if(isset($headers[0]) && is_string($headers[0]) && strpos($headers[0],'404') === false) - { - $exists = true; - } - } - return $exists; - } - /** * Get the file path or url *