1 | <?php |
---|
2 | ////// |
---|
3 | ////// ////// |
---|
4 | ////// liq's feed syndication mod v1.5 |
---|
5 | //////////// |
---|
6 | //////////// |
---|
7 | //////////// |
---|
8 | //////////// |
---|
9 | |
---|
10 | |
---|
11 | @set_time_limit(0); |
---|
12 | @ini_set('memory_limit',999999999); |
---|
13 | |
---|
14 | require_once( "common/includes/class.kill.php" ); |
---|
15 | require_once( "common/includes/class.parser.php" ); |
---|
16 | if ( file_exists("../../common/includes/class.comments.php") ) // for the Eve-Dev Comment Class |
---|
17 | require_once( "common/includes/class.comments.php" ); |
---|
18 | if ( file_exists("../../common/includes/class.comment.php") ) // for the D2 Killboard Comment Class |
---|
19 | require_once( "common/includes/class.comment.php" ); |
---|
20 | |
---|
21 | $insideitem = false; |
---|
22 | $tag = ""; |
---|
23 | $title = ""; |
---|
24 | $description = ""; |
---|
25 | $link = ""; |
---|
26 | $x=0; |
---|
27 | |
---|
28 | function setConfig($key, $value) { |
---|
29 | global $config; |
---|
30 | if (method_exists($config, 'setConfig')) |
---|
31 | return $config->setConfig($key, $value); |
---|
32 | $qry = new DBQuery(); |
---|
33 | $qry->execute("select cfg_value from kb3_config |
---|
34 | where cfg_key = '".$key."' and cfg_site = '".KB_SITE."'"); |
---|
35 | if ($qry->recordCount()) |
---|
36 | $sql = "update kb3_config set cfg_value = '".$value."' |
---|
37 | where cfg_site = '".KB_SITE."' and cfg_key = '".$key."'"; |
---|
38 | else |
---|
39 | $sql = "insert into kb3_config values ( '".KB_SITE."','".$key."','".$value."' )"; |
---|
40 | $qry->execute($sql); |
---|
41 | } |
---|
42 | |
---|
43 | function getConfig($key) { |
---|
44 | global $config; |
---|
45 | if (method_exists($config, 'getConfig')) |
---|
46 | return $config->getConfig($key); |
---|
47 | $qry = new DBQuery(); |
---|
48 | $qry->query("select ".$key." from kb3_config where cfg_site = '".KB_SITE."'"); |
---|
49 | $row = $qry->getRow(); |
---|
50 | if (isset($row[$key])) |
---|
51 | return $row[$key]; |
---|
52 | return false; |
---|
53 | } |
---|
54 | |
---|
55 | function delConfig($key) { |
---|
56 | global $config; |
---|
57 | $qry = new DBQuery(); |
---|
58 | $qry->execute("delete from kb3_config where cfg_key = '".$key."' and cfg_site = '".KB_SITE."'"); |
---|
59 | } |
---|
60 | |
---|
61 | class Fetcher { |
---|
62 | |
---|
63 | function grab($url, $str) { |
---|
64 | global $x, $uurl; |
---|
65 | $x=0; |
---|
66 | $fetchurl = $url.$str; |
---|
67 | $uurl = $url; |
---|
68 | $xml_parser = xml_parser_create(); |
---|
69 | xml_set_object ( $xml_parser, $this ); |
---|
70 | xml_set_element_handler($xml_parser, "startElement", "endElement"); |
---|
71 | xml_set_character_data_handler ( $xml_parser, 'characterData' ); |
---|
72 | $fp = @fopen($fetchurl,"r"); |
---|
73 | while ($chunk = @fread($fp, 4096)) { |
---|
74 | $data .= $chunk; |
---|
75 | } |
---|
76 | $data = preg_replace('<<!--.*?-->>', '', $data); // remove <!-- Cached --> message, else it will break gzinflate |
---|
77 | |
---|
78 | if (!@gzinflate($data)) { |
---|
79 | $cprs = "raw HTML stream"; |
---|
80 | } else { |
---|
81 | $data = gzinflate($data); |
---|
82 | $cprs = "GZip compressed stream"; |
---|
83 | } |
---|
84 | |
---|
85 | if (!xml_parse( $xml_parser, $data, @feof($fp) ) && !@feof($fp) ) |
---|
86 | return "<i>Error getting XML data from ".$url."</i><br><br>"; |
---|
87 | |
---|
88 | @fclose($fp); |
---|
89 | xml_parser_free($xml_parser); |
---|
90 | |
---|
91 | if ( getConfig('fetch_verbose') ) { |
---|
92 | if ($x) |
---|
93 | $html .= "<div class=block-header2>".$x." kills added from feed: ".$url."<br>".$str." <i><br>(".$cprs.")</i><br><br></div>"; |
---|
94 | else |
---|
95 | $html .= "<div class=block-header2>No kills added from feed: ".$url."<br>".$str." <i><br>(".$cprs.")</i><br><br></div>"; |
---|
96 | } else { |
---|
97 | if ($x) |
---|
98 | $html .= "<div class=block-header2>".$x." kills added from feed: ".$url." <i>(".$cprs.")</i><br><br></div>"; |
---|
99 | else |
---|
100 | $html .= "<div class=block-header2>No kills added from feed: ".$url." <i>(".$cprs.")</i><br><br></div>"; |
---|
101 | } |
---|
102 | |
---|
103 | return $html; |
---|
104 | } |
---|
105 | |
---|
106 | function startElement($parser, $name, $attrs) { |
---|
107 | global $insideitem, $tag, $title, $description, $link; |
---|
108 | if ($insideitem) |
---|
109 | $tag = $name; |
---|
110 | elseif ($name == "ITEM") |
---|
111 | $insideitem = true; |
---|
112 | } |
---|
113 | |
---|
114 | function endElement($parser, $name) { |
---|
115 | global $insideitem, $tag, $title, $description, $link, $html, $x, $uurl; |
---|
116 | |
---|
117 | if ($name == "ITEM") { |
---|
118 | if ( isset( $description ) ) { |
---|
119 | $parser = new Parser( $description ); |
---|
120 | $killid = $parser->parse( true ); |
---|
121 | if ( $killid == 0 || $killid == -1 || $killid == -2 ) { |
---|
122 | if ( $killid == 0 && getConfig('fetch_verbose') ) |
---|
123 | $html .= "Killmail is malformed.<br>"; |
---|
124 | if ( $killid == -2 && getConfig('fetch_verbose') ) |
---|
125 | $html .= "Killmail is not related to ".KB_TITLE.".<br>"; |
---|
126 | if ( $killid == -1 && getConfig('fetch_verbose') ) |
---|
127 | $html .= "Killmail already posted <a href=\"?a=kill_detail&kll_id=".$parser->dupeid_."\">here</a>.<br>"; |
---|
128 | } |
---|
129 | else { |
---|
130 | $qry = new DBQuery(); |
---|
131 | $qry->execute( "insert into kb3_log values( ".$killid.", '".KB_SITE."','".$_SERVER['REMOTE_ADDR']."',now() )" ); |
---|
132 | $html .= "Killmail succsessfully posted <a href=\"?a=kill_detail&kll_id=".$killid."\">here</a>.<br>"; |
---|
133 | |
---|
134 | if (class_exists('Comments') && getConfig('fetch_comment')) { // for the Eve-Dev Comment Class |
---|
135 | $comments = new Comments($killid); |
---|
136 | $comments->addComment("liq's feed syndication", getConfig('fetch_comment')." mail fetched from: ".$uurl.")"); |
---|
137 | } |
---|
138 | if (class_exists('Comment') && getConfig('fetch_comment')) { // for the D2 Killboard Comment Class |
---|
139 | $comment = new Comment($killid); |
---|
140 | $comment->postComment(getConfig('fetch_comment')." \n\n\n <i>mail fetched from:\n ".$uurl."</i>", "liquidism"); |
---|
141 | } |
---|
142 | $x++; |
---|
143 | } |
---|
144 | } |
---|
145 | $title = ""; |
---|
146 | $description = ""; |
---|
147 | $link = ""; |
---|
148 | $insideitem = false; |
---|
149 | } |
---|
150 | } |
---|
151 | |
---|
152 | function characterData($parser, $data) { |
---|
153 | global $insideitem, $tag, $title, $description, $link; |
---|
154 | if ($insideitem) { |
---|
155 | switch ($tag) { |
---|
156 | case "TITLE": |
---|
157 | $title .= $data; |
---|
158 | break; |
---|
159 | case "DESCRIPTION": |
---|
160 | $description .= $data; |
---|
161 | break; |
---|
162 | case "LINK": |
---|
163 | $link .= $data; |
---|
164 | break; |
---|
165 | } |
---|
166 | } |
---|
167 | } |
---|
168 | |
---|
169 | } |
---|
170 | ?> |
---|