Moved urlExist to file helper class.

This commit is contained in:
Llewellyn van der Merwe 2022-06-11 19:11:00 +02:00
parent 9f04566c81
commit 9e4a6e0c53
Signed by untrusted user: Llewellyn
GPG Key ID: A9201372263741E7
9 changed files with 74 additions and 96 deletions

View File

@ -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**

View File

@ -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**

View File

@ -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"

View File

@ -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
*

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="4" method="upgrade">
<name>COM_COMPONENTBUILDER</name>
<creationDate>2nd June, 2022</creationDate>
<creationDate>11th June, 2022</creationDate>
<author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>

View File

@ -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
*

View File

@ -313,5 +313,57 @@ abstract class FileHelper
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;
}
}

View File

@ -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(

View File

@ -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
*