Start: Added forum box with latest posts
This commit is contained in:
committed by
Yorik van Havre
parent
5bc02545ca
commit
36cd5a55cf
@@ -1,63 +0,0 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2018 Yorik van Havre <yorik@uncreated.net> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* 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 Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
# NOT WORKING - for further implementation
|
||||
|
||||
# The forum has a "last posts" feed at
|
||||
# https://forum.freecadweb.org/feed.php
|
||||
# Javascript can't fetch it directly, because of cross-domain prohibition
|
||||
# We can't fetch this from python at StartPAge load, becuase it could take
|
||||
# several seconds or even fail
|
||||
# So the idea is to have javascript call this script here, which would
|
||||
# do it, then find a way to make the result available back to javascript
|
||||
# a tempfile, for example...
|
||||
|
||||
url = "https://forum.freecadweb.org/feed.php"
|
||||
from xml.etree.ElementTree import parse
|
||||
xml = parse(urllib.urlopen(url)).getroot()
|
||||
items = []
|
||||
channel = xml.find('channel')
|
||||
for element in channel.findall('item'):
|
||||
items.append({'title': element.find('title').text,
|
||||
'description': element.find('description').text,
|
||||
'link': element.find('link').text})
|
||||
if len(items) > numitems:
|
||||
items = items[:numitems]
|
||||
resp = '<ul>'
|
||||
for item in items:
|
||||
descr = re.compile("style=\".*?\"").sub('',item['description'])
|
||||
descr = re.compile("alt=\".*?\"").sub('',descr)
|
||||
descr = re.compile("\"").sub('',descr)
|
||||
d1 = re.findall("<img.*?>",descr)[0]
|
||||
d2 = re.findall("<span>.*?</span>",descr)[0]
|
||||
descr = "<h3>" + item['title'] + "</h3>"
|
||||
descr += d1 + "<br/>"
|
||||
descr += d2
|
||||
resp += '<li><a onMouseover="show(\''
|
||||
resp += descr
|
||||
resp += '\')" onMouseout="show(\'\')" href="'
|
||||
resp += item['link']
|
||||
resp += '">'
|
||||
resp += item['title']
|
||||
resp += '</a></li>'
|
||||
resp += '</ul>'
|
||||
print(resp)
|
||||
@@ -106,7 +106,7 @@
|
||||
|
||||
<h2>T_RECENTCOMMITS</h2>
|
||||
|
||||
<p>T_DESCR_RECENTCOMMITS</p>
|
||||
<div class="footnote">T_DESCR_RECENTCOMMITS</div>
|
||||
|
||||
<div id="commits">T_OFFLINEPLACEHOLDER</div>
|
||||
|
||||
@@ -117,6 +117,16 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="docbox allwidth">
|
||||
|
||||
<h2>T_FORUM</h2>
|
||||
|
||||
<div class="footnote">T_DESCR_FORUM</div>
|
||||
|
||||
<div id="forum">T_OFFLINEPLACEHOLDER</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
var allowDownloads = 0;
|
||||
|
||||
|
||||
function toggle(tab) {
|
||||
|
||||
// switch to the given tab ID ("tab1", "tab2", etc...)
|
||||
|
||||
var tabs = document.getElementById("tabs").childElementCount;
|
||||
document.getElementById(tab).classList.remove("hidden");
|
||||
document.getElementById("h"+tab).classList.add("active");
|
||||
@@ -13,7 +16,11 @@ function toggle(tab) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function load() {
|
||||
|
||||
// run at startup
|
||||
|
||||
if (allowDownloads == 1) {
|
||||
// load latest commits
|
||||
ddiv = document.getElementById("commits");
|
||||
@@ -29,10 +36,21 @@ function load() {
|
||||
tobj.buildScriptTag(); // Build the script tag
|
||||
tobj.addScriptTag(); // Execute (add) the script tag
|
||||
ddiv.innerHTML = "Downloading addons list...";
|
||||
// load forum recent posts
|
||||
ddiv = document.getElementById("forum");
|
||||
ddiv.innerHTML = "Connecting...";
|
||||
var tobj=new JSONscriptRequest('https://api.rss2json.com/v1/api.json?rss_url=https%3A%2F%2Fforum.freecadweb.org%2Ffeed.php&api_key=s9yqcsrevp9irkqworzmvnrjs4jotjac2g4ybs95&callback=printForum');
|
||||
tobj.buildScriptTag(); // Build the script tag
|
||||
tobj.addScriptTag(); // Execute (add) the script tag
|
||||
ddiv.innerHTML = "Downloading addons list...";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function printCommits(data) {
|
||||
|
||||
// json callback for git commits
|
||||
|
||||
ddiv = document.getElementById('commits');
|
||||
ddiv.innerHTML = "Received";
|
||||
var html = ['<ul>'];
|
||||
@@ -43,7 +61,11 @@ function printCommits(data) {
|
||||
ddiv.innerHTML = html.join('');
|
||||
}
|
||||
|
||||
|
||||
function printAddons(data) {
|
||||
|
||||
// json callback for addons list
|
||||
|
||||
ddiv = document.getElementById('addons');
|
||||
ddiv.innerHTML = "Received";
|
||||
var html = ['<ul class="addonslist">'];
|
||||
@@ -57,10 +79,29 @@ function printAddons(data) {
|
||||
ddiv.innerHTML = html.join('');
|
||||
}
|
||||
|
||||
|
||||
function printForum(data) {
|
||||
|
||||
// json callback for forum posts
|
||||
|
||||
ddiv = document.getElementById('forum');
|
||||
ddiv.innerHTML = "Received";
|
||||
var html = ['<ul>'];
|
||||
for (var i = 0; i < 25; i++) {
|
||||
if (i < data.items.length){
|
||||
html.push('<li><a href="', data.items[i].link, '">', data.items[i].title, '</a><br/><p>', data.items[i].content,'</p></li>');
|
||||
}
|
||||
}
|
||||
html.push('</ul>');
|
||||
ddiv.innerHTML = html.join('');
|
||||
}
|
||||
|
||||
|
||||
// below are JSON helper functions
|
||||
|
||||
|
||||
function JSONscriptRequest(fullUrl) {
|
||||
|
||||
// REST request path
|
||||
this.fullUrl = fullUrl;
|
||||
// Get the DOM location to put the script tag
|
||||
@@ -69,10 +110,13 @@ function JSONscriptRequest(fullUrl) {
|
||||
this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
|
||||
}
|
||||
|
||||
|
||||
// Static script ID counter
|
||||
JSONscriptRequest.scriptCounter = 1;
|
||||
|
||||
|
||||
JSONscriptRequest.prototype.buildScriptTag = function () {
|
||||
|
||||
// Create the script tag
|
||||
this.scriptObj = document.createElement("script");
|
||||
// Add script object attributes
|
||||
@@ -82,6 +126,7 @@ JSONscriptRequest.prototype.buildScriptTag = function () {
|
||||
this.scriptObj.setAttribute("id", this.scriptId);
|
||||
}
|
||||
|
||||
|
||||
JSONscriptRequest.prototype.removeScriptTag = function () {
|
||||
// Destroy the script tag
|
||||
this.headLoc.removeChild(this.scriptObj);
|
||||
|
||||
@@ -34,7 +34,6 @@ iconprovider = QtGui.QFileIconProvider()
|
||||
iconbank = {} # to store already created icons
|
||||
|
||||
|
||||
|
||||
def gethexcolor(color):
|
||||
|
||||
"returns a color hex value #000000"
|
||||
@@ -211,7 +210,8 @@ def handle():
|
||||
HTML = HTML.replace("T_DESCR_RECENTCOMMITS",TranslationTexts.T_DESCR_RECENTCOMMITS)
|
||||
HTML = HTML.replace("T_SEEONGITHUB",TranslationTexts.T_SEEONGITHUB)
|
||||
HTML = HTML.replace("T_CUSTOM",TranslationTexts.T_CUSTOM)
|
||||
|
||||
HTML = HTML.replace("T_FORUM",TranslationTexts.T_FORUM)
|
||||
HTML = HTML.replace("T_DESCR_FORUM",TranslationTexts.T_DESCR_FORUM)
|
||||
|
||||
# build a "create new" icon with the FreeCAD background color gradient
|
||||
|
||||
@@ -390,6 +390,7 @@ def handle():
|
||||
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Start").GetBool("AllowDownload",False):
|
||||
HTML = HTML.replace("var allowDownloads = 0;","var allowDownloads = 1;")
|
||||
|
||||
|
||||
# encode if necessary
|
||||
|
||||
if sys.version_info.major < 3:
|
||||
|
||||
@@ -72,5 +72,7 @@ T_VERSION = translate("StartPage", "version")
|
||||
T_BUILD = translate("StartPage", "build")
|
||||
T_CREATENEW = translate("StartPage", "Create new...")
|
||||
T_UNKNOWN = translate("StartPage", "Unknown")
|
||||
T_FORUM = translate("StartPage", "Forum")
|
||||
T_DESCR_FORUM = translate("StartPage", "The latest posts on the <a href=\"https://forum.freecadweb.org\">FreeCAD forum</a>:")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user