;IRcap8 591a60d7a72cbc893fa6aa6fb4df2464
alias JAB.DISCO {
  if (!$window(@jabdisco)) guiwin @Jabdisco c c 600 316 $s(32)
  %jabdisco.ls1 = 20 68 180 16 1 0 jabdiscoclick @jabdiscols1 arbol | window -hls @jabdiscols1
  if (!$1) llenalista | else clear @jabdiscols1
  guilista @jabdisco jabdisco.ls1 
  jabdiscoag
  window -wa @jabdisco
}

alias jabdiscoag {
  cuagi @jabdisco 230 50 340 244 gui $s(33)
  unset %jabdisco.bt %jabdisco.da*
  %jabdisco.tx = 20 50 180 jabdisco.s ! $+ $m(248)


  if $gettok($1-,2,8) == i {
    %jabdisco.ag = $gettok($1-,4,8)
    %jabdisco.agn = $gettok($1-,3,8)
    %jabdisco.agt = $gettok($1-,5,8)


    if (%jabdisco.agt == gateway) {
      %jabdisco.tx = %jabdisco.tx $+ |320 150 170 jabdisco.da1 $s(39) |320 170 170 jabdisco.da2 $s(40) |320 190 170 jabdisco.da3 $ma($m(204))
      %jabdisco.bt = 320 220 156 jabdiscoregtr $s(34)
      dibutext 320n @jabdisco verdana 9 244 254 $s(65)
      goto L1
    }

    if ($findtok(directory search,%jabdisco.agt,32)) {
      %jabdisco.tx = %jabdisco.tx $+ |320 150 170 jabdisco.da1 $ma($m(204)) |320 170 170 jabdisco.da2 $m(315) |320 190 170 jabdisco.da3 $s(35) |320 210 170 jabdisco.da4 e-mail
      %jabdisco.bt = 320 236 156 jabdiscojud $ma($m(9)) |360 264 76 url_http://www.jabberland.com Jabberland
      goto L1
    }

    drawtext -cnprb @jabdisco $gettok(%gui.cc,2,44) $gettok(%gui.cc,15,44) verdana 9 250 150 314 14 $s(36)
    :L1
    cuagr @jabdisco 250 130 300 2

    var %d = drawtext -cnprb @jabdisco $gettok(%gui.cc,2,44) $gettok(%gui.cc,15,44) verdana 9 250
    %d 70 314 14  $+ $s(33) $+ : %jabdisco.agn
    %d 90 314 14 JID: %jabdisco.ag
    %d 110 314 14   $+ $s(37) $+ : %jabdisco.agt
  }
  guidib @jabdisco
}


alias jabdiscoclick {
  jabdiscoag $3-
}

