From 098c82c222f1a79423eaff626504591e5a0a4371 Mon Sep 17 00:00:00 2001
From: Llewellyn van der Merwe <llewellyn@vdm.io>
Date: Mon, 4 Mar 2019 14:47:28 +0200
Subject: [PATCH] fixed gh-383 to insure the new button works on frontend/site.
 Improved the JCB package import to also now import the new placeholder
 feature values correctly.

---
 README.md                                     |   4 +-
 admin/README.txt                              |   4 +-
 admin/helpers/compiler.php                    |   2 +-
 admin/helpers/compiler/a_Get.php              |   2 +-
 admin/helpers/compiler/b_Structure.php        |   2 +-
 admin/helpers/compiler/c_Fields.php           |   2 +-
 admin/helpers/compiler/e_Interpretation.php   |  18 +++-
 admin/helpers/compiler/f_Infusion.php         |   2 +-
 admin/helpers/componentbuilder.php            |  26 ++++-
 admin/layouts/fieldtype/fields_fullwidth.php  |  16 ++-
 .../server/linked_components_fullwidth.php    |  12 ++-
 admin/models/import_joomla_components.php     |   6 +-
 admin/models/joomla_components.php            | 101 +++++++++++++-----
 componentbuilder.xml                          |   2 +-
 site/helpers/componentbuilder.php             |  26 ++++-
 15 files changed, 176 insertions(+), 49 deletions(-)

diff --git a/README.md b/README.md
index f5ea51357..4001ccf31 100644
--- a/README.md
+++ b/README.md
@@ -146,11 +146,11 @@ TODO
 + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
 + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
 + *First Build*: 30th April, 2015
-+ *Last Build*: 23rd February, 2019
++ *Last Build*: 4th March, 2019
 + *Version*: 2.9.13
 + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
 + *License*: GNU General Public License version 2 or later; see LICENSE.txt
-+ *Line count*: **203476**
++ *Line count*: **203595**
 + *Field count*: **1114**
 + *File count*: **1337**
 + *Folder count*: **209**
diff --git a/admin/README.txt b/admin/README.txt
index f5ea51357..4001ccf31 100644
--- a/admin/README.txt
+++ b/admin/README.txt
@@ -146,11 +146,11 @@ TODO
 + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
 + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
 + *First Build*: 30th April, 2015
-+ *Last Build*: 23rd February, 2019
++ *Last Build*: 4th March, 2019
 + *Version*: 2.9.13
 + *Copyright*: Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
 + *License*: GNU General Public License version 2 or later; see LICENSE.txt
-+ *Line count*: **203476**
++ *Line count*: **203595**
 + *Field count*: **1114**
 + *File count*: **1337**
 + *Folder count*: **209**
diff --git a/admin/helpers/compiler.php b/admin/helpers/compiler.php
index 638961cb8..08e3a672a 100644
--- a/admin/helpers/compiler.php
+++ b/admin/helpers/compiler.php
@@ -5,7 +5,7 @@
  * @created    30th April, 2015
  * @author     Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
  * @github     Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
- * @copyright  Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ * @copyright  Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
  * @license    GNU General Public License version 2 or later; see LICENSE.txt
  */
 
diff --git a/admin/helpers/compiler/a_Get.php b/admin/helpers/compiler/a_Get.php
index c48ea2cf1..9b95dfada 100644
--- a/admin/helpers/compiler/a_Get.php
+++ b/admin/helpers/compiler/a_Get.php
@@ -5,7 +5,7 @@
  * @created    30th April, 2015
  * @author     Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
  * @github     Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
- * @copyright  Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ * @copyright  Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
  * @license    GNU General Public License version 2 or later; see LICENSE.txt
  */
 
diff --git a/admin/helpers/compiler/b_Structure.php b/admin/helpers/compiler/b_Structure.php
index 024a840f0..a221b682c 100644
--- a/admin/helpers/compiler/b_Structure.php
+++ b/admin/helpers/compiler/b_Structure.php
@@ -5,7 +5,7 @@
  * @created    30th April, 2015
  * @author     Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
  * @github     Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
