DoctorD90

WebPFix.tcl

May 7th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 2.08 KB | None | 0 0
  1. ### WebPFix.tcl 1.2.0 mNct0SYj
  2.  
  3. #SUGGESTED
  4. # PBinSrc.tcl fMrtKqyq
  5. # TCLLoader.tcl smApj15u
  6.  
  7. #LICENSE
  8. # Copyright © 2013 Alberto Dietze "DoctorD90"
  9. #
  10. #    This program is free software: you can redistribute it and/or modify
  11. #    it under the terms of the GNU General Public License as published by
  12. #    the Free Software Foundation, either version 3 of the License, or
  13. #    (at your option) any later version.
  14. #
  15. #    This program is distributed in the hope that it will be useful,
  16. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. #    GNU General Public License for more details.
  19. #
  20. #    You should have received a copy of the GNU General Public License
  21. #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. # Full GPLv3 Text: http://www.gnu.org/licenses/gpl.txt
  24.  
  25. #PATERNITY
  26. #Coder: DoctorD90
  27. #Network: irc.OnlineGamesNet.net
  28. #Chan: #eHito
  29. #Script's List: www.EggTcl.tk
  30.  
  31. #PURPOSE
  32. #Check links like 'google.com' and add protocol and www.
  33. #Is possible choice type (www, m, wap, etc)
  34. #and protocol (http, ftp, irc, mail, etc)
  35.  
  36. #USAGE
  37. #Ex. [webpfix_adder "google.com"] => http://www.google.com
  38. #Ex. [webpfix_adder "google.com" "m" "ftp"] => ftp://m.google.com
  39. #By default is http and www
  40.  
  41.  
  42. ### DON'T EDIT ANYTHING BELOW ###
  43.  
  44. proc webpfix_adder {link {mod "www"} {ptc "http"}} {
  45.   if {[string length [string trim $ptc]] && ![string match -nocase "*://" $ptc]} {
  46.     append ptc "://"
  47.   }
  48.   if {[string length [string trim $mod]] && ![string match -nocase "*." $mod]} {
  49.     append mod "."
  50.   }
  51.   set m [string match -nocase "${mod}*" $link]
  52.   set p [string match -nocase "${ptc}*" $link]
  53.   set t [string match -nocase "${ptc}${mod}*" $link]
  54.   if {!$p && !$m} {
  55.     set fix "${ptc}${mod}"
  56.   } elseif {!$p && $m} {
  57.     set fix "${ptc}"
  58.   } elseif {$p && !$t} {
  59.     set fix "${ptc}${mod}"
  60.     set link [string range $link [string length $ptc] end]
  61.   } else {
  62.     set fix ""
  63.   }
  64.   return "${fix}$link"
  65. }
  66.  
  67. ###
  68. putlog "WebPFix.tcl LOADED"
Advertisement