Library manager implementation #195

Merged
Llewellyn merged 24 commits from staging into master 2017-12-12 13:31:16 +00:00
Showing only changes of commit c1675dbd30 - Show all commits

View File

@ -362,7 +362,8 @@ class Fields extends Structure {
* @return void * @return void
* *
*/ */
private function setLine($nr) { private function setLine($nr)
{
if ($this->debugLinenr) if ($this->debugLinenr)
{ {
return ' [Fields '.$nr.']'; return ' [Fields '.$nr.']';
@ -379,7 +380,8 @@ class Fields extends Structure {
* @return string The fields set in xml * @return string The fields set in xml
* *
*/ */
public function setFieldSet($view, $component) { public function setFieldSet($view, $component)
{
// setup the fieldset of this view // setup the fieldset of this view
if (isset($view['settings']->fields) && ComponentbuilderHelper::checkArray($view['settings']->fields)) if (isset($view['settings']->fields) && ComponentbuilderHelper::checkArray($view['settings']->fields))
{ {
@ -538,7 +540,8 @@ class Fields extends Structure {
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Published Field. Type: List (joomla)"); $this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Published Field. Type: List (joomla)");
$fieldXML = $fieldSetXML->addChild('field'); $fieldXML = $fieldSetXML->addChild('field');
$this->xmlAddAttributes($fieldXML, $attributes); $this->xmlAddAttributes($fieldXML, $attributes);
foreach(array('JPUBLISHED'=>1,'JUNPUBLISHED'=>0,'JARCHIVED'=>2,'JTRASHED'=>-2) as $text=>$value) { foreach (array('JPUBLISHED' => 1, 'JUNPUBLISHED' => 0, 'JARCHIVED' => 2, 'JTRASHED' => -2) as $text => $value)
{
$optionXML = $fieldXML->addChild('option'); $optionXML = $fieldXML->addChild('option');
$optionXML->addAttribute('value', $value); $optionXML->addAttribute('value', $value);
$optionXML[] = $text; $optionXML[] = $text;
@ -656,7 +659,8 @@ class Fields extends Structure {
if (count($dynamicFieldsXML)) if (count($dynamicFieldsXML))
{ {
$this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Dynamic Fields."); $this->xmlComment($fieldSetXML, $this->setLine(__LINE__) . " Dynamic Fields.");
foreach($dynamicFieldsXML as $dynamicfield) { foreach ($dynamicFieldsXML as $dynamicfield)
{
$this->xmlAppend($fieldSetXML, $dynamicfield); $this->xmlAppend($fieldSetXML, $dynamicfield);
} }
} }
@ -687,7 +691,8 @@ class Fields extends Structure {
'JGLOBAL_INDEX_NOFOLLOW' => 'index, nofollow', 'JGLOBAL_INDEX_NOFOLLOW' => 'index, nofollow',
'JGLOBAL_NOINDEX_NOFOLLOW' => 'noindex, nofollow', 'JGLOBAL_NOINDEX_NOFOLLOW' => 'noindex, nofollow',
); );
foreach($options as $text=>$value) { foreach ($options as $text => $value)
{
$option = $robots->addChild('option'); $option = $robots->addChild('option');
$option->addAttribute('value', $value); $option->addAttribute('value', $value);
$option[] = $text; $option[] = $text;
@ -734,7 +739,8 @@ class Fields extends Structure {
* *
* *
*/ */
public function setFieldsNames(&$view, &$name) { public function setFieldsNames(&$view, &$name)
{
$this->fieldsNames[$view][$name] = $name; $this->fieldsNames[$view][$name] = $name;
} }
@ -752,10 +758,11 @@ class Fields extends Structure {
* @param string $dbkey The the custom table key * @param string $dbkey The the custom table key
* @param boolean $build The switch to set the build option * @param boolean $build The switch to set the build option
* *
* @return string The complete field in xml * @return SimpleXMLElement The complete field in xml
* *
*/ */
public function setDynamicField(&$field, &$view, &$viewType, &$langView, &$viewName, &$listViewName, &$spacerCounter, &$placeholders, &$dbkey, $build) { public function setDynamicField(&$field, &$view, &$viewType, &$langView, &$viewName, &$listViewName, &$spacerCounter, &$placeholders, &$dbkey, $build)
{
if (isset($field['settings']) && ComponentbuilderHelper::checkObject($field['settings'])) if (isset($field['settings']) && ComponentbuilderHelper::checkObject($field['settings']))
{ {
// reset some values // reset some values
@ -772,12 +779,12 @@ class Fields extends Structure {
{ {
// set the array of field names // set the array of field names
$this->setFieldsNames($viewName,$fieldAttributes['name']); $this->setFieldsNames($viewName,$fieldAttributes['name']);
if ($this->defaultField($typeName, 'option')) if ($this->defaultField($typeName, 'option'))
{ {
//reset options array //reset options array
$optionArray = array(); $optionArray = array();
// now add to the field set // now add to the field set
$xmlElement = $this->setField('option', $fieldAttributes, $name, $typeName, $langView, $viewName, $listViewName, $placeholders, $optionArray); $xmlElement = $this->setField('option', $fieldAttributes, $name, $typeName, $langView, $viewName, $listViewName, $placeholders, $optionArray);
if ($build) if ($build)
{ {
@ -793,7 +800,6 @@ class Fields extends Structure {
$this->setBuilders($langLabel, $langView, $viewName, $listViewName, $name, $view, $field, $typeName, $multiple); $this->setBuilders($langLabel, $langView, $viewName, $listViewName, $name, $view, $field, $typeName, $multiple);
} }
// now add to the field set // now add to the field set
$xmlElement = $this->setField('plain', $fieldAttributes, $name, $typeName, $langView, $viewName, $listViewName, $placeholders, $optionArray); $xmlElement = $this->setField('plain', $fieldAttributes, $name, $typeName, $langView, $viewName, $listViewName, $placeholders, $optionArray);
} }
elseif ($this->defaultField($typeName, 'spacer')) elseif ($this->defaultField($typeName, 'spacer'))
@ -872,11 +878,11 @@ class Fields extends Structure {
* @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 arra $custom Used when field is from config
* *
* @return SimpleXMLElement The field as a SimpleXMLEflement * @return SimpleXMLElement The field in xml
* @return string 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(); $r = new stdClass();
if ($setType === 'option') if ($setType === 'option')
{ {
@ -953,7 +959,8 @@ class Fields extends Structure {
} }
} }
} }
if(!$r->fieldXML->count()) { if (!$r->fieldXML->count())
{
$this->xmlComment($r->fieldXML, $this->setLine(__LINE__) . " No Manual Options Were Added In Field Settings."); $this->xmlComment($r->fieldXML, $this->setLine(__LINE__) . " No Manual Options Were Added In Field Settings.");
} }
} }
@ -1175,7 +1182,6 @@ class Fields extends Structure {
// now add to the field set // now add to the field set
$r->fieldXML = new SimpleXMLElement('<field/>'); $r->fieldXML = new SimpleXMLElement('<field/>');
$r->comment = $this->setLine(__LINE__) . " " . ComponentbuilderHelper::safeString($name, 'F') . " Field. Type: " . ComponentbuilderHelper::safeString($typeName, 'F') . ". (custom)"; $r->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')
@ -1183,7 +1189,6 @@ class Fields extends Structure {
$r->fieldXML->addAttribute($property, $value); $r->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
if ('config' === $viewName && 'configs' === $listViewName) if ('config' === $viewName && 'configs' === $listViewName)
{ {
@ -1209,7 +1214,8 @@ class Fields extends Structure {
* @return void * @return void
* *
*/ */
public function setLayoutBuilder(&$viewName, &$tabName, &$name, &$field) { public function setLayoutBuilder(&$viewName,&$tabName,&$name,&$field)
{
// first fix the zero order // first fix the zero order
// to insure it lands before all the other fields // to insure it lands before all the other fields
// as zero is expected to behave // as zero is expected to behave
@ -1296,7 +1302,8 @@ class Fields extends Structure {
* @return void * @return void
* *
*/ */
public function buildSiteFieldData($view, $field, $set, $type) { public function buildSiteFieldData($view, $field, $set, $type)
{
$decode = array('json','base64','basic_encryption','advance_encryption'); $decode = array('json','base64','basic_encryption','advance_encryption');
$uikit = array('textarea','editor'); $uikit = array('textarea','editor');
if (isset($this->siteFields[$view][$field]) && ComponentbuilderHelper::checkArray($this->siteFields[$view][$field])) if (isset($this->siteFields[$view][$field]) && ComponentbuilderHelper::checkArray($this->siteFields[$view][$field]))
@ -1336,7 +1343,8 @@ class Fields extends Structure {
* @return array The field attributes * @return array The field attributes
* *
*/ */
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;
@ -1673,7 +1681,8 @@ class Fields extends Structure {
* @return void * @return void
* *
*/ */
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); $xml = new SimpleXMLElement($field['settings']->xml);
if (ComponentbuilderHelper::checkArray($field['settings']->properties)) if (ComponentbuilderHelper::checkArray($field['settings']->properties))
@ -1733,7 +1742,8 @@ class Fields extends Structure {
* @return void * @return void
* *
*/ */
protected function setUniqueNameCounter($name, $view) { protected function setUniqueNameCounter($name, $view)
{
if (!isset($this->uniqueNames[$view])) if (!isset($this->uniqueNames[$view]))
{ {
$this->uniqueNames[$view] = array(); $this->uniqueNames[$view] = array();
@ -1759,7 +1769,8 @@ class Fields extends Structure {
* @return string the name * @return string the name
* *
*/ */
protected function uniqueName($name, $view) { protected function uniqueName($name, $view)
{
// only increment if the field name is used multiple times // only increment if the field name is used multiple times
if (isset($this->uniqueNames[$view]['counter'][$name]) && $this->uniqueNames[$view]['counter'][$name] > 1) if (isset($this->uniqueNames[$view]['counter'][$name]) && $this->uniqueNames[$view]['counter'][$name] > 1)
{ {
@ -1777,6 +1788,7 @@ class Fields extends Structure {
return $name; return $name;
} }
/** /**
* set Builders * set Builders
* *
@ -1795,7 +1807,8 @@ class Fields extends Structure {
* @return void * @return void
* *
*/ */
public function setBuilders($langLabel, $langView, $viewName, $listViewName, $name, $view, $field, $typeName, $multiple, $custom = false, $options = false) { public function setBuilders($langLabel, $langView, $viewName, $listViewName, $name, $view, $field, $typeName, $multiple, $custom = false, $options = false)
{
if ($typeName === 'tag') if ($typeName === 'tag')
{ {
// set tags for this view but don't load to DB // set tags for this view but don't load to DB
@ -2103,7 +2116,8 @@ class Fields extends Structure {
$this->setLayoutBuilder($viewName, $tabName, $name, $field); $this->setLayoutBuilder($viewName, $tabName, $name, $field);
} }
public function setCustomFieldTypeFile($data, $viewName_list, $viewName_single) { public function setCustomFieldTypeFile($data, $viewName_list, $viewName_single)
{
// make sure it is not already been build // make sure it is not already been build
if (!isset($this->fileContentDynamic['customfield_'.$data['type']]) || !ComponentbuilderHelper::checkArray($this->fileContentDynamic['customfield_'.$data['type']])) if (!isset($this->fileContentDynamic['customfield_'.$data['type']]) || !ComponentbuilderHelper::checkArray($this->fileContentDynamic['customfield_'.$data['type']]))
{ {
@ -2229,7 +2243,8 @@ class Fields extends Structure {
* @return boolean if the field was found * @return boolean if the field was found
* *
*/ */
public function defaultField($type, $option = 'default') { public function defaultField($type, $option = 'default')
{
// list of default fields // list of default fields
// https://docs.joomla.org/Form_field // https://docs.joomla.org/Form_field
$defaults = array( $defaults = array(
@ -2271,7 +2286,8 @@ class Fields extends Structure {
return false; return false;
} }
public function xmlComment(&$xml,$comment) { public function xmlComment(&$xml, $comment)
{
$domXML = dom_import_simplexml($xml); $domXML = dom_import_simplexml($xml);
$domComment = new DOMComment($comment); $domComment = new DOMComment($comment);
$nodeTarget = $domXML->ownerDocument->importNode($domComment, true); $nodeTarget = $domXML->ownerDocument->importNode($domComment, true);
@ -2279,22 +2295,29 @@ class Fields extends Structure {
$xml = simplexml_import_dom($domXML); $xml = simplexml_import_dom($domXML);
} }
public function xmlAddAttributes(&$xml,$attributes=array()) { public function xmlAddAttributes(&$xml, $attributes = array())
foreach($attributes as $key=>$value) { {
foreach ($attributes as $key => $value)
{
$xml->addAttribute($key, $value); $xml->addAttribute($key, $value);
} }
} }
public function xmlAppend(&$xml,$node) { public function xmlAppend(&$xml, $node)
if(!$node) { // element was not returned {
if (!$node)
{ // element was not returned
return; return;
} }
switch(get_class($node)) { switch (get_class($node))
{
case 'stdClass': case 'stdClass':
if(property_exists($node,'comment')) { if (property_exists($node, 'comment'))
{
$this->xmlComment($xml, $node->comment); $this->xmlComment($xml, $node->comment);
} }
if(property_exists($node,'fieldXML')) { if (property_exists($node, 'fieldXML'))
{
$this->xmlAppend($xml, $node->fieldXML); $this->xmlAppend($xml, $node->fieldXML);
} }
break; break;
@ -2307,9 +2330,11 @@ class Fields extends Structure {
} }
} }
public function xmlPrettyPrint($xml,$nodename) { public function xmlPrettyPrint($xml, $nodename)
{
$dom = dom_import_simplexml($xml)->ownerDocument; $dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true; $dom->formatOutput = true;
return $dom->saveXML($dom->getElementsByTagName($nodename)->item(0)); return $dom->saveXML($dom->getElementsByTagName($nodename)->item(0));
} }
} }