- * @copyright  Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ * @copyright  Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
  * @license    GNU General Public License version 2 or later; see LICENSE.txt
  */
 
diff --git a/admin/helpers/compiler/c_Fields.php b/admin/helpers/compiler/c_Fields.php
index 9e0f836a2..0016638ab 100644
--- a/admin/helpers/compiler/c_Fields.php
+++ b/admin/helpers/compiler/c_Fields.php
@@ -5,7 +5,7 @@
  * @created    30th April, 2015
  * @author     Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
  * @github     Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
- * @copyright  Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ * @copyright  Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
  * @license    GNU General Public License version 2 or later; see LICENSE.txt
  */
 
diff --git a/admin/helpers/compiler/e_Interpretation.php b/admin/helpers/compiler/e_Interpretation.php
index 6ae77e63b..b7a78792f 100644
--- a/admin/helpers/compiler/e_Interpretation.php
+++ b/admin/helpers/compiler/e_Interpretation.php
@@ -5,7 +5,7 @@
  * @created    30th April, 2015
  * @author     Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
  * @github     Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
- * @copyright  Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ * @copyright  Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
  * @license    GNU General Public License version 2 or later; see LICENSE.txt
  */
 
@@ -8083,21 +8083,29 @@ class Interpretation extends Fields
 			$headerscript .= PHP_EOL . '{';
 			$headerscript .= PHP_EOL . $this->_t(1) . '$return .= "&return=" . $_return;';
 			$headerscript .= PHP_EOL . '}';
-			$headerscript .= PHP_EOL . '//' . $this->setLine(__LINE__) . ' set the referral values';
-			$headerscript .= PHP_EOL . '$ref = ($id) ? "&ref=' . $viewName_single . '&refid=" . $id . "&return=" . urlencode(base64_encode($return)) : "";';
+			$headerscript .= PHP_EOL . '//' . $this->setLine(__LINE__) . ' check if return value was set';
+			$headerscript .= PHP_EOL . 'if (' . $this->fileContentStatic[$this->hhh . 'Component' . $this->hhh] . 'Helper::checkString($return))';
+			$headerscript .= PHP_EOL . '{';
+			$headerscript .= PHP_EOL . $this->_t(1) . '//' . $this->setLine(__LINE__) . ' set the referral values';
+			$headerscript .= PHP_EOL . $this->_t(1) . '$ref = ($id) ? "&ref=' . $viewName_single . '&refid=" . $id . "&return=" . urlencode(base64_encode($return)) : "&return=" . urlencode(base64_encode($return));';
+			$headerscript .= PHP_EOL . '}';
+			$headerscript .= PHP_EOL . 'else';
+			$headerscript .= PHP_EOL . '{';
+			$headerscript .= PHP_EOL . $this->_t(1) . '$ref = ($id) ? "&ref=' . $viewName_single . '&refid=" . $id : "";';
+			$headerscript .= PHP_EOL . '}';
 			if ($addNewButon > 0)
 			{
 				// add the link for new
 				if ($addNewButon == 1 || $addNewButon == 2)
 				{
 					$headerscript .= PHP_EOL . '//' . $this->setLine(__LINE__) . ' set the create new URL';
-					$headerscript .= PHP_EOL . '$new = "index.php?option=com_' . $this->fileContentStatic[$this->hhh . 'component' . $this->hhh] . '&view=' . $single . '&layout=edit".$ref;';
+					$headerscript .= PHP_EOL . '$new = "index.php?option=com_' . $this->fileContentStatic[$this->hhh . 'component' . $this->hhh] . '&view=' . $list . '&task=' . $single . '.edit" . $ref;';
 				}
 				// and the link for close and new
 				if ($addNewButon == 2 || $addNewButon == 3)
 				{
 					$headerscript .= PHP_EOL . '//' . $this->setLine(__LINE__) . ' set the create new and close URL';
-					$headerscript .= PHP_EOL . '$close_new = "index.php?option=com_' . $this->fileContentStatic[$this->hhh . 'component' . $this->hhh] . '&view=' . $single . '&layout=edit";';
+					$headerscript .= PHP_EOL . '$close_new = "index.php?option=com_' . $this->fileContentStatic[$this->hhh . 'component' . $this->hhh] . '&view=' . $list . '&task=' . $single . '.edit";';
 				}
 				$headerscript .= PHP_EOL . '//' . $this->setLine(__LINE__) . ' load the action object';
 				$headerscript .= PHP_EOL . '$can = ' . $this->fileContentStatic[$this->hhh . 'Component' . $this->hhh] . 'Helper::getActions(' . "'" . $single . "'" . ');';
diff --git a/admin/helpers/compiler/f_Infusion.php b/admin/helpers/compiler/f_Infusion.php
index 61062975d..79b603b10 100644
--- a/admin/helpers/compiler/f_Infusion.php
+++ b/admin/helpers/compiler/f_Infusion.php
@@ -5,7 +5,7 @@
  * @created    30th April, 2015
  * @author     Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
  * @github     Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
- * @copyright  Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
+ * @copyright  Copyright (C) 2015 - 2019 Vast Development Method. All rights reserved.
  * @license    GNU General Public License version 2 or later; see LICENSE.txt
  */
 
diff --git a/admin/helpers/componentbuilder.php b/admin/helpers/componentbuilder.php
index d440fd38c..a4f722bd1 100644
--- a/admin/helpers/componentbuilder.php
+++ b/admin/helpers/componentbuilder.php
@@ -1209,7 +1209,7 @@ abstract class ComponentbuilderHelper
 					'message' => JText::_('COM_COMPONENTBUILDER_SORRY_THIS_PLACEHOLDER_IS_ALREADY_IN_USE'),
 					'status' => 'danger');
 			}
