Improved the field builder around JCB, moved some xml function into the JCB helper class core

This commit is contained in:
2018-04-08 08:12:18 +02:00
parent 6a77d71095
commit 10fdac5d60
38 changed files with 1123 additions and 472 deletions

View File

@ -250,7 +250,8 @@ class Get
'Joomla' . '.JText._(',
'JText:' . ':script(',
'JText:' . ':_(',
'JText:' . ':sprintf('
'JText:' . ':sprintf(',
'JustTEXT:' . ':_('
);
/**
@ -3568,11 +3569,11 @@ class Get
/**
* Set Language Place Holders
*
*
* @param string $content The content
*
* @return string The content with the updated Language place holder
*
*
*/
public function setLangStrings($content)
{
@ -3591,11 +3592,17 @@ class Get
{
// insure string is not broken
$content = str_replace('COM_###COMPONENT###', $this->langPrefix, $content);
// first get the Joomla.JText._()
// reset some buckets
$langHolders = array();
$langCheck = array();
$langOnly = array();
$jsTEXT = array();
$scTEXT = array();
// first get the Joomla .JText._()
if (in_array('Joomla' . '.JText._(', $langStringTargets))
{
$jsTEXT[] = ComponentbuilderHelper::getAllBetween($content, "Joomla" . ".JText._('", "'");
$jsTEXT[] = ComponentbuilderHelper::getAllBetween($content, 'Joomla.' . 'JText._("', '"');
$jsTEXT[] = ComponentbuilderHelper::getAllBetween($content, 'Joomla' . '.JText._("', '"');
// combine into one array
$jsTEXT = ComponentbuilderHelper::mergeArrays($jsTEXT);
// we need to add a check to insure these JavaScript lang matchup
@ -3621,50 +3628,89 @@ class Get
$this->langMatch = ComponentbuilderHelper::mergeArrays(array($scTEXT, $this->langMatch));
}
}
// now do the little trick for JustTEXT: :_('Just uppercase text');
if (in_array('JustTEXT:' . ':_(', $langStringTargets))
{
$langOnly[] = ComponentbuilderHelper::getAllBetween($content, "JustTEXT:" . ":_('", "')");
$langOnly[] = ComponentbuilderHelper::getAllBetween($content, 'JustTEXT:' . ':_("', '")');
}
// set language data
foreach ($langStringTargets as $langStringTarget)
{
// need some special treatment here
if ($langStringTarget === 'Joomla' . '.JText._(' || $langStringTarget === 'JText:' . ':script(')
if ($langStringTarget === 'Joomla' . '.JText._(' ||
$langStringTarget === 'JText:' . ':script(' ||
$langStringTarget === 'JustTEXT:' . ':_(')
{
continue;
}
$langCheck[] = ComponentbuilderHelper::getAllBetween($content, $langStringTarget . "'", "'");
$langCheck[] = ComponentbuilderHelper::getAllBetween($content, $langStringTarget . '"', '"');
}
$langArray = ComponentbuilderHelper::mergeArrays($langCheck);
if (ComponentbuilderHelper::checkArray($langArray)) //<-- not really needed hmmm
// the normal loading of the language strings
$langCheck = ComponentbuilderHelper::mergeArrays($langCheck);
if (ComponentbuilderHelper::checkArray($langCheck)) //<-- not really needed hmmm
{
foreach ($langArray as $string)
foreach ($langCheck as $string)
{
// this is there to insure we dont break already added Language strings
if (ComponentbuilderHelper::safeString($string, 'U') === $string)
if ($keyLang = $this->setLang($string))
{
continue;
}
// only load if string is not already set
$keyLang = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($string, 'U');
if (!isset($this->langContent[$this->lang][$keyLang]))
{
$this->langContent[$this->lang][$keyLang] = trim($string);
}
// load the language targets
foreach ($langStringTargets as $langStringTarget)
{
$langHolders[$langStringTarget . "'" . $string . "'"] = $langStringTarget . "'" . $keyLang . "'";
$langHolders[$langStringTarget . '"' . $string . '"'] = $langStringTarget . '"' . $keyLang . '"';
// load the language targets
foreach ($langStringTargets as $langStringTarget)
{
$langHolders[$langStringTarget . "'" . $string . "'"] = $langStringTarget . "'" . $keyLang . "'";
$langHolders[$langStringTarget . '"' . $string . '"'] = $langStringTarget . '"' . $keyLang . '"';
}
}
}
// only continue if we have value to replace
if (isset($langHolders) && ComponentbuilderHelper::checkArray($langHolders))
}
// the uppercase loading only (for arrays and other tricks)
if (ComponentbuilderHelper::checkArray($langOnly))
{
$langOnly = ComponentbuilderHelper::mergeArrays($langOnly);
foreach ($langOnly as $string)
{
$content = $this->setPlaceholders($content, $langHolders);
if ($keyLang = $this->setLang($string))
{
// load the language targets
$langHolders["JustTEXT:" . ":_('" . $string . "')"] = "'" . $keyLang . "'";
$langHolders['JustTEXT:' . ':_("' . $string . '")'] = '"' . $keyLang . '"';
}
}
}
// only continue if we have value to replace
if (ComponentbuilderHelper::checkArray($langHolders))
{
$content = $this->setPlaceholders($content, $langHolders);
}
}
return $content;
}
/**
* Set the language String
*
* @param string $string The plan text string (English)
*
* @return string The key language string (all uppercase)
*
*/
public function setLang($string)
{
// this is there to insure we dont break already added Language strings
if (ComponentbuilderHelper::safeString($string, 'U') === $string)
{
return false;
}
// only load if string is not already set
$keyLang = $this->langPrefix . '_' . ComponentbuilderHelper::safeString($string, 'U');
if (!isset($this->langContent[$this->lang][$keyLang]))
{
$this->langContent[$this->lang][$keyLang] = trim($string);
}
return $keyLang;
}
/**
* Set Data Selection of the dynamic get
*

View File

@ -1369,6 +1369,8 @@ class Structure extends Get
// set new file to object
$versionData->move->static->$key_pointer = new stdClass();
$versionData->move->static->$key_pointer->naam = $custom['file'];
// update the dynamic component name placholders in file names
$custom['path'] = $this->setPlaceholders($custom['path'], $this->placeholders);
// get the path info
$pathInfo = pathinfo($custom['path']);
if (isset($pathInfo['extension']) && $pathInfo['extension'])

View File

@ -755,8 +755,8 @@ class Fields extends Structure
$XML = new simpleXMLElement('<a/>');
$fieldSetXML = $XML->addChild('fieldset');
$fieldSetXML->addAttribute('name', 'details');
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Default Fields.");
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Id Field. Type: Text (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Default Fields.");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Id Field. Type: Text (joomla)");
// if id is not set
if (!isset($this->fieldsNames[$view_name_single]['id']))
{
@ -770,7 +770,7 @@ class Fields extends Structure
'default' => 0
);
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
}
@ -787,9 +787,9 @@ class Fields extends Structure
'filter' => 'user_utc'
);
$attributes = array_merge($attributes, $readOnlyXML);
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Date Created Field. Type: Calendar (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Date Created Field. Type: Calendar (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
}
@ -803,9 +803,9 @@ class Fields extends Structure
'description' => $langView . '_CREATED_BY_DESC',
);
$attributes = array_merge($attributes, $readOnlyXML);
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " User Created Field. Type: User (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " User Created Field. Type: User (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
}
@ -818,9 +818,9 @@ class Fields extends Structure
'label' => 'JSTATUS'
);
$attributes = array_merge($attributes, $readOnlyXML);
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Published Field. Type: List (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Published Field. Type: List (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
foreach (array('JPUBLISHED' => 1, 'JUNPUBLISHED' => 0, 'JARCHIVED' => 2, 'JTRASHED' => -2) as $text => $value)
@ -844,9 +844,9 @@ class Fields extends Structure
'format' => '%Y-%m-%d %H:%M:%S',
'filter' => 'user_utc'
);
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Date Modified Field. Type: Calendar (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Date Modified Field. Type: Calendar (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
}
@ -862,9 +862,9 @@ class Fields extends Structure
'readonly' => 'true',
'filter' => 'unset'
);
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " User Modified Field. Type: User (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " User Modified Field. Type: User (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
}
@ -880,9 +880,9 @@ class Fields extends Structure
'required' => "false"
);
$attributes = array_merge($attributes, $readOnlyXML);
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Access Field. Type: Accesslevel (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Access Field. Type: Accesslevel (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
}
@ -900,9 +900,9 @@ class Fields extends Structure
'required' => "false"
);
$attributes = array_merge($attributes, $readOnlyXML);
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Ordering Field. Type: Numbers (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Ordering Field. Type: Numbers (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
}
@ -919,9 +919,9 @@ class Fields extends Structure
'readonly' => "true",
'filter' => 'unset'
);
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Version Field. Type: Text (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Version Field. Type: Text (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
}
@ -937,34 +937,34 @@ class Fields extends Structure
'rows' => 3,
'cols' => 30
);
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Metakey Field. Type: Textarea (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Metakey Field. Type: Textarea (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
// metadesc
$attributes['name'] = 'metadesc';
$attributes['label'] = 'JFIELD_META_DESCRIPTION_LABEL';
$attributes['description'] = 'JFIELD_META_DESCRIPTION_DESC';
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Metadesc Field. Type: Textarea (joomla)");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Metadesc Field. Type: Textarea (joomla)");
$fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes);
ComponentbuilderHelper::xmlAddAttributes($fieldXML, $attributes);
// count the static field created
$this->fieldCount++;
}
// load the dynamic fields now
if (count($dynamicFieldsXML))
{
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Dynamic Fields.");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Dynamic Fields.");
foreach ($dynamicFieldsXML as $dynamicfield)
{
$this->xmlAppend($fieldSetXML, $dynamicfield);
ComponentbuilderHelper::xmlAppend($fieldSetXML, $dynamicfield);
}
}
// check if metadata is added to this view
if (isset($this->metadataBuilder[$view_name_single]) && ComponentbuilderHelper::checkString($this->metadataBuilder[$view_name_single]))
{
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Metadata Fields");
ComponentbuilderHelper::xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Metadata Fields");
$fieldsXML = $fieldSetXML->addChild('fields');
$fieldsXML->addAttribute('name', 'metadata');
$fieldsXML->addAttribute('label', 'JGLOBAL_FIELDSET_METADATA_OPTIONS');
@ -972,7 +972,7 @@ class Fields extends Structure
$fieldsFieldSetXML->addAttribute('name', 'vdmmetadata');
$fieldsFieldSetXML->addAttribute('label', 'JGLOBAL_FIELDSET_METADATA_OPTIONS');
// robots
$this->xmlComment($fieldsFieldSetXML, $this->setLine(__LINE__) . " Robots Field. Type: List (joomla)");
ComponentbuilderHelper::xmlComment($fieldsFieldSetXML, $this->setLine(__LINE__) . " Robots Field. Type: List (joomla)");
$robots = $fieldsFieldSetXML->addChild('field');
$attributes = array(
'name' => 'robots',
@ -980,7 +980,7 @@ class Fields extends Structure
'label' => 'JFIELD_METADATA_ROBOTS_LABEL',
'description' => 'JFIELD_METADATA_ROBOTS_DESC'
);
$this->xmlAddAttributes($robots, $attributes);
ComponentbuilderHelper::xmlAddAttributes($robots, $attributes);
// count the static field created
$this->fieldCount++;
$options = array(
@ -997,7 +997,7 @@ class Fields extends Structure
$option[] = $text;
}
// author
$this->xmlComment($fieldsFieldSetXML, $this->setLine(__LINE__) . " Author Field. Type: Text (joomla)");
ComponentbuilderHelper::xmlComment($fieldsFieldSetXML, $this->setLine(__LINE__) . " Author Field. Type: Text (joomla)");
$author = $fieldsFieldSetXML->addChild('field');
$attributes = array(
'name' => 'author',
@ -1006,11 +1006,11 @@ class Fields extends Structure
'description' => 'JFIELD_METADATA_AUTHOR_DESC',
'size' => 20
);
$this->xmlAddAttributes($author, $attributes);
ComponentbuilderHelper::xmlAddAttributes($author, $attributes);
// count the static field created
$this->fieldCount++;
// rights
$this->xmlComment($fieldsFieldSetXML, $this->setLine(__LINE__) . " Rights Field. Type: Textarea (joomla)");
ComponentbuilderHelper::xmlComment($fieldsFieldSetXML, $this->setLine(__LINE__) . " Rights Field. Type: Textarea (joomla)");
$rights = $fieldsFieldSetXML->addChild('field');
$attributes = array(
'name' => 'rights',
@ -1022,7 +1022,7 @@ class Fields extends Structure
'cols' => 30,
'rows' => 2
);
$this->xmlAddAttributes($rights, $attributes);
ComponentbuilderHelper::xmlAddAttributes($rights, $attributes);
// count the static field created
$this->fieldCount++;
}
@ -1581,7 +1581,7 @@ class Fields extends Structure
}
elseif ($property === 'option')
{
$this->xmlComment($field->fieldXML, $this->setLine(__LINE__) . " Option Set.");
ComponentbuilderHelper::xmlComment($field->fieldXML, $this->setLine(__LINE__) . " Option Set.");
if (strpos($value, ',') !== false)
{
// mulitpal options
@ -1644,7 +1644,7 @@ class Fields extends Structure
}
if (!$field->fieldXML->count())
{
$this->xmlComment($field->fieldXML, $this->setLine(__LINE__) . " No Manual Options Were Added In Field Settings.");
ComponentbuilderHelper::xmlComment($field->fieldXML, $this->setLine(__LINE__) . " No Manual Options Were Added In Field Settings.");
}
}
elseif ($setType === 'plain')
@ -1733,12 +1733,12 @@ class Fields extends Structure
if ($this->defaultField($r_typeName, 'option'))
{
// now add to the field set
$this->xmlAppend($fieldSetXML, $this->setField('option', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
ComponentbuilderHelper::xmlAppend($fieldSetXML, $this->setField('option', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
}
elseif ($this->defaultField($r_typeName, 'plain'))
{
// now add to the field set
$this->xmlAppend($fieldSetXML, $this->setField('plain', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
ComponentbuilderHelper::xmlAppend($fieldSetXML, $this->setField('plain', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
}
elseif (ComponentbuilderHelper::checkArray($r_fieldValues['custom']))
{
@ -1746,7 +1746,7 @@ class Fields extends Structure
$custom = $r_fieldValues['custom'];
unset($r_fieldValues['custom']);
// now add to the field set
$this->xmlAppend($fieldSetXML, $this->setField('custom', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
ComponentbuilderHelper::xmlAppend($fieldSetXML, $this->setField('custom', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
// set lang (just incase)
$r_listLangName = $langView . '_' . ComponentbuilderHelper::safeString($r_name, 'U');
// add to lang array
@ -1794,7 +1794,7 @@ class Fields extends Structure
'name' => 'list_' . $fieldAttributes['name'] . '_modal',
'repeat' => 'true'
);
$this->xmlAddAttributes($form, $attributes);
ComponentbuilderHelper::xmlAddAttributes($form, $attributes);
if (strpos($fieldAttributes['fields'], ',') !== false)
{
@ -1830,12 +1830,12 @@ class Fields extends Structure
if ($this->defaultField($r_typeName, 'option'))
{
// now add to the field set
$this->xmlAppend($form, $this->setField('option', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
ComponentbuilderHelper::xmlAppend($form, $this->setField('option', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
}
elseif ($this->defaultField($r_typeName, 'plain'))
{
// now add to the field set
$this->xmlAppend($form, $this->setField('plain', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
ComponentbuilderHelper::xmlAppend($form, $this->setField('plain', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
}
elseif (ComponentbuilderHelper::checkArray($r_fieldValues['custom']))
{
@ -1843,7 +1843,7 @@ class Fields extends Structure
$custom = $r_fieldValues['custom'];
unset($r_fieldValues['custom']);
// now add to the field set
$this->xmlAppend($form, $this->setField('custom', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
ComponentbuilderHelper::xmlAppend($form, $this->setField('custom', $r_fieldValues, $r_name, $r_typeName, $langView, $view_name_single, $view_name_list, $placeholders, $r_optionArray));
// set lang (just incase)
$r_listLangName = $langView . '_' . ComponentbuilderHelper::safeString($r_name, 'U');
// add to lang array
@ -3030,78 +3030,6 @@ class Fields extends Structure
return false;
}
/**
* xmlComment
*
* @param SimpleXMLElement $xml The XML element reference in which to inject a comment
* @param string $comment The comment to inject
*
* @return null
*
*/
public function xmlComment(&$xml, $comment)
{
$domXML = dom_import_simplexml($xml);
$domComment = new DOMComment($comment);
$nodeTarget = $domXML->ownerDocument->importNode($domComment, true);
$domXML->appendChild($nodeTarget);
$xml = simplexml_import_dom($domXML);
}
/**
* xmlAddAttributes
*
* @param SimpleXMLElement $xml The XML element reference in which to inject a comment
* @param array $attributes The attributes to apply to the XML element
*
* @return null
*
*/
public function xmlAddAttributes(&$xml, $attributes = array())
{
foreach ($attributes as $key => $value)
{
$xml->addAttribute($key, $value);
}
}
/**
* xmlAppend
*
* @param SimpleXMLElement $xml The XML element reference in which to inject a comment
* @param mixed $node A SimpleXMLElement node to append to the XML element reference, or a stdClass object containing a comment attribute to be injected before the XML node and a fieldXML attribute containing a SimpleXMLElement
*
* @return null
*
*/
public function xmlAppend(&$xml, $node)
{
if (!$node)
{
// element was not returned
return;
}
switch (get_class($node))
{
case 'stdClass':
if (property_exists($node, 'comment'))
{
$this->xmlComment($xml, $node->comment);
}
if (property_exists($node, 'fieldXML'))
{
$this->xmlAppend($xml, $node->fieldXML);
}
break;
case 'SimpleXMLElement':
$domXML = dom_import_simplexml($xml);
$domNode = dom_import_simplexml($node);
$domXML->appendChild($domXML->ownerDocument->importNode($domNode, true));
$xml = simplexml_import_dom($domXML);
break;
}
}
/**
* xmlPrettyPrint
*