/** * set the type definition from an xml structure * * @param string xml definition * @param string (byref) variable for failure message * @return boolean setting successful */ public function setXML($a_xml, &$a_failure_message) { global $lng; $this->plugin_object->includeClass('class.ilExternalContentEncodings.php'); $doc = new DOMDocument('1.0'); $doc->formatOutput = true; if (!@$doc->loadXML($a_xml)) { $err = error_get_last(); $a_failure_message = $err[message]; return false; } if (!($interface = $this->getDomChildByName($doc, 'interface'))) { $a_failure_message = $this->txt('type_failure_interfaces'); return false; } $launch_type = $interface->getAttribute('type'); switch ($launch_type) { case self::LAUNCH_TYPE_EMBED: case self::LAUNCH_TYPE_LINK: case self::LAUNCH_TYPE_PAGE: break; default: $a_failure_message = sprintf($this->txt('type_failure_launch_type'), $launch_type); return false; } if ($title_element = $this->getDomChildByName($interface, 'title')) { $title = $title_element->textContent; } if ($description_element = $this->getDomChildByName($interface, 'description')) { $description = $description_element->textContent; } if ($template_element = $this->getDomChildByName($interface, 'template')) { $template = $template_element->textContent; } if ($metasource_element = $this->getDomChildByName($interface, 'metasource')) { $metasource = $metasource_element->textContent; } $tmp_fields = array(); $fields = $interface->getElementsByTagName('field'); foreach ($fields as $field) { $tmp = (object) null; // basic properties $tmp->field_name = $field->getAttribute('name'); $tmp->field_type = $field->getAttribute('type'); // properties for input fields $tmp->required = $field->getAttribute('required'); $tmp->size = $field->getAttribute('size'); $tmp->rows = $field->getAttribute('rows'); $tmp->cols = $field->getAttribute('cols'); $tmp->richtext = $field->getAttribute('richtext'); $tmp->default = $field->getAttribute('default'); // appearance of input fields $tmp->parentfield = $field->getAttribute('parentfield'); $tmp->parentvalue = $field->getAttribute('parentvalue'); $tmp->level = $field->getAttribute('level') ? $field->getAttribute('level') : "object"; // processing properties $tmp->encoding = $field->getAttribute('encoding'); $tmp->function = $field->getAttribute('function'); // optional sub elements (field type specific) if ($title_element = $this->getDomChildByName($field, 'title')) { $tmp->title = $title_element->textContent; } if ($description_element = $this->getDomChildByName($field, 'description')) { $tmp->description = $description_element->textContent; } if ($template_element = $this->getDomChildByName($field, 'template')) { $tmp->template = $template_element->textContent; } // set options for radio fields $tmp->options = array(); foreach ($field->getElementsByTagName('option') as $option) { $opt = (object) null; $opt->value = $option->getAttribute('value'); $opt->title = $this->getDomChildByName($option, 'title')->textContent; $opt->description = $this->getDomChildByName($option, 'description')->textContent; $tmp->options[$opt->value] = $opt; } // set parameters for function fields $tmp->params = array(); foreach ($field->getElementsByTagName('param') as $param) { $tmp->params[$param->getAttribute('name')] = $param->textContent; } // checks field name if (!$tmp->field_name) { $a_failure_message = $this->txt('type_failure_field_name'); return false; } // check the field type switch ($tmp->field_type) { case self::FIELDTYPE_TEMPLATE: case self::FIELDTYPE_CALCULATED: case self::FIELDTYPE_TEXT: case self::FIELDTYPE_TEXTAREA: case self::FIELDTYPE_PASSWORD: case self::FIELDTYPE_CHECKBOX: case self::FIELDTYPE_RADIO: case self::FIELDTYPE_HEADER: case self::FIELDTYPE_DESCRIPTION: break; default: $a_failure_message = sprintf($this->txt('type_failure_field_type'), $tmp->field_type); return false; } // check the encoding if (!ilExternalContentEncodings::_encodingExists($tmp->encoding)) { $a_failure_message = sprintf($this->txt('type_failure_encoding'), $tmp->encoding); return false; } // all checks are ok $tmp_fields[] = $tmp; } // set the data if no error occurred $this->xml = $a_xml; $this->title = $title; $this->description = $description; $this->launch_type = $launch_type; $this->template = $template; $this->meta_data_url = $metasource; $this->fields = $tmp_fields; return true; }
/** * Fill a field and return its value * * @param array field * @param int maximum recoursion depth * @return mixed field value (depending on type) */ private function fillField($a_field, $a_maxdepth = 100) { // check recursion or existing values if (0 > $a_maxdepth--) { return 'max depth reached!'; } elseif (isset($a_field['field_value'])) { //echo "<br />FOUND: ". $a_field['field_name'] . " = "; //var_dump($a_field['field_value']); return $a_field['field_value']; } // get field values that are not yet known switch ($a_field['field_type']) { case ilExternalContentType::FIELDTYPE_ILIAS: $value = $this->fillIliasField($a_field); break; case ilExternalContentType::FIELDTYPE_CALCULATED: $value = $this->fillCalculatedField($a_field, $a_maxdepth); break; case ilExternalContentType::FIELDTYPE_TEMPLATE: $value = $this->fillTemplateRec($a_field['template'], $a_maxdepth); break; } // apply an encoding to the value $value = ilExternalContentEncodings::_applyEncoding($a_field['encoding'], $value); // save the value so that it is not re-calculated $this->fields[$a_field['field_name']]['field_value'] = $value; //echo "<br />FILLED: ". $a_field['field_name'] . " = "; //var_dump($value); return $value; }