-			return false;			
+			return false;
 		}
 		// check if we must return boolean
 		if (!$bool)
@@ -4080,6 +4080,10 @@ abstract class ComponentbuilderHelper
 				{
 					$checked_out = (int) $item->checked_out;
 				}
+				else
+				{
+					$checked_out = self::getVar($view, $item->id, 'id', 'checked_out', '=', str_replace('com_', '', $component));
+				}
 			}
 			elseif (self::checkArray($item) && isset($item['id']))
 			{
@@ -4088,6 +4092,14 @@ abstract class ComponentbuilderHelper
 				{
 					$checked_out = (int) $item['checked_out'];
 				}
+				else
+				{
+					$checked_out = self::getVar($view, $item['id'], 'id', 'checked_out', '=', str_replace('com_', '', $component));
+				}
+			}
+			elseif (is_numeric($item) && $item > 0)
+			{
+				$checked_out = self::getVar($view, $item, 'id', 'checked_out', '=', str_replace('com_', '', $component));
 			}
 			// set the link title
 			$title = self::safeString(JText::_('COM_COMPONENTBUILDER_EDIT') . ' ' . $view, 'W');
@@ -4180,6 +4192,10 @@ abstract class ComponentbuilderHelper
 				{
 					$checked_out = (int) $item->checked_out;
 				}
+				else
+				{
+					$checked_out = self::getVar($view, $item->id, 'id', 'checked_out', '=', str_replace('com_', '', $component));
+				}
 			}
 			elseif (self::checkArray($item) && isset($item['id']))
 			{
@@ -4188,6 +4204,14 @@ abstract class ComponentbuilderHelper
 				{
 					$checked_out = (int) $item['checked_out'];
 				}
+				else
+				{
+					$checked_out = self::getVar($view, $item['id'], 'id', 'checked_out', '=', str_replace('com_', '', $component));
+				}
+			}
+			elseif (is_numeric($item) && $item > 0)
+			{
+				$checked_out = self::getVar($view, $item, 'id', 'checked_out', '=', str_replace('com_', '', $component));
 			}
 			// set the link title
 			$title = self::safeString(JText::_('COM_COMPONENTBUILDER_EDIT') . ' ' . $view, 'W');
