";$out[]="[/pre]";
-
- $in[]="";$out[]="\n";
- $in[]=" ";$out[]="\n";
- $in[]=" ";$out[]="\n";
- $in[]=">";$out[]=">";
- $in[]="<";$out[]="<";
- $in[]="&";$out[]="&";
-
- return str_replace($in, $out, $text);
-}
-
-function fix_text($text) {
- $text = sanitize_html($text);
- $text = image_as_bb($text);
- $text = link_as_bb($text);
- $text = formatting_as_bb($text);
- return $text;
-}
-
function fix_forum_preferences($forum_preferences) {
- $text = fix_text($forum_preferences->signature);
+ $text = html_to_bbcode($forum_preferences->signature);
if ($text != $forum_preferences->signature) {
$query = "update forum_preferences set signature = '".mysql_escape_string($text)."' where userid=".$forum_preferences->userid;
//echo "$forum_preferences->signature\n\n";
diff --git a/html/ops/create_forums.php b/html/ops/create_forums.php
index 04edba62ae..967bfeb858 100644
--- a/html/ops/create_forums.php
+++ b/html/ops/create_forums.php
@@ -38,8 +38,8 @@ function create_category($orderID, $name, $is_helpdesk) {
return mysql_insert_id();
}
-function create_forum($category, $orderID, $title, $description) {
- $q = "insert into forum (category, orderID, title, description) values ($category, $orderID, '$title', '$description')";
+function create_forum($category, $orderID, $title, $description, $is_dev_blog=0) {
+ $q = "insert into forum (category, orderID, title, description, is_dev_blog) values ($category, $orderID, '$title', '$description', $is_dev_blog)";
$result = mysql_query($q);
if (!$result) {
echo "can't create forum\n";
@@ -52,9 +52,10 @@ function create_forum($category, $orderID, $title, $description) {
db_init();
$catid = create_category(0, "", 0);
-create_forum($catid, 0, "Science", "Discussion of this project\'s science");
-create_forum($catid, 1, "Number crunching", "Credit, leaderboards, CPU performance");
-create_forum($catid, 2, "Cafe", "Meet and greet other participants");
+create_forum($catid, 0, "News", "News from this project", 1);
+create_forum($catid, 1, "Science", "Discussion of this project\'s science");
+create_forum($catid, 2, "Number crunching", "Credit, leaderboards, CPU performance");
+create_forum($catid, 3, "Cafe", "Meet and greet other participants");
$catid = create_category(0, "Platform-specific problems", 1);
create_forum($catid, 0, "Windows", "Installing and running BOINC on Windows");
diff --git a/html/ops/news_convert.php b/html/ops/news_convert.php
new file mode 100755
index 0000000000..0720d24627
--- /dev/null
+++ b/html/ops/news_convert.php
@@ -0,0 +1,112 @@
+#!/usr/bin/env php
+.
+
+// This script converts the old file-based news (project_news.inc)
+// into the new forum-based format.
+
+error_reporting(E_ALL);
+ini_set('display_errors', true);
+ini_set('display_startup_errors', true);
+
+require_once("../project/project_news.inc");
+require_once("../inc/forum_db.inc");
+require_once("../inc/forum.inc");
+require_once("../inc/bbcode_convert.inc");
+
+$forum_name = "News";
+$forum_desc = "News from this project";
+
+echo "This script exports project news from the project_news.inc file
+to a message board.
+Do you want to do this (y/n)? ";
+
+$stdin = fopen("php://stdin", "r");
+$x = trim(fgets($stdin));
+if ($x != "y") {
+ exit;
+}
+
+while (1) {
+ echo "Enter the email address of admin account to appear as poster: ";
+ $x = trim(fgets($stdin));
+ $user = BoincUser::lookup("email_addr='$x'");
+ if (!$user) {
+ echo "No such user\n";
+ continue;
+ }
+ BoincForumPrefs::lookup($user);
+ if (!$user->prefs->privilege(S_ADMIN)) {
+ echo "User doesn't have admin privileges";
+ continue;
+ }
+ break;
+}
+
+$category = BoincCategory::lookup("orderID=0 and is_helpdesk=0");
+if (!$category) {
+ die("can't find category");
+}
+
+$forum = BoincForum::lookup("parent_type=0 and title='$forum_name'");
+if ($forum) {
+ die("News forum already exists");
+}
+
+$now = time();
+$forum_id = BoincForum::insert("(category, orderID, title, description, timestamp, is_dev_blog, parent_type) values ($category->id, -1, '$forum_name', '$forum_desc', $now, 1, 0)");
+$forum = BoincForum::lookup_id($forum_id);
+
+foreach (array_reverse($project_news) as $item) {
+ $content = $item[1];
+ if (isset($item[2])) {
+ $title = $item[2];
+ } else {
+ $n = strpos($content, ".");
+ if ($n) {
+ $title = substr($content, 0, $n);
+ } else {
+ $title = $content;
+ }
+ }
+ $when = strtotime($item[0]);
+ $title = mysql_real_escape_string($title);
+ $content = html_to_bbcode($content);
+ $content = mysql_real_escape_string($content);
+
+ $thread_id = BoincThread::insert("(forum, owner, title, create_time, timestamp, replies) values ($forum_id, $user->id, '$title', $when, $when, 0)");
+ if (!$thread_id) die("thread insert failed");
+
+ $id = BoincPost::insert("(thread, user, timestamp, content) values ($thread_id, $user->id, $when, '$content')");
+ if (!$id) die("post insert");
+
+ $forum->update("threads=threads+1, posts=posts+1");
+}
+
+echo "
+
+Project news has been successfully converted from
+html/project/project_news.inc to forum format.
+Change your index.php to use
+ show_news(0, 5)
+to show news and related links.
+
+If everything looks OK, you can delete html/project/project_news.inc
+
+";
+?>
diff --git a/html/project.sample/project_news.inc b/html/project.sample/project_news.inc
deleted file mode 100644
index f014441640..0000000000
--- a/html/project.sample/project_news.inc
+++ /dev/null
@@ -1,23 +0,0 @@
-
diff --git a/html/user/all_news.php b/html/user/all_news.php
index fc141e5c41..bcf315c800 100644
--- a/html/user/all_news.php
+++ b/html/user/all_news.php
@@ -18,11 +18,10 @@
require_once("../inc/util.inc");
require_once("../inc/news.inc");
-require_once("../project/project_news.inc");
page_head("News archive");
-show_old_news($project_news, 0);
+show_old_news(0, 0);
page_tail();
diff --git a/html/user/forum_forum.php b/html/user/forum_forum.php
index cf7b879747..5054d7594b 100644
--- a/html/user/forum_forum.php
+++ b/html/user/forum_forum.php
@@ -87,7 +87,11 @@ echo '
';
-show_button("forum_post.php?id=$id", "New thread", "Add a new thread to this forum");
+if (user_can_create_thread($user, $forum)) {
+ show_button(
+ "forum_post.php?id=$id", "New thread", "Add a new thread to this forum"
+ );
+}
echo "
diff --git a/html/user/forum_post.php b/html/user/forum_post.php
index df6ab46e1b..1ba62710c6 100644
--- a/html/user/forum_post.php
+++ b/html/user/forum_post.php
@@ -33,7 +33,12 @@ check_banished($logged_in_user);
$forumid = get_int("id");
$forum = BoincForum::lookup_id($forumid);
-check_create_thread_access($logged_in_user, $forum);
+if (!user_can_create_thread($logged_in_user, $forum)) {
+ error_page(
+ "Only project admins may create a thread here. However, you may post a reply to existing threads."
+ );
+}
+check_post_access($user, $forum);
$title = post_str("title", true);
if (!$title) $title = get_str("title", true);
diff --git a/html/user/forum_rss.php b/html/user/forum_rss.php
index d4dcc18dd9..d8cdaf97e1 100644
--- a/html/user/forum_rss.php
+++ b/html/user/forum_rss.php
@@ -28,7 +28,8 @@
// else show whole post and convert to HTML
require_once("../project/project.inc");
-require_once("../inc/db.inc");
+require_once("../inc/boinc_db.inc");
+require_once("../inc/forum_rss.inc");
$forumid = get_int('forumid');
$forum = BoincForum::lookup_id($forumid);
@@ -44,7 +45,7 @@ if (get_int('setup', true)) {
Include only posts by user ID (default: all users).
- Include only the most recent posts (default: 20).
+ Include only posts from the last days (default: 30).
Truncate posts
@@ -57,110 +58,14 @@ if (get_int('setup', true)) {
}
$userid = get_int('userid', true);
-$nitems = get_int('nitems', true);
+$ndays = get_int('ndays', true);
$truncate = get_str('truncate', true);
$threads_only = get_str('threads_only', true);
-if(!$nitems || $nitems < "1" || $nitems > "20") {
- $nitems = "20";
+if(!$ndays || $ndays < "1") {
+ $ndays = "30";
}
-$clause = "forum=$forumid ";
-
-if ($userid) {
- $user = BoincUser::lookup_id($userid);
- if (!$user) error_page("no such user");
- $clause .= " and owner=$userid";
-}
-
-$db = BoincDb::get();
-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($q);
-
-// Get unix time that last modification was made to the news source
-//
-
-// Now construct header
-//
-header ("Expires: " . gmdate('D, d M Y H:i:s', time()+86400) . " GMT");
-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";
-if ($user) {
- $description .= " (posts by $user->name)";
-}
-$channel_image = URL_BASE . "rss_image.gif";
-$language = "en-us";
-echo "
-
-
- ".$description."
- ".URL_BASE."
- ".$description."
- ".COPYRIGHT_HOLDER."
- ".$create_date."
- ".$language."
-
- ".$channel_image."
- ".PROJECT."
- ".URL_BASE."
-
-";
-
-// write news items
-//
-foreach ($threads as $thread) {
- $unique_url=URL_BASE."forum_thread.php?id=".$thread->id;
-
- $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 "
- ".strip_tags($thread->title)."
- $unique_url
- $unique_url
- $t
- $post_date
-
-";
-}
-
-// Close XML content
-//
-echo "
-
-
-";
+forum_rss($forumid, $userid, $truncate, $threads_only, $ndays);
?>
diff --git a/html/user/old_news.php b/html/user/old_news.php
index aedbe4c33a..c73510b759 100644
--- a/html/user/old_news.php
+++ b/html/user/old_news.php
@@ -18,11 +18,10 @@
require_once("../inc/util.inc");
require_once("../inc/news.inc");
-require_once("../project/project_news.inc");
page_head("News archive");
-show_old_news($project_news, 5);
+show_news(0, 0);
page_tail();
diff --git a/html/user/rss_main.php b/html/user/rss_main.php
new file mode 100644
index 0000000000..c8fa3beb55
--- /dev/null
+++ b/html/user/rss_main.php
@@ -0,0 +1,33 @@
+.
+
+require_once("../project/project.inc");
+require_once("../inc/forum_rss.inc");
+
+if (defined("NEWS_FORUM_NAME")) {
+ $forum_name = NEWS_FORUM_NAME;
+} else {
+ $forum_name = "News";
+}
+$forum = BoincForum::lookup("parent_type=0 and title = '$forum_name'");
+if (!$forum) {
+ exit;
+}
+
+forum_rss($forum->id, 0, 0, 1, 9999);
+?>
diff --git a/html/user/sample_index.php b/html/user/sample_index.php
index a0d793c705..95ce35c5d3 100644
--- a/html/user/sample_index.php
+++ b/html/user/sample_index.php
@@ -25,8 +25,6 @@ require_once("../inc/sanitize_html.inc");
require_once("../inc/translation.inc");
require_once("../inc/text_transform.inc");
require_once("../project/project.inc");
-require_once("../project/project_news.inc");
-
function show_nav() {
$config = get_config();
@@ -145,14 +143,9 @@ echo "