diff --git a/README.md b/README.md
index 404aa6bdd..d0c4df17b 100644
--- a/README.md
+++ b/README.md
@@ -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)
+ *Name*: [Component Builder](http://joomlacomponentbuilder.com)
+ *First Build*: 30th April, 2015
-+ *Last Build*: 31st January, 2018
++ *Last Build*: 2nd February, 2018
+ *Version*: 2.6.14
+ *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *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**
+ *File count*: **1162**
+ *Folder count*: **186**
diff --git a/admin/README.txt b/admin/README.txt
index 404aa6bdd..d0c4df17b 100644
--- a/admin/README.txt
+++ b/admin/README.txt
@@ -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)
+ *Name*: [Component Builder](http://joomlacomponentbuilder.com)
+ *First Build*: 30th April, 2015
-+ *Last Build*: 31st January, 2018
++ *Last Build*: 2nd February, 2018
+ *Version*: 2.6.14
+ *Copyright*: Copyright (C) 2015. All Rights Reserved
+ *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**
+ *File count*: **1162**
+ *Folder count*: **186**
diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php
index 0964908c7..7aaf6eef4 100644
--- a/admin/helpers/compiler/a_Get.php
+++ b/admin/helpers/compiler/a_Get.php
@@ -3658,19 +3658,20 @@ class Get
{
if (ComponentbuilderHelper::checkString($string))
{
- return $this->setLangStrings($this->setCustomCodeData($this->setOnlineCodeData($string)));
+ return $this->setLangStrings($this->setCustomCodeData($this->setOnlineCodeString($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
*
* @return string
*
*/
- public function setOnlineCodeData($string)
+ public function setOnlineCodeString($string)
{
// check if content has custom code place holder
if (strpos($string, '[ONLIN' . 'ECODE=') !== false)
@@ -3683,52 +3684,22 @@ class Get
// build local bucket
foreach ($found as $url)
{
- $key = '[ONLIN' . 'ECODE=' . $url . ']';
- $urlKey = trim($url);
- // check if we already fethced this
- if (!isset($this->onlineCodeData[$urlKey]))
+ // check if the URL is valid
+ if (!filter_var($url, FILTER_VALIDATE_URL) === false && ComponentbuilderHelper::urlExists($url))
{
- // get the data string (code)
- $this->onlineCodeData[$urlKey] = ComponentbuilderHelper::getFileContents($urlKey);
- // did we get any value
- if (ComponentbuilderHelper::checkString($this->onlineCodeData[$urlKey]))
- {
- // check for changes
- $liveHash = md5($this->onlineCodeData[$urlKey]);
- // check if it exist local
- if ($hash = ComponentbuilderHelper::getVar('online_code', $urlKey, 'url', 'hash'))
- {
- if ($hash !== $liveHash)
- {
- $object = new stdClass();
- $object->url = $urlKey;
- $object->hash = $liveHash;
- // update local hash
- $this->db->updateObject('#__componentbuilder_online_code', $object, 'url');
- // give notice of the change
- $this->app->enqueueMessage(JText::sprintf('The code from %s has been changed since the last compilation, please investigate!', $urlKey), 'warning');
- }
- }
- else
- {
- // add the hash to track changes
- $object = new stdClass();
- $object->url = $urlKey;
- $object->hash = $liveHash;
- // insert local hash
- $this->db->insertObject('#__componentbuilder_online_code', $object);
- }
- }
- else
- {
- // set notice that we could not get the code from the url
- $this->app->enqueueMessage(JText::sprintf('The code from %s could not be added!', $urlKey), 'warning');
- }
+ $this->getOnlineCodeString($url, $bucket);
}
- // add to local bucket
- if (ComponentbuilderHelper::checkString($this->onlineCodeData[$urlKey]))
+ // check if this is a path
+ elseif (JPath::clean($url) === $url && JFile::exists($url))
{
- $bucket[$key] = $this->onlineCodeData[$urlKey];
+ $this->getOnlineCodeString($url, $bucket);
+ }
+ // give notice that url/path is not valid
+ else
+ {
+ $this->app->enqueueMessage(JText::sprintf('The %s 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
@@ -3741,6 +3712,70 @@ class Get
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 . ']';
+ // set URL key
+ $urlKey = trim($url);
+ // check if we already fethced this
+ if (!isset($this->onlineCodeData[$urlKey]))
+ {
+ // get the data string (code)
+ $this->onlineCodeData[$urlKey] = ComponentbuilderHelper::getFileContents($urlKey);
+ // did we get any value
+ if (ComponentbuilderHelper::checkString($this->onlineCodeData[$urlKey]))
+ {
+ // check for changes
+ $liveHash = md5($this->onlineCodeData[$urlKey]);
+ // check if it exist local
+ if ($hash = ComponentbuilderHelper::getVar('online_code', $urlKey, 'url', 'hash'))
+ {
+ if ($hash !== $liveHash)
+ {
+ $object = new stdClass();
+ $object->url = $urlKey;
+ $object->hash = $liveHash;
+ // update local hash
+ $this->db->updateObject('#__componentbuilder_online_code', $object, 'url');
+ // give notice of the change
+ $this->app->enqueueMessage(JText::sprintf('The code/string from %s has been changed since the last compilation, please investigate!', $key), 'warning');
+ }
+ }
+ else
+ {
+ // add the hash to track changes
+ $object = new stdClass();
+ $object->url = $urlKey;
+ $object->hash = $liveHash;
+ // insert local hash
+ $this->db->insertObject('#__componentbuilder_online_code', $object);
+ }
+ }
+ else
+ {
+ // set notice that we could not get the code from the url
+ $this->app->enqueueMessage(JText::sprintf('The %s returned an empty string!', $key), 'warning');
+ // remove the tag
+ $this->onlineCodeData[$urlKey] = '';
+ }
+ }
+ // add to local bucket
+ if (ComponentbuilderHelper::checkString($this->onlineCodeData[$urlKey]))
+ {
+ $bucket[$key] = $this->onlineCodeData[$urlKey];
+ }
+ }
+
/**
* 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']);
// 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
if ($setLang)
{
diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php
index 570f04164..a904c0d6c 100644
--- a/admin/helpers/componentbuilder.php
+++ b/admin/helpers/componentbuilder.php
@@ -1736,6 +1736,49 @@ abstract class ComponentbuilderHelper
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
*
diff --git a/componentbuilder.xml b/componentbuilder.xml
index 666cb204d..363b61362 100644
--- a/componentbuilder.xml
+++ b/componentbuilder.xml
@@ -1,7 +1,7 @@
COM_COMPONENTBUILDER
- 31st January, 2018
+ 2nd February, 2018
Llewellyn van der Merwe
llewellyn@joomlacomponentbuilder.com
http://joomlacomponentbuilder.com
diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php
index d79f95257..6af9c2915 100644
--- a/site/helpers/componentbuilder.php
+++ b/site/helpers/componentbuilder.php
@@ -802,6 +802,49 @@ abstract class ComponentbuilderHelper
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
*