Skip to content

Commit

Permalink
Homepage|Web: Cache blog news feeds and the latest stable release
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 7, 2017
1 parent 8433b6c commit 319ca84
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 49 deletions.
85 changes: 36 additions & 49 deletions web/plugins/z#home/home.php
Expand Up @@ -59,37 +59,44 @@ public function execute($args=NULL)
//includeHTML('latestversion', 'z#home');

require_once(DENG_API_DIR.'/include/builds.inc.php');

$user_platform = detect_user_platform();
$dl_link = 'http://dengine.net/';
switch ($user_platform) {
case 'windows':
$dl_link .= 'windows';
break;
case 'macx':
$dl_link .= 'mac_os';
break;
case 'linux':
$dl_link .= 'linux';
break;
default:
$dl_link .= 'source';
break;
}
// Find out the latest stable build.
$db = db_open();
$result = db_query($db, "SELECT version FROM ".DB_TABLE_BUILDS
." WHERE type=".BT_STABLE." ORDER BY timestamp DESC LIMIT 1");
if ($row = $result->fetch_assoc()) {
$button_label = omit_zeroes($row['version']);
}
else {
$button_label = 'Download';
$ckey = cache_key('home', ['latest_stable', $user_platform]);
if (cache_try_load($ckey)) {
cache_dump();
}
$db->close();
else {
$dl_link = 'http://dengine.net/';
switch ($user_platform) {
case 'windows':
$dl_link .= 'windows';
break;
case 'macx':
$dl_link .= 'mac_os';
break;
case 'linux':
$dl_link .= 'linux';
break;
default:
$dl_link .= 'source';
break;
}
// Find out the latest stable build.
$db = db_open();
$result = db_query($db, "SELECT version FROM ".DB_TABLE_BUILDS
." WHERE type=".BT_STABLE." ORDER BY timestamp DESC LIMIT 1");
if ($row = $result->fetch_assoc()) {
$button_label = omit_zeroes($row['version']);
}
else {
$button_label = 'Download';
}
$db->close();

echo("<div id='latestversion'><h1><div class='download-button'><a href='$dl_link' title='Download latest stable release'>$button_label <span class='downarrow'>&#x21E3;</span></a></div></h1></div>\n");
cache_echo("<div id='latestversion'><h1><div class='download-button'><a href='$dl_link' title='Download latest stable release'>$button_label <span class='downarrow'>&#x21E3;</span></a></div></h1></div>\n");

cache_dump();
cache_store($ckey);
}
?><div id="contentbox"><?php

//includeHTML('introduction', 'z#home');
Expand Down Expand Up @@ -324,28 +331,8 @@ public function execute($args=NULL)
}
});

/*$('#column1').interpretFeed({
feedUri: 'http://files.dengine.net/builds/events.rss',
dataType: 'xml',
maxItems: 3,
clearOnSuccess: false,
generateItemHtml: function (n, t) {
var html = '<div class="block"><article class="buildevent"><header><h1><a href="' + t.link + '" title="Read more about ' + t.title + ' in the repository">' + t.title + '</a></h1>';
var d = new Date(t.pubDate);
var niceDate = $.datepicker.formatDate('MM d, yy', d);
html += '<p><time datetime="' + d.toISOString() + '" pubdate>' + niceDate + '</time></p>';
html += '</header><br />';
html += t.atomSummary;
html += '</article>';
html += '<div class="links"><a href="' + n.feedUri + '" class="link-rss" title="Doomsday Engine build events are reported via RSS">All builds</a></div></div>';
return '<li>' + html + '</li>';
}
});*/

$('#column2').interpretFeed({
feedUri: 'http://dengine.net/blog/category/news/?json=true',
feedUri: 'http://api.dengine.net/1/news?category=news',
dataType: 'json',
clearOnSuccess: false,
maxItems: 2,
Expand All @@ -365,7 +352,7 @@ public function execute($args=NULL)
});

$('#column1').interpretFeed({
feedUri: 'http://dengine.net/blog/category/dev/?json=true',
feedUri: 'http://api.dengine.net/1/news?category=dev',
dataType: 'json',
clearOnSuccess: false,
maxItems: 1,
Expand Down
54 changes: 54 additions & 0 deletions webapi/1/news.php
@@ -0,0 +1,54 @@
<?php
/*
* Doomsday Web API: News
* Copyright (c) 2017 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* License: GPL v2+
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses/gpl.html
*/

require_once('include/cache.inc.php');

function fetch_blog_feed($category)
{
header('Content-Type: application/json');

$json_url = "http://dengine.net/blog/category/$category/?json=true";
$ckey = cache_key('news', $category);
if (cache_try_load($ckey)) {
cache_dump();
return;
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $json_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // as a string
$output = curl_exec($ch);
curl_close($ch);

cache_echo($output);

cache_dump();
cache_store($ckey);
}

//---------------------------------------------------------------------------------------

setlocale(LC_ALL, 'en_US.UTF-8');

if ($_SERVER['REQUEST_METHOD'] == 'GET') {
if ($category = $_GET['category']) {
if ($category == 'news' || $category == 'dev') {
fetch_blog_feed($category);
}
}
}

0 comments on commit 319ca84

Please sign in to comment.