fixed unintended formating. tweaked functions. resolved gh-189

This commit is contained in:
Llewellyn van der Merwe 2017-12-04 16:56:18 +02:00
parent cc9a0e9c4c
commit 87ba078dc8
No known key found for this signature in database
GPG Key ID: CAD7B16D27AF28C5

View File

@ -1,5 +1,4 @@
<?php <?php
/**--------------------------------------------------------------------------------------------------------| www.vdm.io |------/ /**--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
__ __ _ _____ _ _ __ __ _ _ _ __ __ _ _____ _ _ __ __ _ _ _
\ \ / / | | | __ \ | | | | | \/ | | | | | | | \ \ / / | | | __ \ | | | | | \/ | | | | | | |
@ -34,351 +33,352 @@ class Fields extends Structure
{ {
/** /**
* Metadate Switch * Metadate Switch
* *
* @var array * @var array
*/ */
public $metadataBuilder = array(); public $metadataBuilder = array();
/** /**
* View access Switch * View access Switch
* *
* @var array * @var array
*/ */
public $accessBuilder = array(); public $accessBuilder = array();
/** /**
* edit view tabs counter * edit view tabs counter
* *
* @var array * @var array
*/ */
public $tabCounter = array(); public $tabCounter = array();
/** /**
* layout builder * layout builder
* *
* @var array * @var array
*/ */
public $layoutBuilder = array(); public $layoutBuilder = array();
/** /**
* used to fix the zero order * used to fix the zero order
* *
* @var array * @var array
*/ */
private $zeroOrderFix = array(); private $zeroOrderFix = array();
/** /**
* Site field data * Site field data
* *
* @var array * @var array
*/ */
public $siteFieldData = array(); public $siteFieldData = array();
/** /**
* Category other name bucket * Category other name bucket
* *
* @var array * @var array
*/ */
public $catOtherName = array(); public $catOtherName = array();
/** /**
* list of fields that are not being escaped * list of fields that are not being escaped
* *
* @var array * @var array
*/ */
public $doNotEscape = array(); public $doNotEscape = array();
/** /**
* tags builder * tags builder
* *
* @var array * @var array
*/ */
public $tagsBuilder = array(); public $tagsBuilder = array();
/** /**
* query builder * query builder
* *
* @var array * @var array
*/ */
public $queryBuilder = array(); public $queryBuilder = array();
/** /**
* unique keys for database field * unique keys for database field
* *
* @var array * @var array
*/ */
public $dbUniqueKeys = array(); public $dbUniqueKeys = array();
/** /**
* keys for database field * keys for database field
* *
* @var array * @var array
*/ */
public $dbKeys = array(); public $dbKeys = array();
/** /**
* history builder * history builder
* *
* @var array * @var array
*/ */
public $historyBuilder = array(); public $historyBuilder = array();
/** /**
* alias builder * alias builder
* *
* @var array * @var array
*/ */
public $aliasBuilder = array(); public $aliasBuilder = array();
/** /**
* title builder * title builder
* *
* @var array * @var array
*/ */
public $titleBuilder = array(); public $titleBuilder = array();
/** /**
* list builder * list builder
* *
* @var array * @var array
*/ */
public $listBuilder = array(); public $listBuilder = array();
/** /**
* custom Builder List * custom Builder List
* *
* @var array * @var array
*/ */
public $customBuilderList = array(); public $customBuilderList = array();
/** /**
* Hidden Fields Builder * Hidden Fields Builder
* *
* @var array * @var array
*/ */
public $hiddenFieldsBuilder = array(); public $hiddenFieldsBuilder = array();
/** /**
* INT Field Builder * INT Field Builder
* *
* @var array * @var array
*/ */
public $intFieldsBuilder = array(); public $intFieldsBuilder = array();
/** /**
* Dynamic Fields Builder * Dynamic Fields Builder
* *
* @var array * @var array
*/ */
public $dynamicfieldsBuilder = array(); public $dynamicfieldsBuilder = array();
/** /**
* Main text Builder * Main text Builder
* *
* @var array * @var array
*/ */
public $maintextBuilder = array(); public $maintextBuilder = array();
/** /**
* Custom Builder * Custom Builder
* *
* @var array * @var array
*/ */
public $customBuilder = array(); public $customBuilder = array();
/** /**
* Custom Field Links Builder * Custom Field Links Builder
* *
* @var array * @var array
*/ */
public $customFieldLinksBuilder = array(); public $customFieldLinksBuilder = array();
/** /**
* Set Script for User Switch * Set Script for User Switch
* *
* @var array * @var array
*/ */
public $setScriptUserSwitch = array(); public $setScriptUserSwitch = array();
/** /**
* Set Script for Media Switch * Set Script for Media Switch
* *
* @var array * @var array
*/ */
public $setScriptMediaSwitch = array(); public $setScriptMediaSwitch = array();
/** /**
* Category builder * Category builder
* *
* @var array * @var array
*/ */
public $categoryBuilder = array(); public $categoryBuilder = array();
/** /**
* Category Code builder * Category Code builder
* *
* @var array * @var array
*/ */
public $catCodeBuilder = array(); public $catCodeBuilder = array();
/** /**
* Check Box builder * Check Box builder
* *
* @var array * @var array
*/ */
public $checkboxBuilder = array(); public $checkboxBuilder = array();
/** /**
* Json String Builder * Json String Builder
* *
* @var array * @var array
*/ */
public $jsonStringBuilder = array(); public $jsonStringBuilder = array();
/** /**
* Json String Builder for return values to array * Json String Builder for return values to array
* *
* @var array * @var array
*/ */
public $jsonItemBuilderArray = array(); public $jsonItemBuilderArray = array();
/** /**
* Json Item Builder * Json Item Builder
* *
* @var array * @var array
*/ */
public $jsonItemBuilder = array(); public $jsonItemBuilder = array();
/** /**
* Base 64 Builder * Base 64 Builder
* *
* @var array * @var array
*/ */
public $base64Builder = array(); public $base64Builder = array();
/** /**
* Basic Encryption Builder * Basic Encryption Builder
* *
* @var array * @var array
*/ */
public $basicEncryptionBuilder = array(); public $basicEncryptionBuilder = array();
/** /**
* Advnaced Encryption Builder * Advnaced Encryption Builder
* *
* @var array * @var array
*/ */
public $advancedEncryptionBuilder = array(); public $advancedEncryptionBuilder = array();
/** /**
* Get Items Method List String Fix Builder * Get Items Method List String Fix Builder
* *
* @var array * @var array
*/ */
public $getItemsMethodListStringFixBuilder = array(); public $getItemsMethodListStringFixBuilder = array();
/** /**
* Get Items Method Eximport String Fix Builder * Get Items Method Eximport String Fix Builder
* *
* @var array * @var array
*/ */
public $getItemsMethodEximportStringFixBuilder = array(); public $getItemsMethodEximportStringFixBuilder = array();
/** /**
* Selection Translation Fix Builder * Selection Translation Fix Builder
* *
* @var array * @var array
*/ */
public $selectionTranslationFixBuilder = array(); public $selectionTranslationFixBuilder = array();
/** /**
* Sort Builder * Sort Builder
* *
* @var array * @var array
*/ */
public $sortBuilder = array(); public $sortBuilder = array();
/** /**
* Search Builder * Search Builder
* *
* @var array * @var array
*/ */
public $searchBuilder = array(); public $searchBuilder = array();
/** /**
* Filter Builder * Filter Builder
* *
* @var array * @var array
*/ */
public $filterBuilder = array(); public $filterBuilder = array();
/** /**
* Set Group Control * Set Group Control
* *
* @var array * @var array
*/ */
public $setGroupControl = array(); public $setGroupControl = array();
/** /**
* Set Field Names * Set Field Names
* *
* @var array * @var array
*/ */
public $fieldsNames = array(); public $fieldsNames = array();
/** /**
* Set unique Names * Set unique Names
* *
* @var array * @var array
*/ */
public $uniqueNames = array(); public $uniqueNames = array();
/** /**
* Default Fields * Default Fields
* *
* @var array * @var array
*/ */
public $defaultFields = array('created', 'created_by', 'modified', 'modified_by', 'published', 'ordering', 'access', 'version', 'hits', 'id'); public $defaultFields = array('created', 'created_by', 'modified', 'modified_by', 'published', 'ordering', 'access', 'version', 'hits', 'id');
/** /**
* Default Fields set to publishing * Default Fields set to publishing
* *
* @var array * @var array
*/ */
public $newPublishingFields = array(); public $newPublishingFields = array();
/** /**
* Default Fields set to publishing * Default Fields set to publishing
* *
* @var array * @var array
*/ */
public $movedPublishingFields = array(); public $movedPublishingFields = array();
/** /**
* Set the line number in comments * Set the line number in comments
* *
* @param int $nr The line number * @param int $nr The line number
* *
* @return void * @return void
* *
*/ */
private function setLine($nr) private function setLine($nr)
{ {
if ($this->debugLinenr) if ($this->debugLinenr)
{ {
return ' [Fields '.$nr.']'; return ' [Fields '.$nr.']';
} }
return ''; return '';
} }
/** /**
* set the Field set of a view * set the Field set of a view
* *
* @param array $view The view data * @param array $view The view data
* @param string $component The component name * @param string $component The component name
* *
* @return string The fields set in xml * @return string The fields set in xml
* *
*/ */
public function setFieldSet($view, $component) public function setFieldSet($view, $component)
{ {
@ -868,45 +868,45 @@ class Fields extends Structure
/** /**
* set a field * set a field
* *
* @param string $setType The set of fields type * @param string $setType The set of fields type
* @param array $fieldAttributes The field values * @param array $fieldAttributes The field values
* @param string $name The field name * @param string $name The field name
* @param string $typeName The field type * @param string $typeName The field type
* @param string $langView The language string of the view * @param string $langView The language string of the view
* @param string $viewName The singel view name * @param string $viewName The single view name
* @param string $listViewName The list view name * @param string $listViewName The list view name
* @param array $placeholders The place holder and replace values * @param array $placeholders The place holder and replace values
* @param string $optionArray The option bucket array used to set the field options if needed. * @param string $optionArray The option bucket array used to set the field options if needed.
* @param arra $custom Used when field is from config * @param array $custom Used when field is from config
* *
* @return SimpleXMLElement The field in xml * @return SimpleXMLElement The field in xml
* *
*/ */
private function setField($setType, &$fieldAttributes, &$name, &$typeName, &$langView, &$viewName, &$listViewName, $placeholders, &$optionArray, $custom = null) private function setField($setType, &$fieldAttributes, &$name, &$typeName, &$langView, &$viewName, &$listViewName, $placeholders, &$optionArray, $custom = null)
{ {
$r = new stdClass(); $field = new stdClass();
if ($setType === 'option') if ($setType === 'option')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)";
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'option') if ($property != 'option')
{ {
$r->fieldXML->addAttribute($property, $value); $field->fieldXML->addAttribute($property, $value);
} }
elseif ($property === 'option') elseif ($property === 'option')
{ {
$this->xmlComment($r->fieldXML, $this->setLine(__LINE__) . " Option Set."); $this->xmlComment($field->fieldXML, $this->setLine(__LINE__) . " Option Set.");
if (strpos($value, ',') !== false) if (strpos($value, ',') !== false)
{ {
// mulitpal options // mulitpal options
$options = explode(',', $value); $options = explode(',', $value);
foreach ($options as $option) foreach ($options as $option)
{ {
$optionXML = $r->fieldXML->addChild('option'); $optionXML = $field->fieldXML->addChild('option');
if (strpos($option, '|') !== false) if (strpos($option, '|') !== false)
{ {
// has other value then text // has other value then text
@ -934,7 +934,7 @@ class Fields extends Structure
else else
{ {
// one option // one option
$optionXML = $r->fieldXML->addChild('option'); $optionXML = $field->fieldXML->addChild('option');
if (strpos($value, '|') !== false) if (strpos($value, '|') !== false)
{ {
// has other value then text // has other value then text
@ -960,36 +960,36 @@ class Fields extends Structure
} }
} }
} }
if (!$r->fieldXML->count()) if (!$field->fieldXML->count())
{ {
$this->xmlComment($r->fieldXML, $this->setLine(__LINE__) . " No Manual Options Were Added In Field Settings."); $this->xmlComment($field->fieldXML, $this->setLine(__LINE__) . " No Manual Options Were Added In Field Settings.");
} }
} }
elseif ($setType === 'plain') elseif ($setType === 'plain')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)";
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'option') if ($property != 'option')
{ {
$r->fieldXML->addAttribute($property, $value); $field->fieldXML->addAttribute($property, $value);
} }
} }
} }
elseif ($setType === 'spacer') elseif ($setType === 'spacer')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". A None Database Field. (joomla)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". A None Database Field. (joomla)";
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'option') if ($property != 'option')
{ {
$r->fieldXML->addAttribute($property, $value); $field->fieldXML->addAttribute($property, $value);
} }
} }
} }
@ -999,17 +999,17 @@ class Fields extends Structure
if ($typeName === 'repeatable') if ($typeName === 'repeatable')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (depreciated)";
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'fields') if ($property != 'fields')
{ {
$r->fieldXML->addAttribute($property, $value); $field->fieldXML->addAttribute($property, $value);
} }
} }
$fieldsXML = $r->fieldXML->addChild('fields'); $fieldsXML = $field->fieldXML->addChild('fields');
$fieldsXML->addAttribute('name', $fieldAttributes['name'] . '_fields'); $fieldsXML->addAttribute('name', $fieldAttributes['name'] . '_fields');
$fieldsXML->addAttribute('label', ''); $fieldsXML->addAttribute('label', '');
$fieldSetXML = $fieldsXML->addChild('fieldset'); $fieldSetXML = $fieldsXML->addChild('fieldset');
@ -1088,20 +1088,25 @@ class Fields extends Structure
elseif ($typeName === 'subform') elseif ($typeName === 'subform')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (joomla)";
// add all properties
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'fields') if ($property != 'fields' && $property != 'formsource')
{ {
$r->fieldXML->addAttribute($property, $value); $field->fieldXML->addAttribute($property, $value);
} }
} }
// if we do not detect formsource we add the form // if we detect formsource we do not add the form
if (!isset($fieldAttributes['formsource'])) if (isset($fieldAttributes['formsource']) && ComponentbuilderHelper::checkString($fieldAttributes['formsource']))
{ {
$form = $r->fieldXML->addChild('form'); $field->fieldXML->addAttribute('formsource', $fieldAttributes['formsource']);
}
// add the form
else
{
$form = $field->fieldXML->addChild('form');
$attributes = array( $attributes = array(
'hidden' => 'true', 'hidden' => 'true',
'name' => 'list_' . $fieldAttributes['name'] . '_modal', 'name' => 'list_' . $fieldAttributes['name'] . '_modal',
@ -1181,13 +1186,13 @@ class Fields extends Structure
elseif ($setType === 'custom') elseif ($setType === 'custom')
{ {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $field->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (custom)"; $field->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (custom)";
foreach ($fieldAttributes as $property => $value) foreach ($fieldAttributes as $property => $value)
{ {
if ($property != 'option') if ($property != 'option')
{ {
$r->fieldXML->addAttribute($property, $value); $field->fieldXML->addAttribute($property, $value);
} }
} }
// incase the field is in the config and has not been set // incase the field is in the config and has not been set
@ -1201,16 +1206,16 @@ class Fields extends Structure
$this->setCustomFieldTypeFile($data, $listViewName, $viewName); $this->setCustomFieldTypeFile($data, $listViewName, $viewName);
} }
} }
return $r; return $field;
} }
/** /**
* set the layout builder * set the layout builder
* *
* @param string $viewName The single edit view code name * @param string $viewName The single edit view code name
* @param string $tabName The tab code name * @param string $tabName The tab code name
* @param string $name The field code name * @param string $name The field code name
* @param array $field The field details * @param array $field The field details
* *
* @return void * @return void
* *
@ -1295,10 +1300,10 @@ class Fields extends Structure
/** /**
* build the site field data needed * build the site field data needed
* *
* @param string $view The single edit view code name * @param string $view The single edit view code name
* @param string $field The field name * @param string $field The field name
* @param string $set The decoding set this field belongs to * @param string $set The decoding set this field belongs to
* @param string $type The field type * @param string $type The field type
* *
* @return void * @return void
* *
@ -1346,7 +1351,7 @@ class Fields extends Structure
*/ */
private function setFieldAttributes(&$field, &$viewType, &$name, &$typeName, &$multiple, &$langLabel, $langView, &$spacerCounter, $listViewName, $viewName, $placeholders, $repeatable = false) private function setFieldAttributes(&$field, &$viewType, &$name, &$typeName, &$multiple, &$langLabel, $langView, &$spacerCounter, $listViewName, $viewName, $placeholders, $repeatable = false)
{ {
// reset array` // reset array
$fieldAttributes = array(); $fieldAttributes = array();
$setCustom = false; $setCustom = false;
// setup joomla default fields // setup joomla default fields
@ -1469,7 +1474,7 @@ class Fields extends Structure
$name = $this->setPlaceholders($xmlValue, $placeholders); $name = $this->setPlaceholders($xmlValue, $placeholders);
} }
} }
elseif ($property['name'] === 'extension' || $property['name'] === 'directory') elseif ($property['name'] === 'extension' || $property['name'] === 'directory' || $property['name'] === 'formsource')
{ {
$xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); $xmlValue = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"');
// replace the placeholders // replace the placeholders
@ -1487,7 +1492,7 @@ class Fields extends Structure
// set the line number // set the line number
$phpLine = (int) str_replace('type_phpx_', '', $property['name']); $phpLine = (int) str_replace('type_phpx_', '', $property['name']);
// load the php for the custom field file // load the php for the custom field file
$fieldAttributes['custom']['php'][$phpLine] = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"'); $fieldAttributes['custom']['phpx'][$phpLine] = ComponentbuilderHelper::getBetween($field['settings']->xml, $property['name'] . '="', '"');
} }
elseif ($property['name'] === 'extends' && $setCustom) elseif ($property['name'] === 'extends' && $setCustom)
{ {
@ -1684,7 +1689,6 @@ class Fields extends Structure
protected function setUniqueNameKeeper(&$field, &$typeName, &$name, $viewName) protected function setUniqueNameKeeper(&$field, &$typeName, &$name, $viewName)
{ {
// setup a default field // setup a default field
$xml = new SimpleXMLElement($field['settings']->xml);
if (ComponentbuilderHelper::checkArray($field['settings']->properties)) if (ComponentbuilderHelper::checkArray($field['settings']->properties))
{ {
foreach ($field['settings']->properties as $property) foreach ($field['settings']->properties as $property)