- web: bb2html() previously generated HTML that assumed

the BOINC stylesheet (main.css) was included.
    This is no good if we're exporting the HTML.
    Add an option to generate generic HTML.
- web: add options to the forum RSS feed:
    1) threads_only: just show threads (i.e. 1st post in each thread)
    2) truncate: truncate posts to 256 chars.
        If this is not set, convert post from BBcode to generic HTML,
        and put this (XML-encoded) in item.description
This is preparation for using the forum code for project news,
and for displaying forum RSS feeds in the manager.


svn path=/trunk/boinc/; revision=19915
This commit is contained in:
David Anderson 2009-12-15 17:57:36 +00:00
parent 5e5f6a357c
commit 1b7f0aa88a
4 changed files with 126 additions and 48 deletions

View File

@ -10076,3 +10076,22 @@ David 14 Dec 2009
client/
cs_scheduler.cpp
David 15 Dec 2009
- web: bb2html() previously generated HTML that assumed
the BOINC stylesheet (main.css) was included.
This is no good if we're exporting the HTML.
Add an option to generate generic HTML.
- web: add options to the forum RSS feed:
1) threads_only: just show threads (i.e. 1st post in each thread)
2) truncate: truncate posts to 256 chars.
If this is not set, convert post from BBcode to generic HTML,
and put this (XML-encoded) in item.description
This is preparation for using the forum code for project news,
and for displaying forum RSS feeds in the manager.
html/
inc/
text_transform.inc
user/
forum_rss.php

View File

