Changed from onlinecode to externalcode

This commit is contained in:
Llewellyn van der Merwe 2018-02-03 02:13:48 +02:00
parent 765e8cc899
commit c8af1befe4
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5
6 changed files with 48 additions and 51 deletions

View File

@ -126,7 +126,7 @@ 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*: 2nd February, 2018
+ *Last Build*: 3rd 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

View File

@ -126,7 +126,7 @@ 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*: 2nd February, 2018
+ *Last Build*: 3rd 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

View File

@ -165,11 +165,11 @@ class Get
protected $codeAreadyDone = array();
/**
* The online code to be added
* The external code/string to be added
*
* @var array
*/
protected $onlineCodeData = array();
protected $externalCodeString = array();
/*
* The line numbers Switch
@ -3658,48 +3658,47 @@ class Get
{
if (ComponentbuilderHelper::checkString($string))
{
return $this->setLangStrings($this->setCustomCodeData($this->setOnlineCodeString($string)));
return $this->setLangStrings($this->setCustomCodeData($this->setExternalCodeString($string)));
}
return $string;
}
/**
* We start set the online code string & can load it in to string
* Set the external code string & load it in to string
*
* @param string $string The content to check
*
* @return string
*
*/
public function setOnlineCodeString($string)
public function setExternalCodeString($string)
{
// check if content has custom code place holder
if (strpos($string, '[ONLIN' . 'ECODE=') !== false)
if (strpos($string, '[EXTERNA'.'LCODE=') !== false)
{
// urls content
// target content
$bucket = array();
$found = ComponentbuilderHelper::getAllBetween($string, '[ONLIN' . 'ECODE=', ']');
$found = ComponentbuilderHelper::getAllBetween($string, '[EXTERNA'.'LCODE=', ']');
if (ComponentbuilderHelper::checkArray($found))
{
// build local bucket
foreach ($found as $url)
foreach ($found as $target)
{
// check if the URL is valid
if (!filter_var($url, FILTER_VALIDATE_URL) === false && ComponentbuilderHelper::urlExists($url))
// check if the target is valid URL or path
if ((!filter_var($target, FILTER_VALIDATE_URL) === false && ComponentbuilderHelper::urlExists($target))
|| (JPath::clean($target) === $target && JFile::exists($target)))
{
$this->getOnlineCodeString($url, $bucket);
$this->getExternalCodeString($target, $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
// give notice that target is not a valid url/path
else
{
$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> is not a valid url/path!', '[ONLIN'.'ECODE='.$url.']'), 'warning');
// set key
$key = '[EXTERNA'.'LCODE='.$target.']';
// set the notice
$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> is not a valid url/path!', $key), 'warning');
// remove the placeholder
$bucket['[ONLIN'.'ECODE='.$url.']'] = '';
$bucket[$key] = '';
}
}
// now update local string if bucket has values
@ -3713,7 +3712,7 @@ class Get
}
/**
* Get the Online Code/String
* Get the External Code/String
*
* @param string $string The content to check
* @param array $bucket The Placeholders bucket
@ -3721,32 +3720,32 @@ class Get
* @return void
*
*/
protected function getOnlineCodeString($url, &$bucket)
protected function getExternalCodeString($target, &$bucket)
{
// set key
$key = '[ONLIN' . 'ECODE=' . $url . ']';
$key = '[EXTERNA'.'LCODE=' . $target . ']';
// set URL key
$urlKey = trim($url);
// check if we already fethced this
if (!isset($this->onlineCodeData[$urlKey]))
$targetKey = trim($target);
// check if we already fetched this
if (!isset($this->externalCodeString[$targetKey]))
{
// get the data string (code)
$this->onlineCodeData[$urlKey] = ComponentbuilderHelper::getFileContents($urlKey);
$this->externalCodeString[$targetKey] = ComponentbuilderHelper::getFileContents($targetKey);
// did we get any value
if (ComponentbuilderHelper::checkString($this->onlineCodeData[$urlKey]))
if (ComponentbuilderHelper::checkString($this->externalCodeString[$targetKey]))
{
// check for changes
$liveHash = md5($this->onlineCodeData[$urlKey]);
$liveHash = md5($this->externalCodeString[$targetKey]);
// check if it exist local
if ($hash = ComponentbuilderHelper::getVar('online_code', $urlKey, 'url', 'hash'))
if ($hash = ComponentbuilderHelper::getVar('external_code', $targetKey, 'target', 'hash'))
{
if ($hash !== $liveHash)
{
$object = new stdClass();
$object->url = $urlKey;
$object->target = $targetKey;
$object->hash = $liveHash;
// update local hash
$this->db->updateObject('#__componentbuilder_online_code', $object, 'url');
$this->db->updateObject('#__componentbuilder_external_code', $object, 'target');
// 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');
}
@ -3755,24 +3754,22 @@ class Get
{
// add the hash to track changes
$object = new stdClass();
$object->url = $urlKey;
$object->target = $targetKey;
$object->hash = $liveHash;
// insert local hash
$this->db->insertObject('#__componentbuilder_online_code', $object);
$this->db->insertObject('#__componentbuilder_external_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] = '';
// set notice that we could not get a valid string from the target
$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> returned an invalid string!', $key), 'warning');
}
}
// add to local bucket
if (ComponentbuilderHelper::checkString($this->onlineCodeData[$urlKey]))
if (isset($this->externalCodeString[$targetKey]))
{
$bucket[$key] = $this->onlineCodeData[$urlKey];
$bucket[$key] = $this->externalCodeString[$targetKey];
}
}
@ -4400,8 +4397,8 @@ class Get
foreach ($bucket as $nr => &$customCode)
{
$customCode['code'] = base64_decode($customCode['code']);
// always insure that the online code is loaded
$customCode['code'] = $this->setOnlineCodeString($customCode['code']);
// always insure that the external code is loaded
$customCode['code'] = $this->setExternalCodeString($customCode['code']);
// set the lang only if needed
if ($setLang)
{

View File

@ -1634,10 +1634,10 @@ INSERT INTO `#__componentbuilder_library_files_folders_urls` (`id`, `addfiles`,
(2, '', '', '{\"addurls0\":{\"url\":\"https:\\/\\/maxcdn.bootstrapcdn.com\\/bootstrap\\/4.0.0-alpha.6\\/js\\/bootstrap.min.js\",\"type\":\"2\"},\"addurls1\":{\"url\":\"https:\\/\\/maxcdn.bootstrapcdn.com\\/bootstrap\\/4.0.0-alpha.6\\/css\\/bootstrap.min.css\",\"type\":\"2\"}}', 2, '', 1, '2017-11-25 16:17:36', '2017-12-25 12:40:16', 10, '', 2),
(3, '', '', '{\"addurls0\":{\"url\":\"https:\\/\\/cdnjs.cloudflare.com\\/ajax\\/libs\\/uikit\\/3.0.0-beta.35\\/js\\/uikit.min.js\",\"type\":\"2\"},\"addurls1\":{\"url\":\"https:\\/\\/cdnjs.cloudflare.com\\/ajax\\/libs\\/uikit\\/3.0.0-beta.35\\/js\\/uikit-icons.min.js\",\"type\":\"2\"},\"addurls2\":{\"url\":\"https:\\/\\/cdnjs.cloudflare.com\\/ajax\\/libs\\/uikit\\/3.0.0-beta.35\\/css\\/uikit.min.css\",\"type\":\"2\"}}', 3, '', 1, '2017-11-25 21:47:40', '2017-12-25 12:38:24', 8, '', 3);
CREATE TABLE IF NOT EXISTS `#__componentbuilder_online_code` (
`url` VARCHAR(255) NOT NULL DEFAULT '',
CREATE TABLE IF NOT EXISTS `#__componentbuilder_external_code` (
`target` VARCHAR(255) NOT NULL DEFAULT '',
`hash` VARCHAR(64) NOT NULL DEFAULT '',
PRIMARY KEY (`url`)
PRIMARY KEY (`target`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

View File

@ -1,5 +1,5 @@
CREATE TABLE IF NOT EXISTS `#__componentbuilder_online_code` (
`url` VARCHAR(255) NOT NULL DEFAULT '',
CREATE TABLE IF NOT EXISTS `#__componentbuilder_external_code` (
`target` VARCHAR(255) NOT NULL DEFAULT '',
`hash` VARCHAR(64) NOT NULL DEFAULT '',
PRIMARY KEY (`url`)
PRIMARY KEY (`target`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

View File

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