diff --git a/admin/layouts/fieldtype/fields_fullwidth.php b/admin/layouts/fieldtype/fields_fullwidth.php
index fe518049a..11893785e 100644
--- a/admin/layouts/fieldtype/fields_fullwidth.php
+++ b/admin/layouts/fieldtype/fields_fullwidth.php
@@ -26,12 +26,20 @@ if ($_return = $jinput->get('return', null, 'base64'))
 {
 	$return .= "&return=" . $_return;
 }
-// set the referral values
-$ref = ($id) ? "&ref=fieldtype&refid=" . $id . "&return=" . urlencode(base64_encode($return)) : "";
+// check if return value was set
+if (ComponentbuilderHelper::checkString($return))
+{
+	// set the referral values
+	$ref = ($id) ? "&ref=fieldtype&refid=" . $id . "&return=" . urlencode(base64_encode($return)) : "&return=" . urlencode(base64_encode($return));
+}
+else
+{
+	$ref = ($id) ? "&ref=fieldtype&refid=" . $id : "";
+}
 // set the create new URL
-$new = "index.php?option=com_componentbuilder&view=field&layout=edit".$ref;
+$new = "index.php?option=com_componentbuilder&view=fields&task=field.edit" . $ref;
 // set the create new and close URL
-$close_new = "index.php?option=com_componentbuilder&view=field&layout=edit";
+$close_new = "index.php?option=com_componentbuilder&view=fields&task=field.edit";
 // load the action object
 $can = ComponentbuilderHelper::getActions('field');
 
diff --git a/admin/layouts/server/linked_components_fullwidth.php b/admin/layouts/server/linked_components_fullwidth.php
index f7bea90a3..134bb2b45 100644
--- a/admin/layouts/server/linked_components_fullwidth.php
+++ b/admin/layouts/server/linked_components_fullwidth.php
@@ -26,8 +26,16 @@ if ($_return = $jinput->get('return', null, 'base64'))
 {
 	$return .= "&return=" . $_return;
 }
-// set the referral values
-$ref = ($id) ? "&ref=server&refid=" . $id . "&return=" . urlencode(base64_encode($return)) : "";
+// check if return value was set
+if (ComponentbuilderHelper::checkString($return))
+{
+	// set the referral values
+	$ref = ($id) ? "&ref=server&refid=" . $id . "&return=" . urlencode(base64_encode($return)) : "&return=" . urlencode(base64_encode($return));
+}
+else
+{
+	$ref = ($id) ? "&ref=server&refid=" . $id : "";
+}
 
 ?>
 <div class="form-vertical">
diff --git a/admin/models/import_joomla_components.php b/admin/models/import_joomla_components.php
index 4078fac51..8923b3cee 100644
--- a/admin/models/import_joomla_components.php
+++ b/admin/models/import_joomla_components.php
@@ -699,7 +699,7 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
 		// the array of tables to store
 		$tables = array(
 			'validation_rule', 'fieldtype', 'field', 'admin_view', 'snippet', 'dynamic_get', 'custom_admin_view', 'site_view',
-			'template', 'layout', 'joomla_component', 'language', 'language_translation', 'custom_code',
+			'template', 'layout', 'joomla_component', 'language', 'language_translation', 'custom_code', 'placeholder',
 			'admin_fields', 'admin_fields_conditions', 'admin_fields_relations',  'admin_custom_tabs', 'component_admin_views',
 			'component_site_views', 'component_custom_admin_views', 'component_updates', 'component_mysql_tweaks',
 			'component_custom_admin_menus', 'component_config', 'component_dashboard', 'component_files_folders',
@@ -2746,6 +2746,10 @@ class ComponentbuilderModelImport_joomla_components extends JModelLegacy
 						$retryAgain = 2;
 					}
 					break;
