External Code Inclution Option #228

Merged
Llewellyn merged 8 commits from staging into master 2018-02-08 12:42:02 +00:00
6 changed files with 48 additions and 51 deletions
Showing only changes of commit c8af1befe4 - Show all commits

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

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

View File

@ -165,11 +165,11 @@ class Get
protected $codeAreadyDone = array(); protected $codeAreadyDone = array();
/** /**
* The online code to be added * The external code/string to be added
* *
* @var array * @var array
*/ */
protected $onlineCodeData = array(); protected $externalCodeString = array();
/* /*
* The line numbers Switch * The line numbers Switch
@ -3658,48 +3658,47 @@ class Get
{ {
if (ComponentbuilderHelper::checkString($string)) if (ComponentbuilderHelper::checkString($string))
{ {
return $this->setLangStrings($this->setCustomCodeData($this->setOnlineCodeString($string))); return $this->setLangStrings($this->setCustomCodeData($this->setExternalCodeString($string)));
} }
return $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 * @param string $string The content to check
* *
* @return string * @return string
* *
*/ */
public function setOnlineCodeString($string) public function setExternalCodeString($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, '[EXTERNA'.'LCODE=') !== false)
{ {
// urls content // target content
$bucket = array(); $bucket = array();
$found = ComponentbuilderHelper::getAllBetween($string, '[ONLIN' . 'ECODE=', ']'); $found = ComponentbuilderHelper::getAllBetween($string, '[EXTERNA'.'LCODE=', ']');
if (ComponentbuilderHelper::checkArray($found)) if (ComponentbuilderHelper::checkArray($found))
{ {
// build local bucket // build local bucket
foreach ($found as $url) foreach ($found as $target)
{ {
// check if the URL is valid // check if the target is valid URL or path
if (!filter_var($url, FILTER_VALIDATE_URL) === false && ComponentbuilderHelper::urlExists($url)) 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 // give notice that target is not a valid url/path
elseif (JPath::clean($url) === $url && JFile::exists($url))
{
$this->getOnlineCodeString($url, $bucket);
}
// give notice that url/path is not valid
else 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 // remove the placeholder
$bucket['[ONLIN'.'ECODE='.$url.']'] = ''; $bucket[$key] = '';
} }
} }
// now update local string if bucket has values // 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 string $string The content to check
* @param array $bucket The Placeholders bucket * @param array $bucket The Placeholders bucket
@ -3721,32 +3720,32 @@ class Get
* @return void * @return void
* *
*/ */
protected function getOnlineCodeString($url, &$bucket) protected function getExternalCodeString($target, &$bucket)
{ {
// set key // set key
$key = '[ONLIN' . 'ECODE=' . $url . ']'; $key = '[EXTERNA'.'LCODE=' . $target . ']';
// set URL key // set URL key
$urlKey = trim($url); $targetKey = trim($target);
// check if we already fethced this // check if we already fetched this
if (!isset($this->onlineCodeData[$urlKey])) if (!isset($this->externalCodeString[$targetKey]))
{ {
// get the data string (code) // get the data string (code)
$this->onlineCodeData[$urlKey] = ComponentbuilderHelper::getFileContents($urlKey); $this->externalCodeString[$targetKey] = ComponentbuilderHelper::getFileContents($targetKey);
// did we get any value // did we get any value
if (ComponentbuilderHelper::checkString($this->onlineCodeData[$urlKey])) if (ComponentbuilderHelper::checkString($this->externalCodeString[$targetKey]))
{ {
// check for changes // check for changes
$liveHash = md5($this->onlineCodeData[$urlKey]); $liveHash = md5($this->externalCodeString[$targetKey]);
// check if it exist local // 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) if ($hash !== $liveHash)
{ {
$object = new stdClass(); $object = new stdClass();
$object->url = $urlKey; $object->target = $targetKey;
$object->hash = $liveHash; $object->hash = $liveHash;
// update local hash // update local hash
$this->db->updateObject('#__componentbuilder_online_code', $object, 'url'); $this->db->updateObject('#__componentbuilder_external_code', $object, 'target');
// give notice of the change // 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'); $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 // add the hash to track changes
$object = new stdClass(); $object = new stdClass();
$object->url = $urlKey; $object->target = $targetKey;
$object->hash = $liveHash; $object->hash = $liveHash;
// insert local hash // insert local hash
$this->db->insertObject('#__componentbuilder_online_code', $object); $this->db->insertObject('#__componentbuilder_external_code', $object);
} }
} }
else else
{ {
// set notice that we could not get the code from the url // set notice that we could not get a valid string from the target
$this->app->enqueueMessage(JText::sprintf('The <b>%s</b> returned an empty string!', $key), 'warning'); $this->app->enqueueMessage(JText::sprintf('The <b>%s</b> returned an invalid string!', $key), 'warning');
// remove the tag
$this->onlineCodeData[$urlKey] = '';
} }
} }
// add to local bucket // 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) foreach ($bucket as $nr => &$customCode)
{ {
$customCode['code'] = base64_decode($customCode['code']); $customCode['code'] = base64_decode($customCode['code']);
// always insure that the online code is loaded // always insure that the external code is loaded
$customCode['code'] = $this->setOnlineCodeString($customCode['code']); $customCode['code'] = $this->setExternalCodeString($customCode['code']);
// set the lang only if needed // set the lang only if needed
if ($setLang) 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), (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); (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` ( CREATE TABLE IF NOT EXISTS `#__componentbuilder_external_code` (
`url` VARCHAR(255) NOT NULL DEFAULT '', `target` VARCHAR(255) NOT NULL DEFAULT '',
`hash` VARCHAR(64) NOT NULL DEFAULT '', `hash` VARCHAR(64) NOT NULL DEFAULT '',
PRIMARY KEY (`url`) PRIMARY KEY (`target`)
) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8; ) ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;

View File

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

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>2nd February, 2018</creationDate> <creationDate>3rd 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>