Browse Source

- add group creation form

pull/16/head
Christine Ho 13 years ago
parent
commit
5844fb8c99
  1. 10
      system/Utils.php
  2. 41
      system/Widget/widgets/ServerNodes/ServerNodes.php
  3. 5
      system/Widget/widgets/Vcard/Vcard.php
  4. 35
      system/XMPPtoForm.php
  5. 2
      themes/movim/css/forms.css
  6. 1
      themes/movim/server.tpl

10
system/Utils.php

@ -661,6 +661,16 @@ function checkJid($jid)
return filter_var($jid, FILTER_VALIDATE_EMAIL); return filter_var($jid, FILTER_VALIDATE_EMAIL);
} }
function stringToUri($url) {
$url = utf8_decode($url);
$url = strtolower(strtr($url, utf8_decode('ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ()[]\'"~$&%*@ç!?;,:/\^¨€{}<>|+.- '), 'aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn -- c --- e --'));
$url = str_replace(' ', '', $url);
$url = str_replace('---', '-', $url);
$url = str_replace('--', '-', $url);
$url = trim($url,'-');
return $url;
}
function movim_log($log) { function movim_log($log) {
ob_start(); ob_start();
// var_dump($log); // var_dump($log);

41
system/Widget/widgets/ServerNodes/ServerNodes.php

@ -24,6 +24,8 @@ class ServerNodes extends WidgetCommon
{ {
$this->registerEvent('discoitems', 'onDiscoItems'); $this->registerEvent('discoitems', 'onDiscoItems');
$this->registerEvent('disconodes', 'onDiscoNodes'); $this->registerEvent('disconodes', 'onDiscoNodes');
$this->registerEvent('defaultconfig', 'onDefaultConfig');
$this->registerEvent('creationsuccess', 'onCreationSuccess');
} }
function onDiscoNodes($items) function onDiscoNodes($items)
@ -65,16 +67,55 @@ class ServerNodes extends WidgetCommon
RPC::call('movim_fill', 'servernodes', RPC::cdata($html)); RPC::call('movim_fill', 'servernodes', RPC::cdata($html));
RPC::commit(); RPC::commit();
} }
function onDefaultConfig($xml)
{
$html = '<form name="data">';
$form = new XMPPtoForm();
$html .= $form->getHTML($xml[0]->asXML());
$submit = $this->genCallAjax('ajaxSetConfigToNewGroup', "'".$xml[1]."'", "movim_parse_form('data')");
$html .= '<a class="button tiny icon" onclick="'.$submit.'">'.t("Send").'</a>';
$html .= '</form>';
RPC::call('movim_fill', 'newGroupForm', RPC::cdata($html));
RPC::commit();
}
function onCreationSuccess($xml)
{
$r = new moxl\GroupSetConfig();
$r->setTo($xml[0])->setNode($xml[1])->setData($xml[2])
->request();
}
function ajaxGetNodes($server) function ajaxGetNodes($server)
{ {
$r = new moxl\GroupServerGetNodes(); $r = new moxl\GroupServerGetNodes();
$r->setTo($server)->request(); $r->setTo($server)->request();
} }
function ajaxGetDefaultConfig($server)
{
$r = new moxl\GroupGetDefaultConfig();
$r->setTo($server)->request();
}
function ajaxSetConfigToNewGroup($server, $data)
{
//make a uri of the title
$uri = stringToUri($data['pubsub#title']);
$r = new moxl\GroupCreate();
$r->setTo($server)->setNode($uri)->setData($data)
->request();
}
function build() function build()
{ {
?> ?>
<a class="button tiny icon" onclick="<?php echo $this->genCallAjax('ajaxGetDefaultConfig', "'".$_GET['s']."'"); ?>"><?php echo t("Create a new group");?></a>
<div id="newGroupForm"></div>
<div class="tabelem protect red" id="servernodes" title="<?php echo t('Groups');?>"> <div class="tabelem protect red" id="servernodes" title="<?php echo t('Groups');?>">
<script type="text/javascript"><?php echo $this->genCallAjax('ajaxGetNodes', "'".$_GET['s']."'"); ?></script> <script type="text/javascript"><?php echo $this->genCallAjax('ajaxGetNodes', "'".$_GET['s']."'"); ?></script>
</div> </div>

5
system/Widget/widgets/Vcard/Vcard.php

@ -144,7 +144,7 @@ class Vcard extends WidgetBase
</div>'; </div>';
$html .= '<div class="element"> $html .= '<div class="element">
<label for="name">'.t('Email').'</label>
<label for="email">'.t('Email').'</label>
<input type="email" name="email" class="content" value="'.$me->email.'"> <input type="email" name="email" class="content" value="'.$me->email.'">
</div>'; </div>';
@ -326,7 +326,8 @@ class Vcard extends WidgetBase
function ajaxGetVcard() function ajaxGetVcard()
{ {
$r = new moxl\VcardGet(); $r = new moxl\VcardGet();
$r->setTo($this->user->getLogin())->request();
$r->setTo($this->user->getLogin())
->request();
} }
function build() function build()

35
system/XMPPtoForm.php

@ -23,7 +23,6 @@ class XMPPtoForm{
public function create(){ public function create(){
$this->xmpp = str_replace('xmlns=', 'ns=', $this->xmpp); $this->xmpp = str_replace('xmlns=', 'ns=', $this->xmpp);
$x = new SimpleXMLElement($this->xmpp); $x = new SimpleXMLElement($this->xmpp);
//foreach($iq->command[0]->x[0]->children() as $element){
foreach($x->children() as $element){ foreach($x->children() as $element){
switch($element->getName()){ switch($element->getName()){
case "title": case "title":
@ -33,6 +32,7 @@ class XMPPtoForm{
$this->outP($element); $this->outP($element);
break; break;
case "field": case "field":
$this->html .='<div class="element">';
switch($element['type']){ switch($element['type']){
case "boolean": case "boolean":
$this->outCheckbox($element); $this->outCheckbox($element);
@ -67,6 +67,7 @@ class XMPPtoForm{
default: default:
$this->html .= ""; $this->html .= "";
} }
$this->html .='</div>';
break; break;
/*XML without <x> element*/ /*XML without <x> element*/
case 'username': case 'username':
@ -85,7 +86,7 @@ class XMPPtoForm{
private function outGeneric($s){ private function outGeneric($s){
$this->html .= '<label for="'.$s.'">'.$s.'</label> $this->html .= '<label for="'.$s.'">'.$s.'</label>
<input name="'.$s.'" type="'.$s.'" required/><br />';;
<input name="'.$s.'" type="'.$s.'" required/>';;
} }
private function outTitle($s){ private function outTitle($s){
$this->html .= '<h1>'.$s.'</h1>'; $this->html .= '<h1>'.$s.'</h1>';
@ -115,7 +116,7 @@ class XMPPtoForm{
<input name="'.$s['var'].'" type="checkbox" '.$s->required; <input name="'.$s['var'].'" type="checkbox" '.$s->required;
if($s->value == "true" || $s->value == "1") if($s->value == "true" || $s->value == "1")
$this->html .= ' checked'; $this->html .= ' checked';
$this->html .= '/><br />';
$this->html .= '/>';
} }
private function outTextarea($s){ private function outTextarea($s){
@ -126,7 +127,7 @@ class XMPPtoForm{
$this->html .= $value; $this->html .= $value;
} }
} }
$this->html .= '</textarea><br />';
$this->html .= '</textarea>';
} }
private function outInput($s, $type, $multiple){ private function outInput($s, $type, $multiple){
@ -138,7 +139,7 @@ class XMPPtoForm{
} }
} }
$this->html .= '" type="'.$type.'" title="'.$s->desc.'" $this->html .= '" type="'.$type.'" title="'.$s->desc.'"
'.$multiple.' '.$s->required.'/><br />';
'.$multiple.' '.$s->required.'/>';
} }
private function outHiddeninput($s){ private function outHiddeninput($s){
@ -147,7 +148,7 @@ class XMPPtoForm{
private function outList($s, $multiple){ private function outList($s, $multiple){
$this->html .= '<label for="'.$s["var"].'">'.$s["label"].'</label> $this->html .= '<label for="'.$s["var"].'">'.$s["label"].'</label>
<select name="'.$s['var'].'" '.$multiple.' '.$s->required.'>';
<div class="select"><select name="'.$s['var'].'" '.$multiple.' '.$s->required.'>';
if(count($s->xpath('option')) > 0){ if(count($s->xpath('option')) > 0){
foreach($s->option as $option){ foreach($s->option as $option){
@ -164,7 +165,7 @@ class XMPPtoForm{
} }
} }
$this->html .= '</select><br />';
$this->html .= '</select></div>';
} }
} }
@ -185,22 +186,32 @@ class FormtoXMPP{
} }
public function setXMPP($stream){ public function setXMPP($stream){
$this->stream = $stream;
$this->stream = new SimpleXMLElement($stream);
} }
public function setInputs($inputs){ public function setInputs($inputs){
$this->inputs = $inputs; $this->inputs = $inputs;
} }
public function create(){ public function create(){
$this->stream = new SimpleXMLElement($this->stream);
switch($this->stream->getName()){
case "stream":
$node = $this->stream->iq->query;
break;
case "pubsub":
$node = $this->stream->configure->x;
break;
}
foreach($this->inputs as $key => $value) { foreach($this->inputs as $key => $value) {
if($value == '') {
if($value == '' && $this->stream->getName() == "stream") {
RPC::call('movim_reload', RPC::cdata(BASE_URI."index.php?q=account&err=datamissing")); RPC::call('movim_reload', RPC::cdata(BASE_URI."index.php?q=account&err=datamissing"));
RPC::commit(); RPC::commit();
exit; exit;
} }
else
$this->stream->iq->query->addChild($key, $value);
else{
$field = $node->addChild('field');
$field->addChild('value', $value);
$field->addAttribute('var', $key);
}
} }
} }
} }

2
themes/movim/css/forms.css

@ -171,7 +171,7 @@ form .element.simple > *:not(label):not(img):focus {
} }
.element input[type=checkbox] { .element input[type=checkbox] {
visibility: hidden;
/*visibility: hidden;*/
} }
.element .checkbox:after { .element .checkbox:after {

1
themes/movim/server.tpl

@ -17,7 +17,6 @@
<div id="center"> <div id="center">
<?php $this->widget('Tabs');?> <?php $this->widget('Tabs');?>
<?php //$this->widget('Wall');?>
<?php $this->widget('ServerNodes');?> <?php $this->widget('ServerNodes');?>
</div> </div>
</div> </div>

Loading…
Cancel
Save