Changeset 152 for dev/mods

Show
Ignore:
Timestamp:
12/13/06 17:22:00 (13 years ago)
Author:
liq
Message:

liq's feed syndication mod 1.3

Location:
dev/mods/feed_syndication
Files:
1 added
1 removed
3 modified

Legend:

Unmodified
Added
Removed
  • dev/mods/feed_syndication/feed_fetcher.php

    r150 r152  
    11<?php 
     2        ////// 
     3//////  ////// 
     4//////  liq's feed syndication mod v1.3 
     5//////////// 
     6//////////// 
     7//////////// 
     8//////////// 
     9  
    210 
    3 // liq's feed syndication mod v1.2 
    4  
    5   @set_time_limit(0); 
    6   require_once( "class.kill.php" ); 
    7   require_once( "class.parser.php" ); 
    8   if ( file_exists("../../common/class.comments.php") ) // for the Eve-Dev Comment Class 
     11@set_time_limit(0); 
     12require_once( "common/class.kill.php" ); 
     13require_once( "common/class.parser.php" ); 
     14if ( file_exists("../../common/class.comments.php") ) // for the Eve-Dev Comment Class 
    915        require_once( "class.comments.php" ); 
    10   if ( file_exists("../../common/class.comment.php") ) // for the D2 Killboard Comment Class 
     16if ( file_exists("../../common/class.comment.php") ) // for the D2 Killboard Comment Class 
    1117        require_once( "class.comment.php" ); 
    1218 
     
    5359class Fetcher { 
    5460 
    55 function grab($url) { 
    56                 global $x, $fetchurl; 
     61function grab($url, $str) { 
     62                global $x, $uurl; 
    5763                $x=0; 
    58                 $fetchurl = $url; 
     64                $fetchurl = $url.$str; 
     65                $uurl = $url; 
    5966        $xml_parser = xml_parser_create(); 
    6067                xml_set_object ( $xml_parser, $this ); 
    6168                xml_set_element_handler($xml_parser, "startElement", "endElement"); 
    6269                xml_set_character_data_handler ( $xml_parser, 'characterData' ); 
    63                 $fp = @fopen($url,"r"); 
    64                 while ($data = @fread($fp, 4096)) { 
    65                         if (!xml_parse( $xml_parser, $data, feof($fp) ) && !feof($fp) ) 
    66                                 return "<i>Error getting XML data from ".$url."</i><br><br>"; 
     70                $fp = @fopen($fetchurl,"r");  
     71                while ($chunk = @fread($fp, 4096)) { 
     72                        $data .= $chunk; 
    6773                } 
     74                $data = preg_replace('<<!--.*?-->>', '', $data); // remove <!-- Cached --> message, else it will break gzinflate 
     75                 
     76                if (!@gzinflate($data)) { 
     77                        $cprs = "raw HTML stream"; 
     78                } else {  
     79                        $data = gzinflate($data); 
     80                        $cprs = "GZip compressed stream"; 
     81                }        
     82                 
     83                if (!xml_parse( $xml_parser, $data, feof($fp) ) && !feof($fp) ) 
     84                        return "<i>Error getting XML data from ".$url."</i><br><br>";            
     85                         
    6886                @fclose($fp); 
    6987                xml_parser_free($xml_parser); 
     88                 
    7089                if ($x) 
    71                         $html = "<div class=block-header2>".$x." kills added from feed: ".$url."</div>"; 
     90                        $html .= "<div class=block-header2>".$x." kills added from feed: ".$url." <i>(".$cprs.")</i></div>"; 
    7291                else 
    73                         $html = "<div class=block-header2>No kills added from feed: ".$url."</div>"; 
     92                        $html .= "<div class=block-header2>No kills added from feed: ".$url." <i>(".$cprs.")</i></div>"; 
     93                //echo "url:".$url." --- "; 
     94                //echo " strg:".$str; 
     95                 
    7496return $html; 
    7597} 
     
    84106 
    85107function endElement($parser, $name) { 
    86         global $insideitem, $tag, $title, $description, $link, $html, $x, $fetchurl; 
     108        global $insideitem, $tag, $title, $description, $link, $html, $x, $uurl; 
    87109 
    88110        if ($name == "ITEM") { 
     
    105127                                if (class_exists('Comments') && getConfig('fetch_comment')) { // for the Eve-Dev Comment Class 
    106128                                        $comments = new Comments($killid); 
    107                         $comments->addComment("liq's feed syndication", getConfig('fetch_comment')." (mail fetched from: ".$fetchurl.")"); 
     129                        $comments->addComment("liq's feed syndication", getConfig('fetch_comment')." mail fetched from: ".$uurl.")"); 
    108130                                } 
    109131                                if (class_exists('Comment') && getConfig('fetch_comment')) { // for the D2 Killboard Comment Class 
    110132                                        $comment = new Comment($killid); 
    111                         $comment->postComment(getConfig('fetch_comment')." \n\n <i>(mail fetched from:\n ".$fetchurl.")</i>", "liquidism"); 
     133                        $comment->postComment(getConfig('fetch_comment')." \n\n\n <i>mail fetched from:\n ".$uurl."</i>", "liquidism"); 
    112134                                } 
    113135                                $x++; 
  • dev/mods/feed_syndication/readme.txt

    r148 r152  
    1  
    2 // liq's feed syndication mod v1.1 
     1        ////// 
     2//////  ////// 
     3//////  liq's feed syndication mod v1.3 
     4//////////// 
     5//////////// 
     6//////////// 
     7//////////// 
    38 
    49 
    510 
    6 //installation: 
     11//INSTALLATION: 
    712 
    8 1. put all the files in your /common directory. 
     131. create directory mods/feed 
     142. put the files settings.php and feed_fetcher.php in /mods/feed_syndication directory. 
     153. put feed.php in your /common directory 
     163. login as admin and enable the feed-mod in 'Mods' 
     174. wee. youre done. 
    918 
    10 2. add the following line to admin_menu.php: 
    11 $menubox->addOption( "Feeds", "?a=admin_feed" ); 
    12  
    13 3. youre done. 
     19additionally you can add the following line to common/admin_menu.php for direct access: 
     20$menubox->addOption( "Feeds", "?a=settings_feed_syndication" ); 
     21or if you use eve-dev kilboard version 1.2.0 and above (using smarty templates): 
     22$menubox->addOption("link", "Feeds", "?a=settings_feed_syndication"); 
    1423 
    1524 
    16 //files 
     25 
     26//FILES: 
    1727 
    1828feed.php <- prints out all kills of the actual week in rss format. 
     
    2333 
    2434 
    25 //notes 
    2635 
    27 -> enter feed urls in the format 'http://killboard.eve-d2.com/?a=feed' into the admin interface. 
    28 click 'save' to save your changes before you 'fetch' new kills. 
     36//NOTES: 
     37 
     38-> enter feed urls in the format: http://killboard.eve-d2.com/?a=feed 
     39 
     40-> a list of known feeds can be found here: http://www.eve-dev.net/e107_plugins/forum/forum_viewtopic.php?1896 
    2941 
    3042-> clicking the 'fetch' button will get all kills of the actual week. 
    3143 
    32 -> ticking the 'grab-ALL-mails-box' will grab ALL kills! be careful with this option! 
    33 ** it can take several minutes or even hours to have all the kills parsed and added to your database ** 
    34 ** be patient. don't close your browser, don't reload. you only need to use this ONCE in a lifetime ** 
     44-> ticking the 'grab-ALL-mails-box' will grab the kills of ALL weeks (iteration from week #1 through to week #52)! 
     45** be careful with this option! it can take several minutes or even hours to have all the kills parsed and added to your database ** 
     46** be patient. don't close your browser, don't reload. you only need to use this ONCE to initialize a feed connection. 
     47after initializing, weekly updates are totally sufficient to keep your board uptodate ** 
     48 
     49-> by default their kills aka. your losses get fetched unless you tick the 'get kills' 
     50option in which case their losses aka. your kills get fetched 
     51 
     52-> GZip compression is enabled by default because the board automatically 
     53checks and decides if a fetched stream supports GZip compression - if not it uses regular html/rss output. 
     54 
     55-> if you are running a master killboard (eg. to supply and share killdata with other killboards) edit settings.php and set 'MASTER' to 1. 
     56the board will then even fetch kills not related to the alliance or corp ID you set in the killboards config.php. 
     57leave this option untouched if youre running a normal killboard for your corp or alliance - it will just slow things down. 
     58 
     59-> the feed is not supposed to be human readable so ffs dont complain about the formatting, 
     60for human readable rss output use the rss mod ( /?a=rss ) instead. 
    3561 
    3662 
    37 //changes 
     63 
     64//VERSION CHANGES: 
     65 
     66//v1.3 
     67 
     68feed.php: 
     69- added support for GZip compressed output 
     70- minor code cleanups 
     71 
     72feed_fetcher.php: 
     73- converted to a mod 
     74- added support for getting GZip compressed feeds and a fallback if the feed is uncompressed 
     75- changed the text in auto-comment to only show the remote killboards url and not the  
     76complete path with all passed variables, making it more readable 
     77 
     78admin_feed.php / settings.php 
     79- converted to a mod  
     80- renamed to settings.php 
     81- added option to fetch streams with Gzip compression - enabled by default 
     82- added support for master killboards whose only purpose is to collect and share kill data, see notes 
     83 
     84 
     85//v1.2 
     86 
     87feed.php: 
     88- added output of feed's version number 
     89 
     90feed_fetcher.php: 
     91- none 
     92 
     93admin_feed.php 
     94- rearranged options to be inline with other admin settings pages 
     95- added checkboxes to enable / disable fetching specific feed urls 
     96 
    3897 
    3998//v1.1 
     
    50109- included calls to the killboards comment function so you can add predefined comments to autoparsed kills aka. "post your losses noob". 
    51110 
    52 admin_feed.php 
     111admin_feed.php: 
    53112- made the number of feeds user selectable 
    54113- more detailed descriptions 
     
    56115- option to automatically enter a comment with the autoparsed kill 
    57116- option to get kills instead of losses 
     117- added backwards compatibility to exi's v1.0 mod 
    58118 
    59119 
  • dev/mods/feed_syndication/settings.php

    r148 r152  
    1 <? 
     1<?php 
     2        ////// 
     3//////  ////// 
     4//////  liq's feed syndication mod v1.3 
     5//////////// 
     6//////////// 
     7//////////// 
     8//////////// 
    29 
    3 // liq's feed syndication mod v1.2 
     10 
     11// set this to 1 if you are running a master killboard and want  
     12// to even fetch mails not related to your corp / alliance 
     13define( MASTER, 0 ); 
     14 
     15 
    416 
    517@set_time_limit(0); 
     18require_once( "feed_fetcher.php" ); 
    619require_once( "common/class.page.php" ); 
    720require_once( "common/admin_menu.php" ); 
    8 require_once( "common/feed_fetcher.php" ); 
    921require_once( 'common/class.corp.php' ); 
    1022require_once( 'common/class.alliance.php' ); 
     
    3547                else 
    3648                        setConfig('fetch_verbose', '0'); 
     49                 
     50                if ( $_POST['fetch_compress'] ) 
     51                        setConfig('fetch_compress', '0'); 
     52                else 
     53                        setConfig('fetch_compress', '1'); 
    3754 
    3855                if ( $_POST['fetch_comment'] ) 
     
    6178 
    6279        if ( $_POST['fetch'] ) { 
    63          if (CORP_ID) { 
    64             $corp = new Corporation(CORP_ID); 
     80         if (CORP_ID && !MASTER) { 
     81                        $corp = new Corporation(CORP_ID); 
    6582             $myid = '&corp='.urlencode($corp->getName()); 
    6683         } 
    67          if (ALLIANCE_ID) { 
     84         if (ALLIANCE_ID && !MASTER) { 
    6885             $alli = new Alliance(ALLIANCE_ID); 
    6986             $myid = '&alli='.urlencode($alli->getName()); 
    70                  } 
     87                } 
    7188 
    7289                 for ($i=1; $i<=$feedcount; $i++) { 
     
    7996                                if ( $_POST['fetch_losses'] ) 
    8097                        $str .= "&losses=1"; 
     98                                if ( !getConfig('fetch_compress') ) 
     99                        $str .= "&gz=1"; 
    81100                                if ( $_POST['graball'] ) { 
    82101                                        for ($l = 1; $l<=52; $l++) { 
    83102                                                $html .= "<b>Week: ". $l ."</b><br>"; 
    84                                                 $html .= $feedfetch->grab( $feed[$i].$myid.$str."&week=".$l ); 
     103                                                $html .= $feedfetch->grab( $feed[$i]."&week=".$l, $myid.$str ); 
    85104                                        } 
    86105                            } else 
    87                                 $html .= $feedfetch->grab( $feed[$i].$myid.$str ); 
     106                                $html .= $feedfetch->grab( $feed[$i], $myid.$str ); 
    88107                        } 
    89108 
     
    93112        } 
    94113 
    95         $html .= "<form id=options name=options method=post action=?a=admin_feed>"; 
     114        $html .= "<form id=options name=options method=post action=?a=settings_feed>"; 
    96115    $html .= "</table>"; 
    97116 
     
    133152        $html .= "\"><br><i> (leave blank for none)</i><br></td></tr>"; 
    134153 
     154        $html .= "<tr><td height=30px width=150px><b>Enable compression?</b></td>"; 
     155    $html .= "<td><input type=checkbox name=fetch_compress id=fetch_compress"; 
     156        if ( !getConfig('fetch_compress') ) 
     157                $html .= " checked=\"checked\""; 
     158        $html .= "><i> (enables GZip compression for feeds that support this feature, for streams that do not support GZip compression regular html mode will be used automatically)</i></td>"; 
     159        $html .= "</tr>"; 
     160         
    135161        $html .= "<tr><td height=30px width=150px><b>Verbose mode?</b></td>"; 
    136162    $html .= "<td><input type=checkbox name=fetch_verbose id=fetch_verbose"; 
    137163        if ( getConfig('fetch_verbose') ) 
    138164                $html .= " checked=\"checked\""; 
    139         $html .= "><i> (displays errormessages when the imported mail is malformed, already exists, is not related etc.)</i></td>"; 
     165        $html .= "><i> (displays errormessages when the imported mail is rejected for being malformed, already existing, not being related etc.)</i></td>"; 
    140166        $html .= "</tr></table><br><br>"; 
    141167