fieldset = 0; $this->html = ''; $this->xmpp = ''; } public function getHTML($xmpp){ $this->setXMPP($xmpp); $this->create(); return $this->html; } public function setXMPP($xmpp){ $this->xmpp = $xmpp; } public function create(){ $this->xmpp = str_replace('xmlns=', 'ns=', $this->xmpp); $x = new SimpleXMLElement($this->xmpp); foreach($x->children() as $element){ switch($element->getName()){ case "title": $this->outTitle($element); break; case "instructions": $this->outP($element); break; case "field": if($element['type'] != 'hidden' && $element['type'] != 'fixed') $this->html .='
'; switch($element['type']){ case "boolean": $this->outCheckbox($element); break; case "fixed": $this->outBold($element); break; case "text-single": $this->outInput($element, "", ""); break; case "text-multi": $this->outTextarea($element); break; case "text-private": $this->outInput($element, "password", ""); break; case "hidden": $this->outHiddeninput($element); break; case "list-multi": $this->outList($element, "multiple"); break; case "list-single": $this->outList($element, ""); break; case "jid-multi": $this->outInput($element, "email", "multiple"); break; case "jid-single": $this->outInput($element, "email", ""); break; default: $this->html .= ""; } if($element['type'] != 'hidden') $this->html .='
'; break; case 'url': break; /*XML without element*/ case 'username': case 'email': case 'password': $this->html .='
'; $this->outGeneric($element->getName()); $this->html .='
'; break; default: $this->html .= ""; } } if($this->fieldset>0){ $this->html .= ''; } } private function outGeneric($s){ $this->html .= ' '; } private function outTitle($s){ $this->html .= ' '; } private function outP($s){ $this->html .= ' '; } private function outUrl($s) { $this->html .= ' '.$s->getName().''; } private function outBold($s){ if($this->fieldset > 0){ $this->html .= ''; } $this->html .= '
'.$s->value.'
'; $this->fieldset ++; } private function outCheckbox($s){ $this->html .= '
'; } private function outTextarea($s){ $this->html .= ' '; $this->html .= ' '; } private function outInput($s, $type, $multiple){ if($s->required) $req = 'required'; $this->html .= ' html .= $value; } } $this->html .= '"'; if($s['var'] == 'username') $this->html .= ' pattern="[a-z0-9_-]*" '; $this->html .= ' type="'.$type.'" title="'.$s->desc.'" type="'.$s['type'].'" label="'.$s['label'].'" '.$multiple.' '.$req.'/> '; } private function outHiddeninput($s){ $this->html .= ' '; } private function outList($s, $multiple){ $this->html .= '
'; } } class FormtoXMPP{ private $stream; private $inputs; private $dataform; public function __construct(){ $this->stream = ''; $this->inputs = array(); $this->dataform = true; } public function getXMPP($stream, $inputs){ $this->setXMPP($stream); $this->setInputs($inputs); $this->create(); return $this->stream; } public function setXMPP($stream){ $this->stream = new SimpleXMLElement($stream); } public function setInputs($inputs){ $this->inputs = $inputs; } public function setDataformOff() { $this->dataform = false; } public function create(){ switch($this->stream->getName()){ case "stream": $node = $this->stream->iq->query->x; break; case "pubsub": $node = $this->stream->configure->x; break; case "command": $node = $this->stream->x; break; default: $node = $this->stream->x; break; } foreach($this->inputs as $key => $value) { if($value === '' && $this->stream->getName() == "stream") { RPC::call('movim_reload', Route::urlize('account','datamissing')); RPC::commit(); exit; } elseif(substr($key, 0, 8) == 'generic_') { $key = str_replace('generic_', '', $key); if (!is_string($value)) { $value = $value->value; } $node->addChild($key, $value); } elseif($value->attributes) { $field = $node->addChild('field'); if($value == 'true' || $value === 1) $value = '1'; if($value == 'false' || $value === 0) $value = '0'; $field->addChild('value', trim($value->value)); if(isset($value->attributes->required)) $field->addChild('required', ''); $field->addAttribute('var', $value->attributes->name); $field->addAttribute('type', $value->attributes->xmpptype); $field->addAttribute('label', $value->attributes->xmpplabel); } else{ $field = $node->addChild('field'); if($value == 'true') $value = '1'; if($value == 'false') $value = '0'; if(is_bool($value)) { $value = ($value) ? '1' : '0'; } $field->addChild('value', trim($value)); $field->addAttribute('var', trim($key)); } } } } ?>