Mercurial > hg > egg-tcls
comparison urllog.tcl @ 594:a488be0f45e0
urllog: More cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 28 Jan 2021 12:47:20 +0200 |
parents | ac72a228089b |
children | 7f7d8048ecb5 |
comparison
equal
deleted
inserted
replaced
593:3bd5a5e072ad | 594:a488be0f45e0 |
---|---|
134 | 134 |
135 return "\[ $urllog_shorturl_prefix[urllog_get_ss $u1][urllog_get_ss $u2][urllog_get_ss $u3] \]" | 135 return "\[ $urllog_shorturl_prefix[urllog_get_ss $u1][urllog_get_ss $u2][urllog_get_ss $u3] \]" |
136 } | 136 } |
137 | 137 |
138 | 138 |
139 proc urllog_chop_url {ustr} { | 139 proc urllog_chop_str {ustr umax} { |
140 global urllog_shorturl_max_orig | 140 if {[string length $ustr] > $umax} { |
141 | 141 return "[string range $ustr 0 $umax]..." |
142 if {[string length $ustr] > $urllog_shorturl_max_orig} { | |
143 return "[string range $ustr 0 $urllog_shorturl_max_orig]..." | |
144 } else { | 142 } else { |
145 return $ustr | 143 return $ustr |
146 } | 144 } |
147 } | 145 } |
148 | 146 |
149 | 147 |
150 proc urllog_chop_title {ustr} { | |
151 global urllog_title_max | |
152 | |
153 if {[string length $ustr] > $urllog_title_max} { | |
154 return "[string range $ustr 0 $urllog_title_max]..." | |
155 } else { | |
156 return $ustr | |
157 } | |
158 } | |
159 | |
160 | |
161 #------------------------------------------------------------------------- | 148 #------------------------------------------------------------------------- |
162 proc urllog_add_url {urlStr urlNick urlHost urlChan urlTitle} { | 149 proc urllog_add_url {urlStr urlNick urlHost urlChan urlTitle} { |
163 global urllog_db urllog_shorturl urllog_pub_channels | 150 global urllog_db urllog_shorturl_enable urllog_pub_channels |
151 global urllog_add_title_max urllog_add_url_max | |
164 | 152 |
165 | 153 |
166 ### Does the URL already exist? | 154 ### Does the URL already exist? |
167 set usql "SELECT id AS uid, utime AS utime, url AS uurl, user AS uuser, host AS uhost, chan AS uchan, title AS utitle FROM urls WHERE url='[utl_escape $urlStr]'" | 155 set usql "SELECT id AS uid, utime AS utime, url AS uurl, user AS uuser, host AS uhost, chan AS uchan, title AS utitle FROM urls WHERE url='[utl_escape $urlStr]'" |
168 urllog_db eval $usql { | 156 urllog_db eval $usql { |
169 urllog_log "URL said by $urlNick ($urlStr) already known" | 157 urllog_log "URL said by $urlNick ($urlStr) already known" |
170 | 158 |
171 if {[utl_match_delim_list $urllog_pub_channels $uchan]} { | 159 if {[utl_match_delim_list $urllog_pub_channels $uchan]} { |
172 if {$urllog_shorturl != 0} { | 160 if {$urllog_shorturl_enable != 0} { |
173 urllog_verb_msg 1 $urlNick $urlChan "url_known_short" [list $uuser $uchan $uhost [utl_ctime $utime] $utitle $uurl [urllog_get_short $uid]] | 161 urllog_verb_msg 1 $urlNick $urlChan "url_known_short" [list $uuser $uchan $uhost [utl_ctime $utime] $utitle $uurl [urllog_get_short $uid]] |
174 } else { | 162 } else { |
175 urllog_verb_msg 1 $urlNick $urlChan "url_known_long" [list $uuser $uchan $uhost [utl_ctime $utime] $utitle $uurl] | 163 urllog_verb_msg 1 $urlNick $urlChan "url_known_long" [list $uuser $uchan $uhost [utl_ctime $utime] $utitle $uurl] |
176 } | 164 } |
177 } | 165 } |
194 set uid [urllog_db last_insert_rowid] | 182 set uid [urllog_db last_insert_rowid] |
195 urllog_log "Added URL ($urlNick@$urlChan): $urlStr" | 183 urllog_log "Added URL ($urlNick@$urlChan): $urlStr" |
196 | 184 |
197 | 185 |
198 ### Let's say something, to confirm that everything went well. | 186 ### Let's say something, to confirm that everything went well. |
199 if {$urllog_shorturl != 0} { | 187 if {$urllog_shorturl_enable != 0} { |
200 set urlShort [urllog_get_short $uid] | 188 set urlShort [urllog_get_short $uid] |
201 set ushort "short" | 189 set ushort "short" |
202 } else { | 190 } else { |
203 set urlShort "" | 191 set urlShort "" |
204 set ushort "long" | 192 set ushort "long" |
208 set umode "url_added_${ushort}_has_title" | 196 set umode "url_added_${ushort}_has_title" |
209 } else { | 197 } else { |
210 set umode "url_added_${ushort}_no_title" | 198 set umode "url_added_${ushort}_no_title" |
211 } | 199 } |
212 | 200 |
213 urllog_verb_msg 1 $urlNick $urlChan $umode [list $urlTitle [urllog_chop_title $urlTitle] $urlStr [urllog_chop_url $urlStr] $urlShort] | 201 urllog_verb_msg 1 $urlNick $urlChan $umode [list $urlTitle [urllog_chop_str $urlTitle $urllog_add_title_max] $urlStr [urllog_chop_str $urlStr $urllog_add_url_max] $urlShort] |
214 return 1 | 202 return 1 |
215 } | 203 } |
216 | 204 |
217 | 205 |
218 #------------------------------------------------------------------------- | 206 #------------------------------------------------------------------------- |
279 } | 267 } |
280 | 268 |
281 | 269 |
282 #------------------------------------------------------------------------- | 270 #------------------------------------------------------------------------- |
283 proc urllog_validate_url { urlNick urlChan urlMStr urlMProto urlMHostName } { | 271 proc urllog_validate_url { urlNick urlChan urlMStr urlMProto urlMHostName } { |
284 global urllog_httprep urllog_shorturl_prefix urllog_shorturl | 272 global urllog_httprep urllog_shorturl_prefix urllog_shorturl_enable |
285 | 273 |
286 upvar $urlMStr urlStr | 274 upvar $urlMStr urlStr |
287 upvar $urlMProto urlProto | 275 upvar $urlMProto urlProto |
288 upvar $urlMHostName urlHostName | 276 upvar $urlMHostName urlHostName |
289 | 277 |
559 } | 547 } |
560 | 548 |
561 | 549 |
562 #------------------------------------------------------------------------- | 550 #------------------------------------------------------------------------- |
563 ### Parse arguments, find and show the results | 551 ### Parse arguments, find and show the results |
564 proc urllog_cmd_find {unick uhand uchan utext upublic} { | 552 proc urllog_cmd_search {unick uhand uchan utext upublic} { |
565 global urllog_db urllog_shorturl urllog_showmax_pub urllog_showmax_priv | 553 global urllog_db urllog_shorturl_enable urllog_showmax_pub urllog_showmax_priv |
554 global urllog_search_title_max urllog_search_url_max | |
566 | 555 |
567 if {$upublic == 0} { | 556 if {$upublic == 0} { |
568 set ulimit 5 | 557 set ulimit 5 |
569 } else { | 558 } else { |
570 set ulimit 3 | 559 set ulimit 3 |
603 ### Perform SQL query and show results if any | 592 ### Perform SQL query and show results if any |
604 set nresult 0 | 593 set nresult 0 |
605 set usql "SELECT id AS uid, utime AS utime, url AS uurl, user AS uuser, host AS uhost, title AS utitle FROM urls $fquery ORDER BY utime DESC LIMIT $ulimit" | 594 set usql "SELECT id AS uid, utime AS utime, url AS uurl, user AS uuser, host AS uhost, title AS utitle FROM urls $fquery ORDER BY utime DESC LIMIT $ulimit" |
606 urllog_db eval $usql { | 595 urllog_db eval $usql { |
607 incr nresult | 596 incr nresult |
608 if {[info exists $utitle] && [string length $utitle] > 0} { | 597 if {[string length $utitle] > 0} { |
609 set stitle [utl_str_map_values [urllog_qm "search_result_title"] [list $utitle [urllog_chop_title $utitle]]] | 598 set stitle [utl_str_map_values [urllog_qm "search_result_has_title"] [list $utitle [urllog_chop_str $utitle $urllog_search_title_max]]] |
610 } else { | 599 } else { |
611 set stitle [urllog_qm "search_result_no_title"] | 600 set stitle [urllog_qm "search_result_no_title"] |
612 } | 601 } |
613 | 602 |
614 if {$urllog_shorturl != 0 && $uid != ""} { | 603 if {$urllog_shorturl_enable != 0 && $uid != ""} { |
615 urllog_msg $upublic $unick $uchan "search_result_short" [list $nresult $uuser [utl_ctime $utime] $stitle [urllog_chop_url $uurl] [urllog_get_short $uid]] | 604 urllog_msg $upublic $unick $uchan "search_result_short" [list $nresult $uuser [utl_ctime $utime] $stitle [urllog_chop_str $uurl $urllog_search_url_max] [urllog_get_short $uid]] |
616 } else { | 605 } else { |
617 urllog_msg $upublic $unick $uchan "search_result_long" [list $nresult $uuser [utl_ctime $utime] $stitle $uurl] | 606 urllog_msg $upublic $unick $uchan "search_result_long" [list $nresult $uuser [utl_ctime $utime] $stitle $uurl] |
618 } | 607 } |
619 } | 608 } |
620 | 609 |
627 } | 616 } |
628 | 617 |
629 | 618 |
630 #------------------------------------------------------------------------- | 619 #------------------------------------------------------------------------- |
631 ### Finding binded functions | 620 ### Finding binded functions |
632 proc urllog_cmd_pub_find {unick uhost uhand uchan utext} { | 621 proc urllog_cmd_pub_search {unick uhost uhand uchan utext} { |
633 global urllog_search_channels | 622 global urllog_search_channels |
634 | 623 |
635 if {[utl_match_delim_list $urllog_search_channels $uchan]} { | 624 if {[utl_match_delim_list $urllog_search_channels $uchan]} { |
636 return [urllog_cmd_find $unick $uhand $uchan $utext 1] | 625 return [urllog_cmd_search $unick $uhand $uchan $utext 1] |
637 } | 626 } |
638 return 0 | 627 return 0 |
639 } | 628 } |
640 | 629 |
641 | 630 |
642 proc urllog_cmd_msg_find {unick uhost uhand utext} { | 631 proc urllog_cmd_msg_search {unick uhost uhand utext} { |
643 return [urllog_cmd_find $unick $uhand "" $utext 0] | 632 return [urllog_cmd_search $unick $uhand "" $utext 0] |
644 } | 633 } |
645 | 634 |
646 | 635 |
647 #------------------------------------------------------------------------- | 636 #------------------------------------------------------------------------- |
648 # Script initialization | 637 # Script initialization |