Merge pull request #18 from mt-site rss-hotfix...
darkmorford -
5608f9586369 merge
Not Reviewed
Show More
Add another comment
TODOs: 0 unresolved 0 Resolved
COMMENTS: 0 General 0 Inline
@@ -3,47 +3,66
3 require_once('../LocalSettings.php');
3 require_once('../LocalSettings.php');
4
4
5 /* Get the database working */
5 /* Get the database working */
6 $link = mysqli_connect(DB_SERVER, DB_READ_USER, DB_READ_PASS, DB_NAME) or trigger_error('Problem connecting to the SQL database server: '.mysqli_error($link), E_USER_ERROR);
6 $link = mysqli_connect(DB_SERVER, DB_READ_USER, DB_READ_PASS, DB_NAME)
7 or trigger_error('Problem connecting to the SQL database server: ' . mysqli_error($link), E_USER_ERROR);
7
8
8 function numeric_entities($string){
9 function numeric_entities($string)
10 {
9 $mapping = array();
11 $mapping = array();
10 foreach (get_html_translation_table(HTML_ENTITIES, ENT_QUOTES) as $char => $entity){
12 foreach (get_html_translation_table(HTML_ENTITIES, ENT_QUOTES) as $char => $entity)
13 {
11 $mapping[$entity] = '&#' . ord($char) . ';';
14 $mapping[$entity] = '&#' . ord($char) . ';';
12 }
15 }
13 return str_replace(array_keys($mapping), $mapping, $string);
16 return str_replace(array_keys($mapping), $mapping, $string);
14 }
17 }
15
18
16 function Excerpt( $excerpt ) {
19 function Excerpt($excerpt)
17 $excerpt = strip_tags( $excerpt );
20 {
18 if (strlen($excerpt) > 455) {
21 $excerpt = strip_tags($excerpt);
19 $excerpt = substr($excerpt,0,452) . '...';
22 if (strlen($excerpt) > 455)
23 {
24 $excerpt = substr($excerpt, 0, 452) . '...';
20 }
25 }
21 return $excerpt;
26 return $excerpt;
22 }
27 }
23
28
24 function datesort( $a , $b ) {
29 function datesort($a, $b)
25 if( $a->udate == $b->udate ) return 0;
30 {
26 return( $a->udate > $b->udate ) ? -1 : 1;
31 if ($a->udate == $b->udate)
32 {
33 return 0;
34 }
35
36 return ($a->udate > $b->udate) ? -1 : 1;
27 }
37 }
28
38
29 function utfentities($string)
39 function utfentities($string)
30 {
40 {
31 return htmlentities($string, ENT_COMPAT, 'UTF-8');
41 return htmlentities($string, ENT_COMPAT | ENT_XML1);
32 }
42 }
33
43
34 function _query( $s, $byid = false ) {
44 function _query($s, $byid = false)
45 {
35 global $link;
46 global $link;
36 $r = mysqli_query($link, $s ) or die( mysqli_error($link) );
47 $r = mysqli_query($link, $s) or die(mysqli_error($link));
37 $ret=array();
48 $ret = array();
38 $i=0;
49 $i = 0;
39
50
40 if( $byid ) {
51 if ($byid)
41 while ($row = mysqli_fetch_object($r) )
52 {
53 while ($row = mysqli_fetch_object($r))
54 {
42 $ret[$row->id] = $row;
55 $ret[$row->id] = $row;
43 } else {
56 }
44 while ($row = mysqli_fetch_object($r) )
57 }
58 else
59 {
60 while ($row = mysqli_fetch_object($r))
61 {
45 $ret[$i++] = $row;
62 $ret[$i++] = $row;
63 }
46 }
64 }
65
47 return $ret;
66 return $ret;
48 }
67 }
49
68
@@ -77,54 +96,66 $f_desc = 'News and Comics from Megatokyo.';
77 $f_items = array_merge( $f_items, $s );
96 $f_items = array_merge( $f_items, $s );
78 }*/
97 }*/
79
98
80 if( $type == 'strips' or $type == '') {
99 if ($type == 'strips' or $type == '')
100 {
81 $f_title = 'Megatokyo Comics';
101 $f_title = 'Megatokyo Comics';
82 $s = _query("SELECT DISTINCT s.id, UNIX_TIMESTAMP(s.published) as udate, t.description as chapdesc, t.name as chapname, s.title
102
83 FROM media_t media, strip s, strip_t t
103 $comic_query = 'SELECT s.id, UNIX_TIMESTAMP(s.published) as udate, t.description as chapdesc, t.name as chapname, s.title
84 WHERE s.media = media.id AND s.published < NOW()
104 FROM strip s JOIN strip_t t ON s.type = t.id
85 AND s.type = t.id
105 WHERE s.published <= NOW()
86 ORDER BY s.id DESC LIMIT 5") or die(mysqli_error($link));
106 ORDER BY s.id DESC LIMIT 5';
87 foreach($s as $k=>$v) {
107
108 $s = _query($comic_query) or die(mysqli_error($link));
109
110 foreach($s as $k => $v)
111 {
88 $s[$k]->link = SITE_HOST . SITE_PATH . "/strip/$v->id";
112 $s[$k]->link = SITE_HOST . SITE_PATH . "/strip/$v->id";
89 #$s[$k]->title = "Comic [$v->id] \"" . utfentities($v->title, ENT_COMPAT, ini_get('default_charset')) . '"';
113 $s[$k]->title = "Comic [$v->id] \"" . utfentities($v->title) . '"';
90 $s[$k]->title = "Comic [$v->id] \"" . numeric_entities(utfentities($v->title)) . '"';
91 $s[$k]->desc = "<![CDATA[$v->chapdesc comic $v->id
114 $s[$k]->desc = "<![CDATA[$v->chapdesc comic $v->id
92 <br/>[<a href=\"http://www.megatokyo.com/\">read...</a>]
115 <br />[<a href=\"https://megatokyo.com/\">read...</a>]
93 <br/>[<a href=\"" . $s[$k]->link . "\">permalink</a>]
116 <br />[<a href=\"" . $s[$k]->link . "\">permalink</a>]
94 ]]>";
117 ]]>";
95 $s[$k]->date = date( DATE_RSS, $v->udate );
118 $s[$k]->date = date(DATE_RSS, $v->udate);
96 $s[$k]->guid = $s[$k]->link;
119 $s[$k]->guid = $s[$k]->link;
97 $s[$k]->perm = 'true';
120 $s[$k]->perm = 'true';
98 }
121 }
99 $f_items = array_merge( $f_items, $s );
122
123 $f_items = array_merge($f_items, $s);
100 }
124 }
101
125
102 if( $type == 'rants' or $type == '' ) {
126 if ($type == 'rants' or $type == '')
127 {
103 $f_title = 'Megatokyo Rants';
128 $f_title = 'Megatokyo Rants';
104 $contributers = _query("SELECT * FROM contributor", true);
129
105 $s = _query("SELECT r.id, r.body as body, UNIX_TIMESTAMP(r.published) as udate, r.author as authorno, r.title
130 $rant_query = 'SELECT r.id, r.body, UNIX_TIMESTAMP(r.published) as udate, c.name, r.title
106 FROM rant r
131 FROM rant r JOIN contributor c ON r.author = c.id
107 WHERE r.published < NOW()
132 WHERE r.published <= NOW() AND r.status = "published"
108 AND r.status = 'published'
133 ORDER BY r.published DESC LIMIT 5';
109 ORDER BY udate DESC LIMIT 5");
134
110 foreach($s as $k=>$v) {
135 $s = _query($rant_query) or die(mysqli_error($link));
136
137 foreach($s as $k => $v)
138 {
111 $s[$k]->link = SITE_HOST . SITE_PATH . "/rant/$v->id";
139 $s[$k]->link = SITE_HOST . SITE_PATH . "/rant/$v->id";
112 $s[$k]->author = utfentities( $contributers[$v->authorno]->name, ENT_COMPAT, ini_get('default_charset') );
140 $s[$k]->author = utfentities($v->name);
113 $s[$k]->title = "Rant [$v->id] \"" . utfentities($v->title, ENT_COMPAT, ini_get('default_charset')) . '"';
141 $s[$k]->title = "Rant [$v->id] \"" . utfentities($v->title) . '"';
114 $s[$k]->desc = "<![CDATA[" . Excerpt($v->body) . "<p>[<a href=\"" . $s[$k]->link . "\">permalink</a>]</p>]]>";
142 $s[$k]->desc = "<![CDATA[" . Excerpt($v->body) . "<p>[<a href=\"" . $s[$k]->link . "\">permalink</a>]</p>]]>";
115 $s[$k]->date = date( DATE_RSS, $v->udate );
143 $s[$k]->date = date(DATE_RSS, $v->udate);
116 $s[$k]->guid = $s[$k]->link;
144 $s[$k]->guid = $s[$k]->link;
117 $s[$k]->perm = 'true';
145 $s[$k]->perm = 'true';
118 }
146 }
119 $f_items = array_merge( $f_items, $s );
147
148 $f_items = array_merge($f_items, $s);
120 }
149 }
121
150
122 if( $type == '' )
151 if ($type == '')
123 {
152 {
124 $f_title = 'Megatokyo Comics and News';
153 $f_title = 'Megatokyo Comics and News';
154
155 /*
125 $s = _query("SELECT UNIX_TIMESTAMP(published) as udate, body, url FROM rss_comment ORDER BY published DESC LIMIT 5");
156 $s = _query("SELECT UNIX_TIMESTAMP(published) as udate, body, url FROM rss_comment ORDER BY published DESC LIMIT 5");
126
157
127 foreach($s as $k=>$v)
158 foreach($s as $k => $v)
128 {
159 {
129 $s[$k]->link = $v->url;
160 $s[$k]->link = $v->url;
130 $s[$k]->title = $v->body;
161 $s[$k]->title = $v->body;
@@ -133,48 +164,53 if( $type == '' )
133 $s[$k]->desc = '';
164 $s[$k]->desc = '';
134 $s[$k]->perm = 'false';
165 $s[$k]->perm = 'false';
135 }
166 }
167
136 $f_items = array_merge( $f_items, $s );
168 $f_items = array_merge( $f_items, $s );
169 */
137 }
170 }
138
171
139 usort( $f_items, 'datesort' );
172 usort($f_items, 'datesort');
140
173
141 $f_date = $f_items[0]->date;
174 $f_date = $f_items[0]->date;
142
175
143 $rfc1123_date = gmdate( 'D, d M Y H:i:s ', $f_items[0]->udate ) . 'GMT';
176 $rfc1123_date = gmdate('D, d M Y H:i:s T', $f_items[0]->udate);
144 $etag = md5( $rfc1123_date );
177 $etag = md5($rfc1123_date);
145
178
146 /* Conditional Get */
179 /* Conditional Get */
147 header( "Last-Modified: $rfc1123_date" );
180 header("Last-Modified: $rfc1123_date");
148 header( "ETag: \"$etag\"");
181 header("ETag: \"$etag\"");
149
182
150 if( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $rfc1123_date ) {
183 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $rfc1123_date)
184 {
151 header('HTTP/1.0 304 Not Modified');
185 header('HTTP/1.0 304 Not Modified');
152 exit;
186 exit;
153 }
187 }
154 if( isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag ) {
188
189 if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag)
190 {
155 header('HTTP/1.0 304 Not Modified');
191 header('HTTP/1.0 304 Not Modified');
156 exit;
192 exit;
157 }
193 }
158
194
159 header("XX-Powered-By: Nikuman");
195 header("XX-Powered-By: Nikuman");
160 header("Content-Type: application/rss+xml;charset=utf-8");
196 header("Content-Type: application/rss+xml; charset=utf-8");
161
197
162 echo '<?xml version="1.0" encoding="utf-8"?>', "\n";
198 echo '<?xml version="1.0" encoding="utf-8"?>', "\n";
163 ?>
199 ?>
164 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
200 <rss version="2.0">
165 <channel>
201 <channel>
166 <title><?php echo $f_title; ?></title>
202 <title><?php echo $f_title; ?></title>
167 <link>http://www.megatokyo.com</link>
203 <link>https://megatokyo.com</link>
168 <atom:link href="<?php echo SITE_HOST . $_SERVER['REQUEST_URI'] ?>" rel="self" type="application/rss+xml" />
169 <description><?php echo $f_desc; ?></description>
204 <description><?php echo $f_desc; ?></description>
170 <language>en-us</language>
205 <language>en-US</language>
171 <copyright>Fred Gallagher</copyright>
206 <copyright>Fred Gallagher</copyright>
172 <managingEditor>piro@megatokyo.com (Fred Gallagher)</managingEditor>
207 <managingEditor>piro@megatokyo.com (Fred Gallagher)</managingEditor>
208 <docs>http://cyber.harvard.edu/rss/rss.html</docs>
173 <pubDate><?php echo $f_date; ?></pubDate>
209 <pubDate><?php echo $f_date; ?></pubDate>
174 <lastBuildDate><?php echo $f_date; ?></lastBuildDate>
210 <lastBuildDate><?php echo $f_date; ?></lastBuildDate>
175 <ttl>15</ttl>
211 <ttl>15</ttl>
176
212
177 <?php if( count( $f_items )) foreach( $f_items as $v ): ?>
213 <?php foreach ($f_items as $v) { ?>
178 <item>
214 <item>
179 <title><?php echo $v->title; ?></title>
215 <title><?php echo $v->title; ?></title>
180 <link><?php echo $v->link; ?></link>
216 <link><?php echo $v->link; ?></link>
@@ -182,6 +218,6 echo '<?xml version="1.0" encoding="utf-8"?>', "\n";
182 <guid isPermaLink="<?php echo $v->perm; ?>"><?php echo $v->guid; ?></guid>
218 <guid isPermaLink="<?php echo $v->perm; ?>"><?php echo $v->guid; ?></guid>
183 <pubDate><?php echo $v->date; ?></pubDate>
219 <pubDate><?php echo $v->date; ?></pubDate>
184 </item>
220 </item>
185 <?php endforeach; ?>
221 <?php } ?>
186 </channel>
222 </channel>
187 </rss>
223 </rss>
1 NO CONTENT: file was removed
NO CONTENT: file was removed
Comments 0
You need to be logged in to leave comments. Login now