Request: Long URL replacement.

Moderator: GeekShed.Net Staff

Request: Long URL replacement.

Postby GrimReaper » Sat Jun 26, 2010 6:49 pm

This script was requested by Kyle.

Basically what it does is searches anything you type, If it see's a link either beginning with http:// or www. and uses a URL shortener to replace the link and shrink it.

Code: Select all
menu * {
  URL Replacer
  .$iif(%shrturl == On,$style(1)) URL Replacer
  ..$iif(%shrturl == On,$style(2)) On: set %shrturl on
  ..$iif(!%shrturl,$style(2)) Off: unset %shrturl
  -
}
on 1:input:*: {
  if (%shrturl == on) {
    if ($left($1,1) == /) { return }
    elseif (l0p.us iswm $1-) { return }
    else {
      haltdef
      var %a = $numtok($$1-,32)
      while (%a) {
        if (http:// isin $gettok($1-,%a,32)) || (www. isin $gettok($1-,%a,32)) {
          if ($sock(l0pus)) { .sockclose l0pus }
          else { sockopen l0pus www.l0p.us 80 }
          set %shrt.urlget $gettok($1-,%a,32)
          set %shrt.act $active
          set %shrt.msg $1-
          halt
          dec %a
        }
        else { dec %a }
      }
      msg $active $1-
    }
  }
}

on *:SockOpen:l0pus: {
  if ($sockerr) { echo -at Error connecting to l0p.us }
  else {
    sockwrite -nt l0pus GET $+(/api-make.php?alias=&url=,%shrt.urlget) HTTP/1.1
    sockwrite -n l0pus Host: www.l0p.us
    sockwrite -n l0pus $crlf
  }
}
on *:SockRead:l0pus: {
  var %read | sockRead  %read
  if (http://* iswm %read) {
    var %urlshort = %read
    msg %shrt.act $replace(%shrt.msg,%shrt.urlget,%urlshort)
    unset %shrt.*
  }
}


I will advise that any other on *:INPUT script's that you have loaded and working that you either turn them off or remove them as this will cause a double post.

I had a little help with it from a mate of mine called PuNkTuReD on another network. I have also tested it and it does work.
Last edited by GrimReaper on Tue Jun 29, 2010 5:04 pm, edited 1 time in total.
GrimReaper
 
Posts: 73
Joined: Wed Oct 28, 2009 4:34 pm
Location: In your router, Resetting your connection.

Re: Request: Long URL replacement.

Postby Henco » Mon Jun 28, 2010 7:57 pm

works perfectly for me, only thing is though, ya might want to except l0p.us, so if you paste a link that's already shortened, it won't shorten it twice :p
Henco
Henry Cole

"There are 2 ways to write error-free programs; only the 3rd one works"
Henco
 
Posts: 14
Joined: Tue Oct 27, 2009 12:18 am
Location: Suffolk, UK

Re: Request: Long URL replacement.

Postby GrimReaper » Tue Jun 29, 2010 5:05 pm

Updated previous code with the suggestion from Henco.

Let me know what you guy's think or if there are any way's that you'd like to see it improved.
GrimReaper
 
Posts: 73
Joined: Wed Oct 28, 2009 4:34 pm
Location: In your router, Resetting your connection.


Return to Script help

Who is online

Users browsing this forum: No registered users and 8 guests

cron