+				case 'placeholder':
+					// search for placeholder (since there should only be one)
+					$getter = 'target';
+					break;
 				case 'custom_code':
 					// search for custom code
 					$getter = array('comment_type', 'target');
diff --git a/admin/models/joomla_components.php b/admin/models/joomla_components.php
index 7871e8daf..ff3cf2fd7 100644
--- a/admin/models/joomla_components.php
+++ b/admin/models/joomla_components.php
@@ -66,6 +66,8 @@ class ComponentbuilderModelJoomla_components extends JModelList
 	protected $smartBox = array();
 	protected $smartIDs = array();
 	protected $customCodeM = array();
+	protected $placeholderM = array();
+	protected $placeholderS = array();
 	protected $fieldTypes = array();
 	protected $isMultiple = array();
 
@@ -254,7 +256,9 @@ class ComponentbuilderModelJoomla_components extends JModelList
 				// component image
 				$this->moveIt(array($item->image), 'image');
 				// set the custom code ID's
-				$this->setCustomCodeIds($item, 'joomla_component');
+				$this->setCodePlaceholdersIds($item, 'joomla_component');
+				// set the placeholder ID's
+				$this->setCodePlaceholdersIds($item, 'joomla_component', 'placeholder');
 				// set the language strings for this component
 				$this->setLanguageTranslation($item->id);
 				// load to global object
@@ -351,6 +355,11 @@ class ComponentbuilderModelJoomla_components extends JModelList
 			{
 				$this->setData('custom_code', array_values($this->smartIDs['custom_code']), 'id');
 			}
+			// add placeholder
+			if (isset($this->smartIDs['placeholder']) && ComponentbuilderHelper::checkArray($this->smartIDs['placeholder']))
+			{
+				$this->setData('placeholder', array_values($this->smartIDs['placeholder']), 'id');
+			}
 			// set limiter
 			$limit = 0;
 			// and add those custom codes found in custom codes
@@ -614,10 +623,14 @@ class ComponentbuilderModelJoomla_components extends JModelList
 				{
 					$this->smartIDs['layout'] = array();
 				}
-				elseif ('custom_code' === $table && 'id' === $key)
+				elseif ('custom_code' === $table && 'id' === $key && !isset($this->smartIDs['custom_code']))
 				{
 					$this->smartIDs['custom_code'] = array();
 				}
