Added more checks to the onlinecode methods
This commit is contained in:
parent
8b3528d0a4
commit
765e8cc899
@ -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**
|
||||
|
@ -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**
|
||||
|
@ -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 <b>%s</b> 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 <b>%s</b> 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 <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
|
||||
@ -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 <b>%s</b> 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 <b>%s</b> 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)
|
||||
{
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension type="component" version="3.2" method="upgrade">
|
||||
<name>COM_COMPONENTBUILDER</name>
|
||||
<creationDate>31st January, 2018</creationDate>
|
||||
<creationDate>2nd February, 2018</creationDate>
|
||||
<author>Llewellyn van der Merwe</author>
|
||||
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
|
||||
<authorUrl>http://joomlacomponentbuilder.com</authorUrl>
|
||||
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user