@ -214,6 +214,7 @@ function language_form() {
."<option value=en>English"
."<option value=es>Espa&ntilde;ol (Spanish)"
."<option value=fr>Fran&ccedil;ais (French)"
."<option value=el>Ελληνικά (Greek)"
."<option value=ja>日本語 (Japanese)"
."<option value=ko>한국어 (Korean)"
//."<option value=lt>Lietuvių (Lithuanian)"

View File

@ -102,8 +102,9 @@ function get_output_options($user) {
}
// Converts bbcode to proper HTML
// If $export is true, don't use BOINC CSS
function bb2html($text) {
function bb2html($text, $export=false) {
$urlregex = "(?:\"?)(?:(http\:\/\/)?)([^\[\"<\ ]+)(?:\"?)";
$httpsregex = "(?:\"?)https\:\/\/([^\[\"<\ ]+)(?:\"?)";
// List of allowable tags
@ -138,32 +139,61 @@ function bb2html($text) {
);
// What the above tags are turned in to
$htmltags = array (
"'<div class=\"pre\">'.stop_recursion(remove_br('\\1')).'</div>'",
"'<div class=\"code\">'.stop_recursion('\\1').'</div>'",
"<b>\\1</b>",
"<i>\\1</i>",
"<u>\\1</u>",
"<a href=\"https://\\1\" rel=\"nofollow\">\\2</a>",
"<a href=\"https://\\1\" rel=\"nofollow\">https://\\1</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"<div style='font-style: oblique'>\\1 wrote:</div><blockquote class='postbody'>\\2</blockquote>",
"<blockquote class='postbody'>\\1</blockquote>",
"<ul>\\1</ul><p>",
"<ol>\\1</ol><p>",
"<img src=\"http://\\2\">",
"<font color=\"\\1\">\\2</font>",
"\\1<li>\\2\n\\3",
"<span style=\"font-size: \\1px;\">\\2</span>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/ticket/\\1\">#\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/wiki/\\1\">\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/changeset/\\1\">[\\1]</a>"
);
if ($export) {
$htmltags = array (
"'<pre>'.stop_recursion(remove_br('\\1')).'</pre>'",
"'<code>'.stop_recursion('\\1').'</code>'",
"<b>\\1</b>",
"<i>\\1</i>",
"<u>\\1</u>",
"<a href=\"https://\\1\" rel=\"nofollow\">\\2</a>",
"<a href=\"https://\\1\" rel=\"nofollow\">https://\\1</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"<i>\\1 wrote:</i><blockquote>\\2</blockquote>",
"<blockquote>\\1</blockquote>",
"<ul>\\1</ul><p>",
"<ol>\\1</ol><p>",
"<img src=\"http://\\2\">",
"<font color=\"\\1\">\\2</font>",
"\\1<li>\\2\n\\3",
"<span style=\"font-size: \\1px;\">\\2</span>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/ticket/\\1\">#\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/wiki/\\1\">\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/changeset/\\1\">[\\1]</a>"
);
} else {
$htmltags = array (
"'<div class=\"pre\">'.stop_recursion(remove_br('\\1')).'</div>'",
"'<div class=\"code\">'.stop_recursion('\\1').'</div>'",
"<b>\\1</b>",
"<i>\\1</i>",
"<u>\\1</u>",
"<a href=\"https://\\1\" rel=\"nofollow\">\\2</a>",
"<a href=\"https://\\1\" rel=\"nofollow\">https://\\1</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"<div style='font-style: oblique'>\\1 wrote:</div><blockquote class='postbody'>\\2</blockquote>",
"<blockquote class='postbody'>\\1</blockquote>",
"<ul>\\1</ul><p>",
"<ol>\\1</ol><p>",
"<img src=\"http://\\2\">",
"<font color=\"\\1\">\\2</font>",
"\\1<li>\\2\n\\3",
"<span style=\"font-size: \\1px;\">\\2</span>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/ticket/\\1\">#\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/wiki/\\1\">\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/changeset/\\1\">[\\1]</a>"
);
}
// Do the actual replacing - iterations for nested items
$lasttext = "";

View File

@ -16,7 +16,16 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// get a forum (possibly filtered by user) as RSS feed
// get a forum as RSS feed
// arguments:
// threads_only
// If true, only show threads (not posts within a thread)
// by decreasing create time
// Else enumerate threads by decreasing timestamp,
// and show the post with latest timestamp for each
// truncate
// If true, truncate posts to 256 chars and show BBcode
// else show whole post and convert to HTML
require_once("../project/project.inc");
require_once("../inc/db.inc");
@ -37,6 +46,10 @@ if (get_int('setup', true)) {
<p>
Include only the <input name=nitems> most recent posts (default: 20).
<p>
Truncate posts <input type=checkbox name=truncate checked>
<p>
Threads only <input type=checkbox name=threads_only>
<p>
<input type=submit value=OK>
";
page_tail();
@ -45,12 +58,13 @@ if (get_int('setup', true)) {
$userid = get_int('userid', true);
$nitems = get_int('nitems', true);
$truncate = get_str('truncate', true);
$threads_only = get_str('threads_only', true);
if(!$nitems || $nitems < "1" || $nitems > "20") {
$nitems = "20";
}
$clause = "forum=$forumid ";
if ($userid) {
@ -59,32 +73,29 @@ if ($userid) {
$clause .= " and owner=$userid";
}
class Int {
};
$db = BoincDb::get();
$x = $db->lookup_fields(
"thread",
"Int",
"max(timestamp) as foo",
"$clause and status=0 and hidden=0 and sticky=0"
);
$last_mod_time = $x->foo;
if ($threads_only) {
$q = "$clause and status=0 and hidden=0 and sticky=0 order by create_time desc limit $nitems";
} else {
$q = "$clause and status=0 and hidden=0 and sticky=0 order by timestamp desc limit $nitems";
}
$threads = BoincThread::enum("$clause and status=0 and hidden=0 and sticky=0 order by create_time desc limit $nitems"
);
$threads = BoincThread::enum($q);
// Get unix time that last modification was made to the news source
//
$create_date = gmdate('D, d M Y H:i:s', $last_mod_time) . ' GMT';
// Now construct header
//
header ("Expires: " . gmdate('D, d M Y H:i:s', time()+86400) . " GMT");
header ("Last-Modified: " . $create_date);
if (sizeof($threads)) {
$t = $threads[0];
$last_mod_time = $threads_only?$t->create_time:$t->timestamp;
$create_date = gmdate('D, d M Y H:i:s', $last_mod_time) . ' GMT';
header ("Last-Modified: " . $create_date);
}
header ("Content-Type: application/xml");
// Create channel header and open XML content
//
$description = PROJECT.": $forum->description";
@ -112,17 +123,34 @@ echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>
// write news items
//
foreach ($threads as $thread) {
$post_date=gmdate('D, d M Y H:i:s',$thread->create_time).' GMT';
$unique_url=URL_BASE."forum_thread.php?id=".$thread->id;
$clause2 = $userid?"and user=$userid":"";
$posts = BoincPost::enum("thread=$thread->id $clause2 order by timestamp limit 1");
$clause2 = " and hidden=0 ";
if ($userid) $clause2 .= "and user=$userid";
if ($threads_only) {
$posts = BoincPost::enum("thread=$thread->id $clause2 order by id limit 1");
} else {
$posts = BoincPost::enum("thread=$thread->id $clause2 order by timestamp desc limit 1");
}
$post = $posts[0];
$post_date=gmdate('D, d M Y H:i:s',$post->timestamp).' GMT';
if ($truncate) {
if (strlen($post->content) > 256) {
$t = substr($post->content, 0, 256).". . .";
} else {
$t = $post->content;
}
$t = htmlspecialchars(htmlspecialchars(htmlspecialchars($t)));
// in this case we don't want to convert BBcode to HTML
// because there might be unclosed tags
} else {
$t = htmlspecialchars(bb2html($post->content, true));
}
echo "<item>
<title>".strip_tags($thread->title)."</title>
<link>$unique_url</link>
<guid isPermaLink=\"true\">$unique_url</guid>
<description>".htmlspecialchars(htmlspecialchars(substr($post->content,0,255)))." . . .</description>
<description>$t</description>
<pubDate>$post_date</pubDate>
</item>
";