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
*

View File

@ -1187,12 +1187,12 @@ abstract class ComponentbuilderHelper
);
/**
* Get the snippet contributor details
* Get the snippet contributor details
*
* @param string $filename The file name
* @param string $type The type of file
* @param string $filename The file name
* @param string $type The type of file
*
* @return array On success the contributor details
* @return array On success the contributor details
*
*/
public static function getContributorDetails($filename, $type = 'snippet')
@ -1245,11 +1245,11 @@ abstract class ComponentbuilderHelper
}
/**
* Get the library files
* Get the library files
*
* @param int $id The library id to target
* @param int $id The library id to target
*
* @return array On success the array of files that belong to this library
* @return array On success the array of files that belong to this library
*
*/
public static function getLibraryFiles($id)
@ -1579,12 +1579,12 @@ abstract class ComponentbuilderHelper
}
/**
* The zipper method
* The zipper method
*
* @param string $workingDIR The directory where the items must be zipped
* @param string $filepath The path to where the zip file must be placed
* @param string $workingDIR The directory where the items must be zipped
* @param string $filepath The path to where the zip file must be placed
*
* @return bool true On success
* @return bool true On success
*
*/
public static function zip($workingDIR, &$filepath)
@ -1630,13 +1630,13 @@ abstract class ComponentbuilderHelper
/**
* Write a file to the server
*
* @param string $path The path and file name where to safe the data
* @param string $data The data to safe
* Write a file to the server
*
* @param string $path The path and file name where to safe the data
* @param string $data The data to safe
*
* @return bool true On success
*
* @return bool true On success
*
*/
public static function writeFile($path, $data)
{
@ -1792,13 +1792,13 @@ abstract class ComponentbuilderHelper
}
/**
* get between
* get between
*
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
*
* @return string On success / empty string on failure
* @return string On success / empty string on failure
*
*/
public static function getBetween($content, $start, $end)
@ -1813,13 +1813,13 @@ abstract class ComponentbuilderHelper
}
/**
* get all between
* get all between
*
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
*
* @return array On success
* @return array On success
*
*/
public static function getAllBetween($content, $start, $end)
@ -2037,17 +2037,17 @@ abstract class ComponentbuilderHelper
}
/**
* Get the file path or url
*
* @param string $type The (url/path) type to return
* @param string $target The Params Target name (if set)
* @param string $fileType The kind of filename to generate (if not set no file name is generated)
* @param string $key The key to adjust the filename (if not set ignored)
* @param string $default The default path if not set in Params (fallback path)
* @param bool $createIfNotSet The switch to create the folder if not found
* Get the file path or url
*
* @param string $type The (url/path) type to return
* @param string $target The Params Target name (if set)
* @param string $fileType The kind of filename to generate (if not set no file name is generated)
* @param string $key The key to adjust the filename (if not set ignored)
* @param string $default The default path if not set in Params (fallback path)
* @param bool $createIfNotSet The switch to create the folder if not found
*
* @return string On success the path or url is returned based on the type requested
*
* @return string On success the path or url is returned based on the type requested
*
*/
public static function getFilePath($type = 'path', $target = 'filepath', $fileType = null, $key = '', $default = JPATH_SITE . '/images/', $createIfNotSet = true)
{
@ -2149,13 +2149,13 @@ abstract class ComponentbuilderHelper
/**
* get the content of a file
*
* @param string $path The path to the file
* @param string/bool $none The return value if no content was found
* get the content of a file
*
* @param string $path The path to the file
* @param string/bool $none The return value if no content was found
*
* @return string On success
*
* @return string On success
*
*/
public static function getFileContents($path, $none = '')
{
@ -3183,6 +3183,19 @@ abstract class ComponentbuilderHelper
return false;
}
/**
* Get a Variable
*
* @param string $table The table from which to get the variable
* @param string $where The value where
* @param string $whereString The target/field string where/name
* @param string $what The return field
* @param string $operator The operator between $whereString/field and $where/value
* @param string $main The component in which the table is found
*
* @return mix string/int/float
*
*/
public static function getVar($table, $where = null, $whereString = 'user', $what = 'id', $operator = '=', $main = 'componentbuilder')
{
if(!$where)
@ -3223,6 +3236,20 @@ abstract class ComponentbuilderHelper
return false;
}
/**
* Get array of variables
*
* @param string $table The table from which to get the variables
* @param string $where The value where
* @param string $whereString The target/field string where/name
* @param string $what The return field
* @param string $operator The operator between $whereString/field and $where/value
* @param string $main The component in which the table is found
* @param bool $unique The switch to return a unique array
*
* @return array
*
*/
public static function getVars($table, $where = null, $whereString = 'user', $what = 'id', $operator = 'IN', $main = 'componentbuilder', $unique = true)
{
if(!$where)
@ -3691,28 +3718,141 @@ abstract class ComponentbuilderHelper
return JAccess::getAssetRules(0);
}
/**
* 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 static function xmlAppend(&$xml, $node)
{
if (!$node)
{
// element was not returned
return;
}
switch (get_class($node))
{
case 'stdClass':
if (property_exists($node, 'comment'))
{
self::xmlComment($xml, $node->comment);
}
if (property_exists($node, 'fieldXML'))
{
self::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;
}
}
/**
* xmlComment
*
* @param SimpleXMLElement $xml The XML element reference in which to inject a comment
* @param string $comment The comment to inject
*
* @return null
*
*/
public static 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 static function xmlAddAttributes(&$xml, $attributes = array())
{
foreach ($attributes as $key => $value)
{
$xml->addAttribute($key, $value);
}
}
/**
* xmlAddOptions
*
* @param SimpleXMLElement $xml The XML element reference in which to inject a comment
* @param array $options The options to apply to the XML element
*
* @return void
*
*/
public static function xmlAddOptions(&$xml, $options = array())
{
foreach ($options as $key => $value)
{
$addOption = $xml->addChild('option');
$addOption->addAttribute('value', $key);
$addOption[] = $value;
}
}
/**
* Render Bool Button
*
* @param array $args All the args for the button
* 0) name
* 1) additional (options class) // not used at this time
* 2) default
* 3) yes (name)
* 4) no (name)
*
* @return string The input html of the button
*
*/
public static function renderBoolButton()
{
$args = func_get_args();
// check if there is additional button class
$additional = isset($args[1]) ? (string) $args[1] : ''; // not used at this time
// start the xml
$buttonXML = new SimpleXMLElement('<field/>');
// button attributes
$buttonAttributes = array(
'type' => 'radio',
'name' => isset($args[0]) ? self::htmlEscape($args[0]) : 'bool_button',
'label' => isset($args[0]) ? self::safeString(self::htmlEscape($args[0]), 'Ww') : 'Bool Button', // not seen anyway
'class' => 'btn-group',
'filter' => 'INT',
'default' => isset($args[2]) ? (int) $args[2] : 0);
// load the haskey attributes
self::xmlAddAttributes($buttonXML, $buttonAttributes);
// set the button options
$buttonOptions = array(
'1' => isset($args[3]) ? self::htmlEscape($args[3]) : 'JYES',
'0' => isset($args[4]) ? self::htmlEscape($args[4]) : 'JNO');
// load the button options
self::xmlAddOptions($buttonXML, $buttonOptions);
// get the radio element
$button = JFormHelper::loadFieldType('radio');
// setup the properties
$name = self::htmlEscape($args[0]);
$additional = isset($args[1]) ? (string) $args[1] : '';
$value = $args[2];
$yes = isset($args[3]) ? self::htmlEscape($args[3]) : 'JYES';
$no = isset($args[4]) ? self::htmlEscape($args[4]) : 'JNO';
// prepare the xml
$element = new SimpleXMLElement('<field name="'.$name.'" type="radio" class="btn-group"><option '.$additional.' value="0">'.$no.'</option><option '.$additional.' value="1">'.$yes.'</option></field>');
// run
$button->setup($element, $value);
$button->setup($buttonXML, $buttonAttributes['default']);
return $button->input;
}
/**