alias -l llenalista {
  var %w = @jabdiscols1 | clear %w
  aline %w ag $m(502) --1
  aline %w bg $s(38) --1
  var %i = 1
  bunset &inf
  :L1
  var %p = $bfind(&h,%i,<item) 
  if (%p > 0) { 
    var %f = $bfind(&h,%p,<item)
    if (%f > 0) {
      var %t = $bvar(&h,%p,900).text

      var %a = $pos(%t,jid=") , %id = $gettok($mid(%t,%a,100),2,34)
      var %a = $pos(%t,name=") , %na = $gettok($mid(%t,%a,100),2,34) | if (!%na) { %na = %id }
      var %t = b , %ca = N/A , %ic = 12 , %su = $gettok(%id,1,46)
      if (msn isin %su) || ($findtok(msn yahoo icq gadu gg aim,%su,32)) { var %ca = gateway , %t = a , %ic = 4 }
      if (conf isin %su) || ($findtok(muc irc,%su,32)) { var %ca = conference , %t = b , %ic = 8 }
      if (users isin %su) || ($findtok(user,%su,32)) { var %ca = directory , %t = b , %ic = 3 }
      if ($findtok(proxy,%su,32)) { var %ca = proxy , %t = b , %ic = 9 }

      aline %w %t $+ i $+ %na $+  $+ %id $+  $+ %ca $+  $+ %ic
      bset -t &inf $calc($bvar(&inf,0) + 1) <iq type="get" to=" $+ %id $+ " id="getagentinfo- $+ %id $+ " ><query xmlns="http://jabber.org/protocol/disco#info"/></iq>
      %i = $calc(%f + 1) | goto L1
    }
  }
  var %p = $bfind(&h,1,from=") , %t = $bvar(&h,$calc(%p + 6),500).text | %jabdisco.s = $gettok($gettok(%t,1,34),1,47) 
  sockwrite xmpp &inf | bunset &inf
}

alias jab.agentinfo {
  var %p = $bfind(&h,1, id="getagentinfo-) , %t = $bvar(&h,%p,900).text , %id = $gettok($mid(%t,18,100),1,34)

  var %p = $bfind(&h,1,<identity) , %t = $bvar(&h,%p,900).text
  var %a = $pos(%t,name=") , %na = $gettok($mid(%t,%a,100),2,34) | if (!%na) { %na = %id }
  var %a = $pos(%t,category=") , %ca = $gettok($mid(%t,%a,100),2,34) | if (!%ca) { %ca = n/a }
  var %a = $pos(%t,type=") , %ty = $gettok($mid(%t,%a,100),2,34) | if (!%ty) { %ty = n/a }

  if (%id == server) { aline @jabdiscols1 aag %jabdisco.s --1 | aline @jabdiscols1 aai %na  %ty  %ca 3 }

  var %i = 3 | if (%ca == conference) { %i = 8 } | if (%ca == proxy) { %i = 9 } | if (%ca == gateway) { %i = 4 }
  var %e = $fline(@jabdiscols1,*i* $+ %id $+ *,1)
  if (%e) { rline @jabdiscols1 %e $iif(%ca == gateway,a,b) $+ i $+ %na $+  $+ %id $+  $+ %ca $+  $+ %i }
  guilista @jabdisco jabdisco.ls1 | guidib @jabdisco
}


alias onedit.@jabdisco {
  if $1 == jabdisco.s { 
    jabdiscoag | clear @jabdiscols1 | guilista @jabdisco jabdisco.ls1 
    xm <iq id="getagent" type="get" to=" $+ %jabdisco.s $+ "><query xmlns="http://jabber.org/protocol/disco#items"/></iq><iq id="getagentinfo-server" type="get" to=" $+ %jabdisco.s $+ "><query xmlns="http://jabber.org/protocol/disco#info"/></iq>
  }
}


alias jabdiscoregtr {
  xmpp regagent %jabdisco.ag %jabdisco.da1 %jabdisco.da2 %jabdisco.da3
}

alias jabdiscojud {
  xm <iq type="set" to=" $+ %jabdisco.ag $+ " id="BUSCOGENTE"><query xmlns="jabber:iq:search"><nick> $+ $mrcjab(%jabdisco.da1) $+ </nick><first> $+ $mrcjab(%jabdisco.da2) $+ </first><last> $+ $mrcjab(%jabdisco.da3) $+ </last><email> $+ $mrcjab(%jabdisco.da4) $+ </email></query></iq>
}

alias jabdisco.cierra unset %jabdisco.* | window -c @jabdiscols1 | jabber2fin








alias JAB.auser {
  guiwin @Jabauser c c 436 200 $ma($m(506))

  %jabauser.tc = Jabber | %jabauser.tc1 = Jabber
  %jabauser.cb = 20 60 160 jabauser.tc Jabber! $+ $s(29)
  %jabauser.tx = 20 110 170 jabauser.id ! $+ $s(30)
  %jabauser.bt = 20 150 154 jabauser+ $ma($m(506))

  cuagi @jabauser 210 45 200 130 gui
  dibutext 190 @jabauser verdana 9 220 50 $s(31)

  guidib @jabauser | window -wa @jabauser
  var %i = 1
  :L1
  var %a = $hget(roster,%i).item
  if (%a) {
    if (@ !isin %a) {
      %jabauser.tc1 = $addtok(%jabauser.tc1,$gettok($hget(roster,%i).data,1,22) : %a,22)
    }
    inc %i | goto L1
  }
  %jabauser.cb = 20 60 160 jabauser.tc %jabauser.tc1 $+ ! $+ $s(29)
  guidib @jabauser
}
alias jabauser+ {
  var %r = $remove($gettok(%jabauser.tc,-1,58),$chr(32))
  if (%r == Jabber) { var %c = %jabauser.id }
  else { var %c = $replace(%jabauser.id,@,%) $+ @ $+ %r }
  if (@ !isin %c) { fallo | return }
  xmpp subscribe %c $gettok(%jab.ge,3,22) | xmppui rost1c %c
  unset %jabauser.id | guidib @jabauser
}


alias jabauser.cierra unset %jabauser.* | jabber2fin







alias JAB.vcard {
  var %p = $bfind(&h,1,from=") , %t = $bvar(&h,$calc(%p + 6),500).text | %vcard.de = $gettok($gettok(%t,1,34),1,47)
  if ($window(@vcard)) { window @vcard $window(@vcard).x $window(@vcard).y 454 360 | guiwin @vCard x x 454 360 }
  else guiwin @vCard c c 454 360

  %vcard.fn = $vtag(fn)
  %vcard.jabberid = $vtag(jabberid) | if (!%vcard.jabberid) { %vcard.jabberid = %vcard.de }
  %vcard.fn = $vtag(fn)
  %vcard.given = $vtag(given,n)
  %vcard.family = $vtag(family,n)
  %vcard.nickname = $vtag(nickname)
  %vcard.bday = $vtag(bday)
  %vcard.street = $vtag(street,adr) 
  %vcard.extadr = $vtag(extadr,adr) 
  %vcard.ctry = $vtag(ctry,adr)
  %vcard.locality = $vtag(locality,adr)
  %vcard.region = $vtag(region,adr)
  %vcard.pcode = $vtag(pcode,adr)
  %vcard.number = $vtag(number,tel)
  %vcard.userid = $vtag(userid,email)
  %vcard.title = $vtag(title)
  %vcard.role = $vtag(role)
  %vcard.orgname = $vtag(orgname,org)
  %vcard.orgunit = $vtag(orgunit,org)
  %vcard.url = $vtag(url)
  %vcard.desc = $strip($vtag(desc))
  if (!%vcard.given) { %vcard.given = %vcard.fn }

  %vcard.pñ1 = 28 56 1 vcard.pest $s(42)  $s(43)  $s(44)  $s(45)
  vcard.pest 1

  window -wa @vcard

  %vcard.foto = $vcardfoto
  vcard.pest 1
  titula @vcard %vcard.de
}

alias vcard.pest {
  cuag @vcard 16 56 420 254 gui | pestana @vcard vcard.pñ1 | %vcard.bt =

  if $1 == 1 {
    cuagi @vcard 286 70 136 140 $gettok(%gui.cc,1,32)
    %vcard.tx = 88 76 176 vcard.given $ma($m(315)) |88 96 176 vcard.family $s(35) |88 116 152 vcard.nickname Nick|88 148 176 vcard.bday $s(46) |88 168 176 vcard.ctry $s(47) |88 188 176 vcard.locality $s(48) |88 220 176 vcard.number $s(49) |88 240 152 vcard.url Web|88 260 176 vcard.userid e-mail|88 280 176 vcard.jabberid JabberID
    %vcard.bt = 244 236 8 vcard.vurl >
    if (%vcard.de != $gettok(%ujabber,1,32)) {
      %vcard.bt = %vcard.bt $+ |244 112 8 vcard.pnick >
      if (%vcard.foto) { %vcard.bt = %vcard.bt $+ |398 214 10 vcard.mfoto ! }
    }
    else { %vcard.bt = %vcard.bt $+ |284 214 52 vcard.mifoto_+ $ma($m(257)) |356 214 52 vcard.mifoto_- $ma($m(220))  }
    if ($gettok(%vcard.foto,2,46) isin jpg bmp png gif) { dibfoto @vcard 290 76 128 128 %vcard.foto }
  }
  if $1 == 2 {
    %vcard.tx = 88 76 330 vcard.street $s(50) |88 96 330 vcard.extadr |88 124 330 vcard.pcode $s(51) |88 148 330 vcard.locality $s(48) |88 172 330 vcard.region $s(52) |88 196 330 vcard.ctry $s(47)
  }
  if $1 == 3 {
    %vcard.tx = 88 76 330 vcard.orgname $s(53) |88 100 330 vcard.orgunit $s(54) |88 124 330 vcard.title $s(55) |88 148 330 vcard.role $s(56)
  }
  if $1 == 4 {
    %vcard.tx = 38 96 380 vcard.desc ! $+ $s(57)
  }
  if (%vcard.de == $gettok(%ujabber,1,32)) { %vcard.bt = %vcard.bt $+ |330 320 90 vcard.pub $s(58) }
  else { %vcard.bt = %vcard.bt $+ |340 320 80 jabprivado_ $+ %vcard.de $s(59) $iif((!$hget(roster,%vcard.de)),|220 320 100 vcard+ $ma($m(506))) }
  guidib @vcard
}


alias -l vtag var %a = $xmltagb(-,$1,$2) | if (%a) { var %t = $bvar(&h,$gettok(%a,1,32),$gettok(%a,2,32)).text | return $jabmrc(%t) }


alias vcardfoto {
  var %a = $xmltagB(&h,binval,photo)
  if (!%a) { var %a = $xmltagB(&h,photo) }
  if (!%a) { var %a = $xmltagB(&h,pict) }
  if (!%a) return

  bunset &foto
  bcopy &foto 1 &h $gettok(%a,1,32) $gettok(%a,2,32)
  .remove vcard.jpg | .remove vcard.bmp | .remove vcard.png | .remove vcard.gif

  var %i = 2 
  :L1
  var %a = $bfind(&foto,%i,$chr(10))
  if (%a == 0) { %a = $calc($bvar(&foto,0) + 1) }
  if ($calc(%a - %i) > 900) { bwrite vcard.jpg -1 -1 &foto | goto L2 }
  var %t = $bvar(&foto,%i,$calc(%a -%i)).text

  bunset &l 
  if (%t) {
    bset -t &l 1 %t
    bwrite vcard.jpg -1 -1 &l
    %i = %a | inc %i | if (%i < $bvar(&foto,0)) goto L1
  }
  :L2
  bunset &foto
  bunset &l 
  bread vcard.jpg 0 $file(vcard.jpg).size &l
  var %z = $decode(&l,mb)
  .remove vcard.jpg
  bwrite vcard.jpg -1 -1 &l

  var %a = $bvar(&l,1,6).text
  var %n
  if (ÿØÿà isincs %a) { %n = vcard.jpg }
  if (BM isincs %a) { %n = vcard.bmp | .rename vcard.jpg %n }
  if (PNG isincs %a) { %n = vcard.png | .rename vcard.jpg %n }
  if (GIF isincs %a) { %n = vcard.gif | .rename vcard.jpg %n }
  bunset &foto | bunset %l
  return %n
}


alias dibfoto {
  if (!$file($6).size) return
  var %h = $pic($6).height , %w = $pic($6).width , %fh = $calc(%h / $4) , %fw = $calc(%w / $5)
  var %f = %fh | if (%fw > %f) { %f = %fw } | if (%f < 1) { %f = 1 } | %w = $int($calc(%w / %f)) | %h = $int($calc(%h / %f))
  drawpic -sm $1 $int($calc(($2 + $4 / 2) - (%w / 2))) $int($calc(($3 + $5 / 2) - (%h / 2))) %w %h $6
}

alias scalafoto {
  window -c @scalafoto
  var %h = $pic($3).height , %w = $pic($3).width , %fh = $calc(%h / $2) , %fw = $calc(%w / $1)
  var %f = %fh | if (%fw > %f) { %f = %fw } | if (%f < 1) { %f = 1 } | %w = $int($calc(%w / %f)) | %h = $int($calc(%h / %f))
  window -ph +d @scalafoto 100 100 %w %h
  drawpic -sm @scalafoto 0 0 %w %h $3
  if (!$4) .remove %vcard.foto
  drawsave -q90 @scalafoto $iif(($4),$4,$gettok(%vcard.foto,1,46) $+ .jpg)
  window -c @scalafoto
}

alias vcard.mfoto {
  if (!$1) { smenu vcard.mfoto 100 $s(60)  $s(61)  $s(62) | return }
  if $1 == 1 { run %vcard.foto }
  if $1 == 2 {
    var %a = usr\avatar\ $+ $remove(%vcard.de,@,.) $+ .jpg
    scalafoto 80 80 %vcard.foto %a
    if (!$window(@jab> $+ %vcard.de)) jabprivado %vcard.de | background -p @jab> $+ %vcard.de %a
  }
  if $1 == 3 {
    var %f = $sfile(usr\avatar\) | if (%f) .copy %vcard.foto " $+ %f $+ . $+ $gettok(%vcard.foto,2,46) $+ "
  }
}

alias vcard.mifoto {
  if $1 == - { unset %vcard.foto | vcard.pest 1 | return }
  var %f = $dir=" $s(63) " [ usr\avatar\*.jpg ] | if (!%f) return
  var %e = $right(%f,3) | .remove vcard. $+ %e | .copy " $+ %f $+ " vcard. $+ %e | %vcard.foto = vcard. $+ %e
  if ($file(%vcard.foto).size > 10000) { scalafoto 128 128 %vcard.foto | %vcard.foto = vcard.jpg }
  vcard.pest 1
}


alias vcard.pub {
  bunset &p
  vs <iq type="set" id='SETVCARD'><vCard xmlns="vcard-temp">
  vs <N><GIVEN> $+ $mrcjab(%vcard.given) $+ </GIVEN><FAMILY> $+ $mrcjab(%vcard.family) $+ </FAMILY></N><FN> $+ $mrcjab(%vcard.given %vcard.family) $+ </FN>
  vs <NICKNAME> $+ $mrcjab(%vcard.nickname) $+ </NICKNAME>
  vs  <BDAY> $+ $mrcjab(%vcard.bday) $+ </BDAY>
  vs <ADR><STREET> $+ $mrcjab(%vcard.street) $+ </STREET><EXTADR> $+ $mrcjab(%vcard.extadr) $+ </EXTADR><CTRY> $+ $mrcjab(%vcard.ctry) $+ </CTRY>
  vs <LOCALITY> $+ $mrcjab(%vcard.locality) $+ </LOCALITY><REGION> $+ $mrcjab(%vcard.region) $+ </REGION><PCODE> $+ $mrcjab(%vcard.pcode) $+ </PCODE></ADR>
  vs <TEL><NUMBER> $+ $mrcjab(%vcard.number) $+ </NUMBER></TEL>
  vs <EMAIL><USERID> $+ $mrcjab(%vcard.userid) $+ </USERID></EMAIL>
  vs <TITLE> $+ $mrcjab(%vcard.title) $+ </TITLE>
  vs <ROLE> $+ $mrcjab(%vcard.role) $+ </ROLE>
  vs <ORG><ORGNAME> $+ $mrcjab(%vcard.orgname) $+ </ORGNAME><ORGUNIT> $+ $mrcjab(%vcard.orgunit) $+ </ORGUNIT></ORG>
  vs <URL> $+ $mrcjab(%vcard.url) $+ </URL>
  vs <DESC> $+ $mrcjab(%vcard.desc) $+ </DESC>
  if (%vcard.foto) {
    vs <PHOTO><BINVAL>
    bunset &l
    bread %vcard.foto 0 $file(%vcard.foto).size &l
    var %z = $encode(&l,mb)
    bcopy -c &p $calc($bvar(&p,0) + 1) &l 1 $bvar(&l,0)
    bunset &l
    vs </BINVAL></PHOTO>
  }

  vs </vCard></iq>
  sockwrite xmpp &p | bunset &p
}
alias -l vs bset -t &p $calc($bvar(&p,0) + 1) $1-

alias vcard.vurl url %vcard.url
alias vcard+ xmpp subscribe %vcard.de $gettok(%jab.ge,3,22) | xmppui rost1c %vcard.de
alias vcard.pnick {
  if (!%vcard.nickname) || (!$hget(roster,%vcard.de)) return
  $xmpp(nick,%vcard.de,%vcard.nickname,*) | xmppui rost1c %vcard.de | if ($window(@jab> $+ %vcard.de)) titlebar @jab> $+ %vcard.de %vcard.nickname
}


alias vcard.cierra if (%vcard.foto) .remove %vcard.foto | unset %vcard.* | jabber2fin








alias JAB.JUD {
  window -hls @jabjudls1 | clear @jabjudls1

  var %i = 1 , %co = 1
  :J1
  var %p = $bfind(&h,%i,<item) , %f = $bfind(&h,$calc(%p + 1),<item) | if (%f == 0) { %f = $bvar(&h,0) }
  if (%p != 0) {
    var %item = $bvar(&h,%p,$calc(%f - %p)).text

    var %a = $pos(%item,jid=") , %id = $gettok($mid(%item,%a,100),2,34)
    var %n = $jabmrc($xmltag(%item,nick)) | if (!%n) { %n = - }
    var %fi = $jabmrc($xmltag(%item,first)) | if (!%fi) { %fi = - }
    var %l = $jabmrc($xmltag(%item,last)) | if (!%l) { %l = - }
    var %m = $jabmrc($xmltag(%item,email)) | if (!%m) { %m = - }
    if (@ isin %n) && (@ !isin %m) { %a = %n | %n = %m | %m = %a }

    aline @jabjudls1 %id $+ $chr(8) $+ %n $+ $chr(8) $+ %fi %l $+ $chr(8) $+ %m
    inc %co
    %i = %f | goto J1
  }

  :LL
  if (!$window(@jabjud)) guiwin @jabJUD c c 600 400 $m(314)
  %jabjud.ls1 = 16 50 548 22 1 0 jabjudvcard @jabjudls1 0,190,270,420

  guilista @jabjud jabjud.ls1
  guitgrid @jabjud %jabjud.ls1 JID  Nick  $s(41)  e-mail
  %jabjud.bt = 20 366 120 jabjud+ $ma($m(506)) |170 366 60 jabjudvcard $ma($m(50))
  guidib @jabjud | window -wa @jabjud
}

alias jabjudvcard {
  if ($1 == 1) return
  var %a = $gettok($sline(@jabjudls1,1),1,8)
  if (%a) { xmppui info %a }
}
alias jabjud+ var %a = $gettok($sline(@jabjudls1,1),1,8) | if (%a) { xmpp subscribe %a $gettok(%jab.ge,3,22) | xmppui rost1c %a }


alias jabjud.cierra unset %jabjud.* | window -c @jabjudls1 | jabber2fin
alias -l S return $hget(jabber2,$1)
alias -l ma return $upper($left($1,1)) $+ $mid($1-,2,99)

on 1:load: if (!$s(p1)) { .hmake -s jabber2 | .hload jabber2 "lng\ $+ %idioma $+ \jabber.lnh" }

alias -l jabber2fin {
  if ($window(@jabdisco)) || ($window(@jabjud)) || ($window(@jabauser)) || ($window(@vcard)) return
  hfree jabber2
  .unload -rs jabber2.mrc
}

;EOF-dt
