Added more checks to the onlinecode methods

This commit is contained in:
Llewellyn van der Merwe 2018-02-02 19:36:22 +02:00
parent 8b3528d0a4
commit 765e8cc899
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
6 changed files with 173 additions and 52 deletions

View File

@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 31st January, 2018 + *Last Build*: 2nd February, 2018
+ *Version*: 2.6.14 + *Version*: 2.6.14
+ *Copyright*: Copyright (C) 2015. All Rights Reserved + *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
+ *Line count*: **180866** + *Line count*: **180952**
+ *Field count*: **1577** + *Field count*: **1577**
+ *File count*: **1162** + *File count*: **1162**
+ *Folder count*: **186** + *Folder count*: **186**

View File

@ -126,11 +126,11 @@ Component Builder is mapped as a component in itself on my local development env
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](http://joomlacomponentbuilder.com) + *Name*: [Component Builder](http://joomlacomponentbuilder.com)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 31st January, 2018 + *Last Build*: 2nd February, 2018
+ *Version*: 2.6.14 + *Version*: 2.6.14
+ *Copyright*: Copyright (C) 2015. All Rights Reserved + *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html + *License*: GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
+ *Line count*: **180866** + *Line count*: **180952**
+ *Field count*: **1577** + *Field count*: **1577**
+ *File count*: **1162** + *File count*: **1162**
+ *Folder count*: **186** + *Folder count*: **186**

View File

@ -3658,19 +3658,20 @@ class Get
{ {
if (ComponentbuilderHelper::checkString($string)) if (ComponentbuilderHelper::checkString($string))
{ {
return $this->setLangStrings($this->setCustomCodeData($this->setOnlineCodeData($string))); return $this->setLangStrings($this->setCustomCodeData($this->setOnlineCodeString($string)));
} }
return $string; return $string;
} }
/** /**
* We start set the online code data & can load it in to string * We start set the online code string & can load it in to string
* *
* @param string $string The content to check * @param string $string The content to check
* *
* @return string * @return string
* *
*/ */
public function setOnlineCodeData($string) public function setOnlineCodeString($string)
{ {
// check if content has custom code place holder // check if content has custom code place holder
if (strpos($string, '[ONLIN' . 'ECODE=') !== false) if (strpos($string, '[ONLIN' . 'ECODE=') !== false)
@ -3683,7 +3684,48 @@ class Get
// build local bucket // build local bucket
foreach ($found as $url) foreach ($found as $url)
{ {
// check if the URL is valid
if (!filter_var($url, FILTER_VALIDATE_URL) === false && ComponentbuilderHelper::urlExists($url))
{
$this->getOnlineCodeString($url, $bucket);
}
// check if this is a path
elseif (JPath::clean($url) === $url && JFile::exists($url))
{
$this->getOnlineCodeString($url, $bucket);
}
// give notice that url/path is not valid
else
{
$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> is not a valid url/path!', '[ONLIN'.'ECODE='.$url.']'), 'warning');
// remove the placeholder
$bucket['[ONLIN'.'ECODE='.$url.']'] = '';
}
}
// now update local string if bucket has values
if (ComponentbuilderHelper::checkArray($bucket))
{
$string = $this->setPlaceholders($string, $bucket);
}
}
}
return $string;
}
/**
* Get the Online Code/String
*
* @param string $string The content to check
* @param array $bucket The Placeholders bucket
*
* @return void
*
*/
protected function getOnlineCodeString($url, &$bucket)
{
// set key
$key = '[ONLIN' . 'ECODE=' . $url . ']'; $key = '[ONLIN' . 'ECODE=' . $url . ']';
// set URL key
$urlKey = trim($url); $urlKey = trim($url);
// check if we already fethced this // check if we already fethced this
if (!isset($this->onlineCodeData[$urlKey])) if (!isset($this->onlineCodeData[$urlKey]))
@ -3706,7 +3748,7 @@ class Get
// update local hash // update local hash
$this->db->updateObject('#__componentbuilder_online_code', $object, 'url'); $this->db->updateObject('#__componentbuilder_online_code', $object, 'url');
// give notice of the change // give notice of the change
$this->app->enqueueMessage(JText::sprintf('The code from <b>%s</b> has been changed since the last compilation, please investigate!', $urlKey), 'warning'); $this->app->enqueueMessage(JText::sprintf('The code/string from <b>%s</b> has been changed since the last compilation, please investigate!', $key), 'warning');
} }
} }
else else
@ -3722,7 +3764,9 @@ class Get
else else
{ {
// set notice that we could not get the code from the url // set notice that we could not get the code from the url
$this->app->enqueueMessage(JText::sprintf('The code from <b>%s</b> could not be added!', $urlKey), 'warning'); $this->app->enqueueMessage(JText::sprintf('The <b>%s</b> returned an empty string!', $key), 'warning');
// remove the tag
$this->onlineCodeData[$urlKey] = '';
} }
} }
// add to local bucket // add to local bucket
@ -3731,15 +3775,6 @@ class Get
$bucket[$key] = $this->onlineCodeData[$urlKey]; $bucket[$key] = $this->onlineCodeData[$urlKey];
} }
} }
// now update local string if bucket has values
if (ComponentbuilderHelper::checkArray($bucket))
{
$string = $this->setPlaceholders($string, $bucket);
}
}
}
return $string;
}
/** /**
* We start set the custom code data & can load it in to string * We start set the custom code data & can load it in to string
@ -4366,7 +4401,7 @@ class Get
{ {
$customCode['code'] = base64_decode($customCode['code']); $customCode['code'] = base64_decode($customCode['code']);
// always insure that the online code is loaded // always insure that the online code is loaded
$customCode['code'] = $this->setOnlineCodeData($customCode['code']); $customCode['code'] = $this->setOnlineCodeString($customCode['code']);
// set the lang only if needed // set the lang only if needed
if ($setLang) if ($setLang)
{ {

View File

@ -1736,6 +1736,49 @@ abstract class ComponentbuilderHelper
return false; return false;
} }
/**
* 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 === 200)
{
$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 * Get the file path or url
* *

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2" method="upgrade"> <extension type="component" version="3.2" method="upgrade">
<name>COM_COMPONENTBUILDER</name> <name>COM_COMPONENTBUILDER</name>
<creationDate>31st January, 2018</creationDate> <creationDate>2nd February, 2018</creationDate>
<author>Llewellyn van der Merwe</author> <author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail> <authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://joomlacomponentbuilder.com</authorUrl> <authorUrl>http://joomlacomponentbuilder.com</authorUrl>

View File

@ -802,6 +802,49 @@ abstract class ComponentbuilderHelper
return false; return false;
} }
/**
* 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 === 200)
{
$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 * Get the file path or url
* *