+ Reply to Thread
Results 1 to 7 of 7

Thread: php, lua and e2 rss feed viewer

  1. #1
    Wirererer ben1066's Avatar
    Join Date
    Aug 2009
    Posts
    151

    Default php, lua and e2 rss feed viewer

    So then, after being inspired by seeing vvoman's color image downloader and making my own from scratch at a 256*256 resolution I thought what else could I make with the same sort of set up. I then came up with the idea to make an rss viewer and here it is! It like vvoman's downloader uses php, lua and e2 and in a very similar way. To use this you will need a small web server on your pc with php and the simplepie (SimplePie: Super-fast, easy-to-use, RSS and Atom feed parsing in PHP.) rss parser on it as that made my life a lot easier! When you have it all set up you open your server, run the lua script in gmod and spawn the e2 and console screen and wire them up. Then you wait for the e2 to tell you it's really and you can then view rss feeds on your console screen! It's a known issue that if the url to the feed has a question mark in it it will not work, it will simply break. Below I will post some images and the code for all three things, it will help to know your way round each language to set them up.





    e2
    Code:
    @name RSS Reader
    @inputs Screen:wirelink
    @outputs 
    @persist Data:array ChatArray:array Busy Print
    @trigger 
    
    runOnChat(1)
    runOnFile(1)
    
    if(first()){
        Busy=1
        timer("ready",11000)
        Screen[2041]=1
    }
    
    if(clk("ready")){
        Busy=0
        print("RSS Feed Reader Ready")
        Screen[2041]=0
    }
    
    if(lastSpoke()==owner()){ChatArray=lastSaid():explode(" ")}
    if(ChatArray[1,string]=="!rss"&!Busy){
        fileRemove("e2feed.txt")
        concmd("rss_load "+ChatArray[2,string]:replace("http://","HTTP"):replace(" ","%20"))
        Busy=1
        Screen[2041]=1
        Print=0
    }
    
    if(ChatArray[1,string]=="[rss_file_generated]"&Busy&!Print){
        fileLoad("e2feed.txt")
        print("Loading Feed.")
        Print=1
        hideChat(1)
    }
    
    if(fileClk("e2feed.txt")){
        Screen[2041]=0
        print("Printing Feed.")
        Data=fileRead("e2feed.txt"):explode("!%BREAK%!")
        TitleLength=Data[1,string]:length()
        BodyStart=ceil(TitleLength/29)
        Screen:writeString(Data[1,string],0,0,900) 
        Screen:writeString(Data[2,string]:sub(9):replace("&mdash",""),0,BodyStart)
        Busy=0
    }
    lua (credit to vvoman for this, used his code mostly, with permission)
    Code:
    print("RSS php and e2 communication layer loaded!\n")
    
    function loadRSS(ply,cmd,args) 
    	print("Refreshing RSS Data File!\n")
    
    	url=args[1]
    	
    	print("URL: "..tostring(url))
    	
    	function callBackLoadRSS(contents, size)
    		print(contents)
    		RunConsoleCommand("say", "[rss_file_generated]")
    	end
    	
    	http.Get("http://localhost/rssgen.php?feed="..tostring(url), "", callBackLoadRSS) 
    end 
     
    concommand.Add("rss_load", loadRSS)
    php (64x)
    Code:
    <?php
    require_once('simplepie/simplepie.inc');
    $url = str_replace("HTTP","http://",$_GET["feed"]);
    $url = str_replace("%20"," ",$url);
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->strip_htmltags(array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style', 'a', 'img', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'br', 'div', 'i', 'em', 'strong', 'p','&mdash'));
    $feed->init();
    $feed->handle_content_type();
    $item = $feed->get_item(1);
    $string = $item->get_title();
    $string .= "!%BREAK%!";
    $string .= $item->get_description();
    $fh = fopen("C:\Program Files (x86)\Steam\steamapps\<Your username here>\garrysmod\garrysmod\data\e2files\e2feed.txt", 'w') or die("can't open file");
    fwrite($fh, $string);
    fclose($fh);
    echo $string;
    php (32x)
    Code:
    <?php
    require_once('simplepie/simplepie.inc');
    $url = str_replace("HTTP","http://",$_GET["feed"]);
    $url = str_replace("%20"," ",$url);
    $feed = new SimplePie();
    $feed->set_feed_url($url);
    $feed->strip_htmltags(array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style', 'a', 'img', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'br', 'div', 'i', 'em', 'strong', 'p','&mdash'));
    $feed->init();
    $feed->handle_content_type();
    $item = $feed->get_item(1);
    $string = $item->get_title();
    $string .= "!%BREAK%!";
    $string .= $item->get_description();
    $fh = fopen("C:\Program Files\Steam\steamapps\<Your username here>\garrysmod\garrysmod\data\e2files\e2feed.txt", 'w') or die("can't open file");
    fwrite($fh, $string);
    fclose($fh);
    echo $string;

  2. #2
    Wire Sofaking Unsmart's Avatar
    Join Date
    Dec 2008
    Location
    Belgium OR BANland
    Posts
    1,965

    Default Re: php, lua and e2 rss feed viewer

    You are dlb1, right?

    Yeah nice idea!
    New server IP: 89.238.160.17:27018
    Hologram contraptions 1 Holo contraptions 2 EGP stuff Holo minigun Holo javelin rocket launcher
    Unsmart: I doubt the intelligence of some people.
    Drunkie: Nobody could have said that any better than Unsmart.

    Unsmart: Solece, I totally did your mom yesterday
    Solece: Who hasnt

    Divran: there are more retarded people than there are clever people in this world

  3. #3
    Wirererer ben1066's Avatar
    Join Date
    Aug 2009
    Posts
    151

    Default Re: php, lua and e2 rss feed viewer

    Yeah, I'm dlb1, thanks unsmart.

  4. #4
    hurrr physics Tolyzor's Avatar
    Join Date
    Aug 2008
    Location
    England
    Posts
    1,019

    Default Re: php, lua and e2 rss feed viewer

    sweet, wont be long till ingame e2 browsers surpass the steam browser...

  5. #5
    Wirererer Timomo's Avatar
    Join Date
    Jul 2009
    Location
    toCity( owner():pos() )
    Posts
    107

    Default Re: php, lua and e2 rss feed viewer

    this is just awesome

  6. #6
    Wire Noob VVoMan_PL's Avatar
    Join Date
    Oct 2008
    Location
    Toruń, Poland
    Posts
    15

    Default Re: php, lua and e2 rss feed viewer

    Good job, I see it's based on my scripts :P

  7. #7
    Wirererer ben1066's Avatar
    Join Date
    Aug 2009
    Posts
    151

    Default Re: php, lua and e2 rss feed viewer

    Yeah, thanks for the inspiration VVoMan, with your downloader, the lua is almost all yours.

+ Reply to Thread

LinkBacks (?)

  1. 02-17-2010, 09:14 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots