Rss Reader — File Browser
RssReaderv2.0 / RssReaderv2.0 / rss / rss.mrc
rss.mrc — 20.05 KB — Download this file
alias mdx {
var %dll = $scriptdir $+ mdx.dll
return $dll(%dll,$1,$2-)
}
alias hOS {
var %dll = $scriptdir $+ hOS.dll
return $dll(%dll,$1,$2-)
}
alias hDock {
var %dll = $scriptdir $+ UltraDock.dll
return $dll(%dll,$1,$2-)
}
alias mpop {
if ($isid) { return $dll(rss\mpopup.dll,$1,$2-) }
else { dll rss\mpopup.dll $1 $2- }
}
alias vdll {
return $scriptdir $+ views.mdx
}
dialog RssReaderBar {
title "Rss Reader"
size -1 -1 160 100
button "X",2, 2 2 18 18, flat
button "C",3, 2 20 18 18, flat
list 4, 23 3 163 120, size
list 6, 190 3 830 120, size
}
alias RssReader {
dialog -m RssReaderBar RssReaderBar
}
on *:dialog:RssReaderBar:init:0:{
;here it is loading the dll mdx. you can change this with the mark function in mdx.
mdx SetMircVersion $version
mdx MarkDialog $dname
mdx SetDialog $dname style
mdx SetControlMDX 4 treeview haslines hasbuttons linesatroot showsel > $vdll
mdx SetControlMDX 6 listview report rowselect showsel single labeltip headerdrag flatsb> $vdll
did -i $dname 6 1 headerdims 200 420 200
did -i $dname 6 1 headertext title $chr(9) Description $chr(9) Link
;hDock Dock -1 $dialog(RssReaderBar).hwnd bottom RssReaderBar
hOS Dock RssReaderBar bottom -1
; load from the ini file the rss url.
RssReaderBar.Load
}
;-----------------------------------------------------------------------
; Refresh button
;
; !!! warning!!! , if you're not a op, or the channel don't accept more than 3 line of text,
; u'll be kicked when echoing all this text to the channel.
;-----------------------------------------------------------------------
on 1:dialog:RssReaderBar:dclick:6: {
; retrieve the link from the listview control.
describe $active • Title : $ldid(RssReaderBar,6,1 )
describe $active • Descr : $ldid(RssReaderBar,6,2 )
describe $active • Link : $ldid(RssReaderBar,6,3 )
}
;-----------------------------------------------------------------------
; Refresh Rss news
;-----------------------------------------------------------------------
alias refresh {
Rss.Read $did-tree(RssReaderBar,4)
}
;-----------------------------------------------------------------------
; Display Rss news in the tree.
;-----------------------------------------------------------------------
alias display {
; erase the content of the listview.
did -r RssReaderBar 6
; scan the xml file, and put it in the listview.
rss.show $did-tree(RssReaderBar,4)
}
;-----------------------------------------------------------------------
; Undock dialog and close it.
;----------------------------------------------------------------------
alias closeRss {
hOS Undock RssReaderBar
dialog -x RssReaderBar
}
;-----------------------------------------------------------------------
; Close the RssReader Bar.
;-----------------------------------------------------------------------
on 1:dialog:RssReaderBar:sclick:2: {
CloseRss
}
;-----------------------------------------------------------------------
; Display Config Dialog where we could add ID and URL of the rss feed.
;-----------------------------------------------------------------------
on 1:dialog:RssReaderBar:sclick:3: {
rss.config
}
;-----------------------------------------------------------------------
; TreeView Simple click.
; Taken from Chaos v3.2
;-----------------------------------------------------------------------
on 1:dialog:RssReaderBar:sclick:4: {
set %tmp $did(4,1)
set %root $gettok(%tmp, 3-, 32)
if ($gettok(%tmp,1,32) = rclick) {
var %m = $mpop(MPCreateMenu,RssTreeMenu)
var %h = $gettok(%m,2,32)
var %m = $mpop(MPAddItem, %h > 1 0 0 $chr(160) Refresh > Refresh )
var %m = $mpop(MPAddItem, %h > 2 0 0 $chr(160) Display > display )
; var %m = $mpop(MPAddItem, %h > 3 0 0 - > -)
; var %m = $mpop(MPAddItem, %h > 4 0 0 $chr(160) Config > rss.config)
var %m = $mpop(MPopup, RssTreeMenu> $mouse.dx $mouse.dy left top right)
}
}
alias mdx-info {
var %dname, %did
if ($0 = 1) {
set %dname $dname
set %did $1
}
else {
set %dname $1
set %did $2
}
did -i %dname %did 1 page $prop
return $gettok($did(%dname, %did, 1), 3-, 32)
}
alias RssReaderBar.Load {
did -a RssReaderBar 4 +bce Programmation $chr(9) test
did -i RssReaderBar 4 1 cb 2
;--- Retrieve the url and their id from the ini file.
;--- Number of lines under the first section which is [url id]
%lines = $ini($+(",$scriptdir,url.ini,"),1,0)
;--- Setup the the hash table.
.hfree -ws IDUrl
.hmake -s IDUrl 50
;--- Iterate through the ini file, and display them in the tree view.
%iLoop = 1
while (%iLoop <= %lines) {
%col1 = $ini($+(",$scriptdir,url.ini,"),1,%iLoop)
%col2 = $readini($+(",$scriptdir,url.ini,"),urls,%col1)
.hadd -sm IDUrl %col1 %col2
did -a RssReaderBar 4 +e %col1 $chr(9) %col2
inc %iLoop
}
}
;------------------
var %url
dialog RssDialogConfigAdd {
size -1 -1 276 124
title "Add..."
text "ID:",1,40 13 15 13
text "URL:",2,32 34 23 13
edit "",3,79 10 187 25
edit "",4,79 37 187 49, hsbar multi
button "&OK",5,140 91 60 22, ok
button "&Close",6,205 91 60 22, cancel
}
on *:dialog:RssDialogConfigAdd:sclick:5: {
%var1 = $did(RssDialogConfigAdd,3)
%var2 = $did(RssDialogConfigAdd,4)
; the user must supply values...
if ((!%var1) || (!%var2)) {
%t = $input(You must supply values !!!,oh,Error)
halt
}
; check if this ID still exist in our hash table.
%result = $hget(IDUrl, %var1)
if (%result) {
%t = $input(ID %var1 always exist !!!,oh,Error)
halt
}
did -a RssDialogConfig 1 + 0 0 0 %var1 $+ $chr(9) $+ + 0 0 0 %var2
.hadd -m IDUrl %var1 %var2
}
dialog RssDialogConfig {
size -1 -1 461 226
title "Add Rss Url"
list 1,10 14 452 166,vsbar size
button "&Add",2,100 191 57 25
button "&Update",3,224 191 57 25
button "&Remove",4,157 191 57 25
button "&Close",5,283 191 57 25, ok
}
on *:dialog:RssDialogConfig:sclick:3: {
; create another empty file by erasing the older one.
.remove $+(",$scriptdir,url.ini,")
%lines = $did(RssDialogConfig,1).lines
%iLoop = 1
while (%iLoop < %lines) {
writeini $+(",$scriptdir,url.ini,") urls $ldid(RssDialogConfig,1,1,%iLoop) $ldid(RssDialogConfig,1,2,%iLoop)
inc %iLoop
}
}
on *:dialog:RssDialogConfig:sclick:2: {
dialog -mp RssDialogConfigAdd RssDialogConfigAdd
}
on *:dialog:RssDialogConfig:sclick:4: {
%result = $input(Are you sure to remove this item ?,yw,Warning)
if (%result == $true) {
; remove it from the listview.
hdel IDUrl $cell(RssDialogConfig,1,$did(1).sel,1)
; remove it from the listview.
did -d RssDialogConfig 1 $did(1).sel
}
}
on *:dialog:RssDialogConfig:init:*:{
mdx SetMircVersion $version
mdx MarkDialog $dname
mdx SetControlMDX $dname 1 ListView editlabels report rowselect showsel single labeltip headerdrag flatsb > $scriptdir $+ views.mdx
did -i $dname 1 1 headerdims 77 350
did -i $dname 1 1 headertext ID $chr(9) URL
;--------- retrieve the url and their id from the ini file.
; number of lines under the first section which is [url id]
%lines = $ini($+(",$scriptdir,url.ini,"),1,0)
;setup the listview control and the hash table.
.hfree -ws IDUrl
.hmake -s IDUrl 50
%iLoop = 1
while (%iLoop <= %lines) {
%col1 = $ini($+(",$scriptdir,url.ini,"),1,%iLoop)
%col2 = $readini($+(",$scriptdir,url.ini,"),urls,%col1)
did -a RssDialogConfig 1 + 0 0 0 %col1 $+ $chr(9) $+ + 0 0 0 %col2
.hadd -sm IDUrl %col1 %col2
inc %iLoop
}
}
alias Rss.config {
dialog -m RssDialogConfig RssDialogConfig
}
alias Rss.Read {
if (!$1-) {
echo -a Missing ID Rss Adress ...
return
}
%url = $hget(IDUrl, $1-)
if (!%url) {
echo -a No Url associated with this ID.
return
}
; save the rss feed we get from internet, in a directory called "Files"
httpget %url Files/ $+ $1-
}
alias Rss.show {
if (!$1-) {
echo -a Missing RSS ID ...
return
}
; dll and .xml files
var %dll = $+(",$scriptdir,xml.dll,")
var %xml = $+(",$scriptdir,Files/,$1,")
if (!$isfile(%dll)) { echo -a Error - missing: %dll | return }
if (!$isfile(%xml)) { echo -a Error - missing: %xml | return }
; parser name
var %n = Rss
var %a = $dll(%dll,create_parser,%n)
if (%a != S_OK) { echo -a Error - create_parser: %a | return }
dll %dll set_handler_chardata %n hchardata
;echo -a Setting XML file : %xml
dll %dll set_file %n %xml
; global var: dll pathname will be use in start and end element handlers
%xmldemo.dll = %dll
;echo $color(join) -a Parsing :
var %a = $dll(%dll,parse_file,%n)
if (%a != S_OK) { echo -a Error - parse_file: %a }
;echo -a Deleting parser %n
dll %dll free_parser %n
; unsets global var
unset %xmldemo.*
}
alias InsertDescription {
var %nLines = $did(RssReaderBar,6).lines
var %stTitles = $ldid(RssReaderBar,6,1,$calc(%nLines - 1))
var %stLink = $ldid(RssReaderBar,6,3,$calc(%nLines - 1))
did -o RssReaderBar 6 %nLines %stTitles $chr(9) $1- $chr(9) %stLink
}
alias InsertLink {
var %nLines = $did(RssReaderBar,6).lines
var %stTitles = $ldid(RssReaderBar,6,1,$calc(%nLines - 1))
var %stDescrp = $ldid(RssReaderBar,6,2,$calc(%nLines - 1))
did -o RssReaderBar 6 %nLines %stTitles $chr(9) %stDescrp $chr(9) $1-
}
alias hchardata {
; The Channel
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/title ) {
;echo -a $chr(31) $+ Channel Title $+ $chr(31) : $2-
}
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/description ) {
;echo -a $chr(31) $+ Channel Description $+ $chr(31) : $striphtml($2-)
}
; item
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/title ) {
did -a RssReaderBar 6 $striphtml($2-)
}
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/description ) {
InsertDescription $striphtml($2-)
}
if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/link ) {
; echo -a $chr(2) $2- $chr(2)
; did -a RssReaderBar 6 $2-
InsertLink $striphtml($2-)
}
; uncomment this one if u would some more information
;if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/Author ) {
; echo -a Article author : $2-
;}
;if ( $dll(%xmldemo.dll,get_abspath,$1) == rss/channel/item/pubdate ) {
; echo -a Article date : $2-
;}
}
; -----------------------------------------------------------------------------------
;HTTP Transfer Script
;beta phase!
;
;Original script: Tomalak Geret'kal from www.deep-space-5.org/mirchelp.php";
;Usage: /httpget http://<host>/<path> [local_folder]
;
;-------------------------------------------------------------------------------------*/
alias httpget {
if ($regex($1,/^http:\/\/([^\/]+)(\/.+)$/i)) {
echo -a [HTTP] Opening to $+ $regml(1) $+ on port: 80
var %name = httpget_socket
sockopen %name $regml(1) 80
set % $+ %name $+ .url $regml(1)
set % $+ %name $+ .path $regml(2)
var %2 = $2
set % $+ %name $+ .saveto %2
}
}
on *:sockopen:httpget_socket:{
echo -a • Connection established
var %request1 = GET % [ $+ [ $sockname ] $+ .path ] HTTP/1.1
var %request2 = Host: % [ $+ [ $sockname ] $+ .url ]
var %request3 = % [ $+ [ $sockname ] $+ .url ] close
sockwrite -t $sockname %request1 $+ $crlf $+ %request2 $+ $crlf $+ Connection: close $+ $crlf $+ $crlf
echo -a • Request sent...
}
on *:sockwrite:httpget_socket:{
if ($sockerr) echo -a • Error: $ifmatch
}
on *:sockread:httpget_socket:{
if ($sockerr > 0) return
var %fname = $+(",$scriptdir,%httpget_socket.saveto,")
:nextread
if (!$sock($sockname).mark) {
sockread %output
if ($sockbr == 0) {
sockclose $sockname
return
}
var %400 = HTTP/1.1 400 Bad Request
var %404 = HTTP/1.1 404 Not Found
if (%400 iswm %output) {
echo -a 4• Bad HTTP Request
sockclose $sockname
}
elseif (%404 iswm %output) {
echo -a • File Not Found!
sockclose $sockname
}
elseif ($regex(%output,/HTTP\/1.1 (4|5\d\d) (.+)/)) {
echo -a • ERROR $regml(1) $+ : $regml(2)
sockclose $sockname
}
if (%output == $null) {
sockmark $sockname header received
write -c %fname
}
}
else {
sockread -nf 4096 &output
if ($sockbr == 0) {
return
}
bwrite %fname -1 -1 &output
}
goto nextread
}
on *:sockclose:httpget_socket:{
echo -a • Transfer complete. File saved as 12 $+ %httpget_socket.saveto $+
echo -a • Connection closed
.unset % $+ $sockname $+ .*
}
; Usage:
; $cell(Dialog name,ID,Line,Cell)
; Contact:
; IRC: Gallagher @ PTnet
; E-mail: morphy_chaos@hotmail.com
; Website: www.chaos.page.vu
alias cell {
return $gettok($gettok($gettok($did($1,$2,$3),$4,9),$iif($4 = 1,6,5) $+ -,32),1,4)
}
; $ldid(Dialog,ID,N) de l3z4rD
alias ldid {
var %line = $iif($4 isnum,$calc($4 +1),$did($1,$2).sel)) , %did = $did($1,$2,%line)
if ($prop == total) return $numtok(%did,9)
return $gettok($gettok(%did,$3,9),$iif($3 == 1,6-,5-),32)
}
/*
By Yochai Timmer
*/
alias did-tree {
var %dialog = $1
var %id = $2
;It's not necessery to set the $1 and $2 to vars, but I like to use named vars (Espcialy in examples)
if (!$dialog(%dialog)) return
;Just checking...
if ($3) {
; Checks if a specific location was requested
var %Loc = $3-
;Sets the location
if ($prop = lines) {
;Checks if the Property .lines was used
did -i %dialog %id 1 cb root %loc
;always need to use cb (change branch) to get the requested location
return $calc($did(%dialog,%id,0).lines -1)
;mdx default returns the number of lines + 1 (the options line), so you need to reduce by one to get the actuall number of lines
}
if ($numtok(%Loc,32) = 1) did -i %dialog %id 1 cb root
else { did -i %dialog %id 1 cb root $gettok(%loc,1- $+ $calc($numtok(%loc,32) -1),32) }
;Changing to the requested branch...
var %line = $gettok($did(%dialog,%id,$gettok(%Loc,-1,32)),7-,32)
;This sets %line to the branch's text
if ($prop = tooltip) return $gettok(%line,2-,9)
;This returns the branch's tooltip
return $gettok(%line,1,9)
;This returns the requested branch
}
var %entry = $did(%dialog,%id,1)
if ($gettok(%entry,1,32) = slclick) var %loc = $gettok(%entry,4-,32)
else var %loc = $gettok(%entry,3-,32)
;This checks the last event in the requested ID
var %depth = $calc($numtok(%loc,32) -1)
var %branch = $gettok(%loc,-1,32)
;Setting the depth of the branch, and the actuall branch position
if (%depth = 0) did -i %dialog %id 1 cb root
else did -i %dialog %id 1 cb root $gettok(%loc,1- $+ %depth,32)
;Changing to the requested branch
var %line = $gettok($did(%dialog,%id,%branch),7-,32)
;This sets %line to the branch's text
if (!$prop) return $gettok(%line,1,9)
;If no props were set it returns the branch's text
if ($prop = root) return $gettok(%loc,1,32)
;returns the root ID
if ($prop = sel) return %loc
;returns the branch's location
if ($prop = lines) return $calc($did(%dialog,%id,0).lines -1)
;Returnes the number of lines in the selected branch
if ($prop = len) return $len(%line)
;This returns the length of the branch's text
if ($prop = tooltip) return $gettok(%line,2-,9)
;This returns the branch's tooltip
if ($prop = event) return $gettok(%entry,1,32)
;This returns the last Event that in the dialog
}
/*
By Yochai Timmer
This snippet is used in MDX Tree-views to search for branches with wildcard text
Usage:
$Find-branch(Dialog,ID,Match string,<Branch Location>)
The location is optional, if you don't give a location, the snippet will search in the root branch.
If you give a Branch location, it will look in all the Sub-branches.
The snippet returns the matching location.
*/
alias Find-branch {
; $1 is the Dialog name
; $2 is the specified ID
; $3 is the Match string
; $4 is the Location
if (!$dialog($1)) return
if (!$4) var %loc = 1
else %loc = $4
var %num = 0
var %a = 2
did -i $1 $2 1 cb root %loc
;selecting the requested location
while ($gettok($did($1,$2,%a),7-,32)) {
;looping through the branches
var %line = $gettok($v1,1,9)
;This sets %line to the branch's value (without the comment)
if ($3 iswm %line) {
if ($4 != 0) return %a
inc %num
}
inc %a
}
if ($4 != 0) return
return %num
}
# .:[ dJabba's $striphtml ]:. #
; -----------------------––––––––––––-----––––––––––––––––––––––––––––––––––––––
; Author : dJabba
; Email : jabbalenium@gmail.com
; URL : http://www.dJabbaScripts.tk
; Contact : mailto:jabbalenium@gmail.com?subject=dJsthtml
alias striphtml {
;Syntax : $striphtml(html line)
;Description: Removes all html tags and converts most special charaters tags
; to there real ascii characters.
;Example : //echo -a Plain text: $striphtml(<td width=10></td><td>Strip html script. « Echo test »</td>)
;Property : You can add the property .160 to replace spaces with $chr(160) instead of $chr(32).
;Example : //echo -a Plain text: $striphtml(<td width=10></td><td>Strip html script. « Echo test »</td>).160
if (!$isid) || (!$1) return
var %H = $1 , %T = $regsub(%H,/(<[^>]+>)/g,,%H)
if ($chr(38) isin %H) set %H $reptags(%H)
if ($chr(38) isin %H) set %H $replacecs(%H,"," ,<,< ,>,> ,&,& , ,$iif($prop,$chr($prop),$chr(32)) ,£,£ ,§,$chr(36) ,¨,¨ ,«,« ,»,» ,ß,ß, Ñ,Ñ ,ñ,ñ)
if ($chr(38) isin %H) set %H $replacecs(%H,À,À ,Á,Á ,Â, ,Ã,à ,Ä,Ä ,Å,Å ,Æ,Æ ,à,à ,á,á ,â,â ,ã,ã ,ä,ä ,å,å ,æ,æ)
if ($chr(38) isin %H) set %H $replacecs(%H,È,È,É,É,Ê,Ê,Ë,Ë,è,è,é,é,ê,ê,ë,ë,Ì,Ì,Í,Í,Î,Î,Ï,Ï,ì,ì,í,í,î,î)
if ($chr(38) isin %H) set %H $replacecs(%H,ï,ï,Ò,Ò,Ó,Ó,Ô,Ô,Õ,Õ,Ö,Ö,Ø,Ø,ò,ò,ó,ó,ô,ô,õ,õ,ö,ö,ø,ø,Ù,Ù,Ú,Ú,Û,Û,Ü,Ü,Ý,Ý,ù,ù,ú,ú,û,û,ü,ü,ý,ý,ÿ,ÿ)
return %H
}
alias reptags {
;Tnx tidy_trax for the code piece here.
var %a, %b = $regsub($replace($1,$chr(32),$chr(32) $!chr(32) $!+ $!chr(32) $chr(32)),/&#(\d+);/g,$chr(32) \$+ \$chr(\1) \$+ $chr(32),%a)
return $(%a,2)
}
alias _striphtml {
;Syntax : $_striphtml(html line)
;Description: The exact same as $striphtml, this one isn't case sensitive in
; the replace methods. this is not a valid form, but might come
; handy to some people.
if (!$isid) || (!$1) return
var %H = $1 , %T = $regsub(%H,/(<[^>]+>)/g,,%H)
if ($chr(38) isin %H) set %H $reptags(%H)
if ($chr(38) isin %H) set %H $replace(%H,"," ,<,< ,>,> ,&,& , ,$iif($prop,$chr($prop),$chr(32)) ,£,£ ,§,$chr(36) ,¨,¨ ,«,« ,»,» ,ß,ß, Ñ,Ñ ,ñ,ñ)
if ($chr(38) isin %H) set %H $replace(%H,À,À ,Á,Á ,Â, ,Ã,à ,Ä,Ä ,Å,Å ,Æ,Æ ,à,à ,á,á ,â,â ,ã,ã ,ä,ä ,å,å ,æ,æ)
if ($chr(38) isin %H) set %H $replace(%H,È,È,É,É,Ê,Ê,Ë,Ë,è,è,é,é,ê,ê,ë,ë,Ì,Ì,Í,Í,Î,Î,Ï,Ï,ì,ì,í,í,î,î)
if ($chr(38) isin %H) set %H $replace(%H,ï,ï,Ò,Ò,Ó,Ó,Ô,Ô,Õ,Õ,Ö,Ö,Ø,Ø,ò,ò,ó,ó,ô,ô,õ,õ,ö,ö,ø,ø,Ù,Ù,Ú,Ú,Û,Û,Ü,Ü,Ý,Ý,ù,ù,ú,ú,û,û,ü,ü,ý,ý,ÿ,ÿ)
return %H
}