+				elseif ('placeholder' === $table && 'id' === $key && !isset($this->smartIDs['placeholder']))
+				{
+					$this->smartIDs['placeholder'] = array();
+				}
 				// start loading the data
 				if (!isset($this->smartBox[$table]))
 				{
@@ -666,7 +679,9 @@ class ComponentbuilderModelJoomla_components extends JModelList
 					// load to global object
 					$this->smartBox[$table][$item->id] = $item;
 					// set the custom code ID's
-					$this->setCustomCodeIds($item, $table);
+					$this->setCodePlaceholdersIds($item, $table);
+					// set the placeholder ID's
+					$this->setCodePlaceholdersIds($item, $table, 'placeholder');
 					// actions to take if table is component_files_folders
 					if ('component_files_folders' === $table && 'clone' !== $this->activeType)
 					{
@@ -866,7 +881,7 @@ class ComponentbuilderModelJoomla_components extends JModelList
 			// the array of tables to store
 			$tables = array(
 				'fieldtype', 'field', 'admin_view', 'snippet', 'dynamic_get', 'custom_admin_view', 'site_view',
-				'template', 'layout', 'joomla_component', 'language', 'language_translation', 'custom_code',
+				'template', 'layout', 'joomla_component', 'language', 'language_translation', 'custom_code', 'placeholder',
 				'admin_fields', 'admin_fields_conditions', 'admin_fields_relations',  'admin_custom_tabs', 'component_admin_views',
 				'component_site_views', 'component_custom_admin_views', 'component_updates', 'component_mysql_tweaks',
 				'component_custom_admin_menus', 'component_config', 'component_dashboard', 'component_files_folders',
@@ -1378,15 +1393,16 @@ class ComponentbuilderModelJoomla_components extends JModelList
 	}
 
 	/**
-	* Set the ids of the found custom code
+	* Set the ids of the found code placeholders
 	*
 	*  @param   object    $item   The item being searched
 	*  @param   string    $target  The target table
+	*  @param   string    $type    The type of placeholder to search and set
 	* 
 	*  @return  void
 	* 
 	*/
-	protected function setCustomCodeIds($item, $target)
+	protected function setCodePlaceholdersIds($item, $target, $type = 'custom_code')
 	{
 		if ($keys = $this->getCodeSearchKeys($target))
 		{
@@ -1415,35 +1431,70 @@ class ComponentbuilderModelJoomla_components extends JModelList
 					// search and open the base64 strings
 					$this->searchOpenBase64($value, $keys['base64_search'][$key]);
 				}
-				// search the value to see if it has custom code
-				$codeArray = ComponentbuilderHelper::getAllBetween($value, '[CUSTOMC' . 'ODE=',']');
-				if (ComponentbuilderHelper::checkArray($codeArray))
+				// based on the type of search
+				if ('custom_code' === $type)
 				{
-					foreach ($codeArray as $func)
+					// search the value to see if it has custom code
+					$codeArray = ComponentbuilderHelper::getAllBetween($value, '[CUSTOMC' . 'ODE=',']');
+					if (ComponentbuilderHelper::checkArray($codeArray))
 					{
-						// first make sure we have only the function key
-						if (strpos($func, '+') !== false)
+						foreach ($codeArray as $func)
 						{
-							$funcArray = explode('+', $func);
-							$func = $funcArray[0];
-						}
-						if (!isset($this->customCodeM[$func]))
-						{
-							$this->customCodeM[$func] = $func;
-							// if numeric add to ids
-							if (is_numeric($func))
+							// first make sure we have only the function key
+							if (strpos($func, '+') !== false)
 							{
-								$this->setSmartIDs($func, 'custom_code');
+								$funcArray = explode('+', $func);
+								$func = $funcArray[0];
 							}
-							elseif (ComponentbuilderHelper::checkString($func))
+							if (!isset($this->customCodeM[$func]))
 							{
-								if (($funcID = ComponentbuilderHelper::getVar('custom_code', $func, 'function_name', 'id')) !== false && is_numeric($funcID))
+								$this->customCodeM[$func] = $func;
+								// if numeric add to ids
+								if (is_numeric($func))
 								{
-									$this->setSmartIDs($funcID, 'custom_code');
+									$this->setSmartIDs($func, $type);
+								}
+								elseif (ComponentbuilderHelper::checkString($func))
+								{
+									if (($funcID = ComponentbuilderHelper::getVar($type, $func, 'function_name', 'id')) !== false && is_numeric($funcID))
+									{
+										$this->setSmartIDs($funcID, $type);
+									}
+									else
+									{
+										// set a notice that custom code was not found (weird)
+									}
+								}
+							}
+						}
+					}
+				}
+				elseif ('placeholder' === $type)
+				{
+					// check if we already have the placeholder search array
+					if (!componentbuilderHelper::checkArray($this->placeholderM) && !componentbuilderHelper::checkArray($this->placeholderS))
+					{
+						$this->placeholderS = ComponentbuilderHelper::getVars($type, 1, 'published', 'target');
+					}
+					// only continue search if placeholders found
+					if (componentbuilderHelper::checkArray($this->placeholderS))
+					{
+						foreach ($this->placeholderS as $remove => $placeholder)
+						{
+							// search the value to see if it has this placeholder and is not already set
+							if (!isset($this->placeholderM[$placeholder]) && strpos($value, $placeholder) !== false)
+							{
+								// add only once
+								$this->placeholderM[$placeholder] = $placeholder;
+								unset($this->placeholderS[$remove]);
+								// get the ID
+								if (($placeholderID = ComponentbuilderHelper::getVar($type, $placeholder, 'target', 'id')) !== false && is_numeric($placeholderID))
+								{
+									$this->setSmartIDs($placeholderID, $type);
 								}
 								else
 								{
-									// set a notice that custom code was not found
+									// set a notice that placeholder was not found (weird)
 								}
 							}
 						}
diff --git a/componentbuilder.xml b/componentbuilder.xml
index f50a76fe4..82f983921 100644
--- a/componentbuilder.xml
+++ b/componentbuilder.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <extension type="component" version="3.2" method="upgrade">
 	<name>COM_COMPONENTBUILDER</name>
-	<creationDate>23rd February, 2019</creationDate>
+	<creationDate>4th March, 2019</creationDate>
 	<author>Llewellyn van der Merwe</author>
 	<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
 	<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>
diff --git a/site/helpers/componentbuilder.php b/site/helpers/componentbuilder.php
index 812c5384c..3baf8e4d4 100644
--- a/site/helpers/componentbuilder.php
+++ b/site/helpers/componentbuilder.php
@@ -1209,7 +1209,7 @@ abstract class ComponentbuilderHelper
 					'message' => JText::_('COM_COMPONENTBUILDER_SORRY_THIS_PLACEHOLDER_IS_ALREADY_IN_USE'),
 					'status' => 'danger');
 			}
-			return false;			
+			return false;
 		}
 		// check if we must return boolean
 		if (!$bool)
@@ -4080,6 +4080,10 @@ abstract class ComponentbuilderHelper
 				{
 					$checked_out = (int) $item->checked_out;
 				}
+				else
+				{
+					$checked_out = self::getVar($view, $item->id, 'id', 'checked_out', '=', str_replace('com_', '', $component));
+				}
 			}
 			elseif (self::checkArray($item) && isset($item['id']))
 			{
@@ -4088,6 +4092,14 @@ abstract class ComponentbuilderHelper
 				{
 					$checked_out = (int) $item['checked_out'];
 				}
+				else
+				{
+					$checked_out = self::getVar($view, $item['id'], 'id', 'checked_out', '=', str_replace('com_', '', $component));
+				}
+			}
+			elseif (is_numeric($item) && $item > 0)
+			{
+				$checked_out = self::getVar($view, $item, 'id', 'checked_out', '=', str_replace('com_', '', $component));
 			}
 			// set the link title
 			$title = self::safeString(JText::_('COM_COMPONENTBUILDER_EDIT') . ' ' . $view, 'W');
@@ -4180,6 +4192,10 @@ abstract class ComponentbuilderHelper
 				{
 					$checked_out = (int) $item->checked_out;
 				}
+				else
+				{
+					$checked_out = self::getVar($view, $item->id, 'id', 'checked_out', '=', str_replace('com_', '', $component));
+				}
 			}
 			elseif (self::checkArray($item) && isset($item['id']))
 			{
@@ -4188,6 +4204,14 @@ abstract class ComponentbuilderHelper
 				{
 					$checked_out = (int) $item['checked_out'];
 				}
+				else
+				{
+					$checked_out = self::getVar($view, $item['id'], 'id', 'checked_out', '=', str_replace('com_', '', $component));
+				}
+			}
+			elseif (is_numeric($item) && $item > 0)
+			{
+				$checked_out = self::getVar($view, $item, 'id', 'checked_out', '=', str_replace('com_', '', $component));
 			}
 			// set the link title
 			$title = self::safeString(JText::_('COM_COMPONENTBUILDER_EDIT') . ' ' . $view, 'W');