Fortsetzung des .TCL Codes
PHP-Code:
proc rss::parse {content} {
regsub -all -- {n+|s+|t+} $content { } content
regsub -all -- {([&])} $content {1} content
set item 0
set news ""
while {[regexp -nocase -- {<item(s[^>]*?)?>(.+?)</item>} $content -> & value]} {
incr item
set title {n/a}
regexp -nocase -- {<title>(.+?)</title>} $value -> title
regexp -nocase -- {\<\!\[CDATA\[(.*?)\]\]\>} $title -> title
set link {n/a}
regexp -nocase -- {<link>(.+?)</link>} $value -> link
regexp -nocase -- {\<\!\[CDATA\[(.*?)\]\]\>} $link -> link
regsub -nocase -- {<item.*?>.+?</item>} $content {} content
lappend news "$item {$link} {$title}"
}
return [lsort -integer -unique -index 0 $news]
}
proc rss::decode {content} {
if {![regexp -- & $content]} {
return $content
}
set escapes {
\x20 " \x22 & \x26 ' \x27 – \x2D < \x3C > \x3E ˜ \x7E € \x80 ¡ \xA1
¢ \xA2 £ \xA3 ¤ \xA4 ¥ \xA5 ¦ \xA6 § \xA7 ¨ \xA8 © \xA9 ª \xAA « \xAB
¬ \xAC ­ \xAD ® \xAE &hibar; \xAF ° \xB0 ± \xB1 ² \xB2 ³ \xB3 ´ \xB4 µ \xB5
¶ \xB6 · \xB7 ¸ \xB8 ¹ \xB9 º \xBA » \xBB ¼ \xBC ½ \xBD ¾ \xBE ¿ \xBF
À \xC0 Á \xC1 Â \xC2 Ã \xC3 Ä \xC4 Å \xC5 Æ \xC6 Ç \xC7 È \xC8 É \xC9
Ê \xCA Ë \xCB Ì \xCC Í \xCD Î \xCE Ï \xCF Ð \xD0 Ñ \xD1 Ò \xD2 Ó \xD3
Ô \xD4 Õ \xD5 Ö \xD6 × \xD7 Ø \xD8 Ù \xD9 Ú \xDA Û \xDB Ü \xDC Ý \xDD
Þ \xDE ß \xDF à \xE0 á \xE1 â \xE2 ã \xE3 ä \xE4 å \xE5 æ \xE6 ç \xE7
è \xE8 é \xE9 ê \xEA ë \xEB ì \xEC í \xED î \xEE ï \xEF ð \xF0 ñ \xF1
ò \xF2 ó \xF3 ô \xF4 õ \xF5 ö \xF6 ÷ \xF7 ø \xF8 ù \xF9 ú \xFA û \xFB
ü \xFC ý \xFD þ \xFE ÿ \xFF
}
set content [string map $escapes $content]
regsub -all -- {&[a-zA-Z]+?;} [clean $content] {?} content
regsub -all -- {&#(\d{1,3});} $content {[format %c [scan \1 %d]]} content
return [subst $content]
}
proc rss::private {nickname hostname handle arguments} {
global feed
variable spam
variable protect
set arguments [clean $arguments]
set spewfeed [lindex $arguments 0]
if {![validfeed $spewfeed 1]} {
putquick "NOTICE $nickname :Please supply a valid feed: [join [lsort -dictionary [array names feed]] ",\x20"]"
return 0
}
set spewfeed [validfeed $spewfeed 2]
if {([info exists spam(flood,$spewfeed,$hostname)])} {
set s [expr [clock seconds] - $spam(flood,$spewfeed,$hostname)]
if {$s < $protect} {
putquick "NOTICE $nickname :Sorry - This trigger has recently been used. It will be unlocked in [expr $protect - $s] seconds."
return 0
}
}
set spam(flood,$spewfeed,$hostname) [clock seconds]
news $nickname $spewfeed 1
}
proc rss::public {nickname hostname handle channel arguments} {
global feed
variable spam
variable protect
set arguments [clean $arguments]
set spewfeed [lindex $arguments 0]
if {![validfeed $spewfeed 1]} {
putquick "PRIVMSG $channel :Please supply a valid feed: [join [lsort -dictionary -unique [array names feed]] ",\x20"]"
return 0
}
set spewfeed [validfeed $spewfeed 2]
if {([info exists spam(flood,$spewfeed,$channel)]) && (![isop $nickname $channel])} {
set s [expr [clock seconds] - $spam(flood,$spewfeed,$channel)]
if {$s < $protect} {
putquick "PRIVMSG $channel :Sorry - This trigger has recently been used. It will be unlocked in [expr $protect - $s] seconds."
return 0
}
}
set spam(flood,$spewfeed,$channel) [clock seconds]
set channels 0
foreach item [split $feed($spewfeed) \n] {
regsub -all -- {/\*.*\*/} $item {} item
regexp -nocase -- {^\s*CHANNELS=(.+?)\s*$} $item tmp channels
}
if {([lsearch -exact [string tolower $channels] [string tolower $channel]] == -1) && (![string equal -nocase $channels "ALL"])} {
putquick "PRIVMSG $channel :The \[$spewfeed\] feed is not available on this channel. ($channels)"
return 0
}
news $channel $spewfeed 2
}
proc rss::msg {channels headline} {
if {[string equal -nocase $channels "ALL"]} {
foreach channel [channels] {
if {[regexp -- {c} [getchanmode $channel]] && [regexp -- {\003} $headline]} {
lappend nocolors $channel
} else {
lappend colors $channel
}
}
} else {
foreach channel [channels] {
if {[lsearch -exact [string tolower $channels] [string tolower $channel]] >= 0} {
if {[regexp -- {c} [getchanmode $channel]] && [regexp -- {\003} $headline]} {
lappend nocolors $channel
} else {
lappend colors $channel
}
}
}
}
if {[info exists nocolors]} {
putquick "PRIVMSG [join $nocolors {,}] :[stripcodes c $headline]"
}
if {[info exists colors]} {
putquick "PRIVMSG [join $colors {,}] :$headline"
}
}
proc rss::validfeed {keyword type} {
global feed
foreach id [array names feed] {
if {[string equal -nocase $id $keyword]} {
switch -exact -- $type {
{1} {
return 1
}
{2} {
return $id
}
}
}
}
return 0
}
proc rss::upfirstchar {content} {
regsub -all -- {((^|\s)([a-z]))} [clean $content] {[string toupper "\1"]} content
return [subst $content]
}
proc rss::clean {string} {
regsub -all -- {([\(\)\[\]\{\}\$\"\\])} $string {\\\1} string
return $string
}
putlog "Script loaded: RSS feed parser $rss::version (C) 2004 perpleXa."
Lesezeichen