- web: change the way project news is stored.

Old: in a flat file (html/project/project_news.inc)
    New: in a forum (called "News" by default)
    The script html/ops/news_convert.php copies news from
    old to new format.
    You'll also need to edit your index.php and use
    "show_news(0, 5)" to show news.
- web: added a "message of the day" mechanism.
    Edit html/user/motd.php to show a message.
    This will be shown as the first news item,
    but it's not archived (i.e., it's not a forum post)


svn path=/trunk/boinc/; revision=19949
This commit is contained in:
David Anderson 2009-12-16 22:35:08 +00:00
parent f57cf01b79
commit e1bdfc0ee8
24 changed files with 535 additions and 577 deletions

View File

@ -10146,3 +10146,46 @@ Rom 16 Dec 2009
sleeper.vcproj
ss_app.vcproj
uc2_graphics.vcproj
David 16 Dec 2009
- web: change the way project news is stored.
Old: in a flat file (html/project/project_news.inc)
New: in a forum (called "News" by default)
The script html/ops/news_convert.php copies news from
old to new format.
You'll also need to edit your index.php and use
"show_news(0, 5)" to show news.
- web: added a "message of the day" mechanism.
Edit html/user/motd.php to show a message.
This will be shown as the first news item,
but it's not archived (i.e., it's not a forum post)
html/
inc/
bbcode_convert.inc (new)
forum.inc
forum_db.inc
forum_rss.inc (new);
news.inc
ops/
bbcode_convert.php
bbcode_convert_response1.php
bbcode_convert_response2.php
bbcode_convert_signature.php
news_convert.php (new)
create_forums.php
project_sample/
project_news.inc (removed)
user/
all_news.php
forum_forum.php
forum_post.php
old_news.php
rss_main.php (new)
sample_index.php
sample_motd.php (new)
sample_rss_main.php (removed)
py/Boinc/
setup_project.py
tools/
upgrade

View File

@ -0,0 +1,93 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once('../inc/sanitize_html.inc');
function image_as_bb($text){
// This function depends on sanitized HTML
$pattern = '@<img(.*) src=\"([^>^"]+)\"([^>]*)>@si';
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<img(.*) src='([^>^']+)'([^>]*)>@si";
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function link_as_bb($text){
/* This function depends on sanitized HTML */
// Build some regex (should be a *lot* faster)
$pattern = '@<a href=\"([^>]+)\">@si'; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<a href='([^>]+)'>@si"; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@</a>@si";
$replacement = '[/url]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function formatting_as_bb($text){
/* This function depends on sanitized HTML */
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<i>";$out[]="[i]";
$in[]="</i>";$out[]="[/i]";
$in[]="<u>";$out[]="[u]";
$in[]="</u>";$out[]="[/u]";
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<ul>";$out[]="[list]";
$in[]="</ul>";$out[]="[/list]";
$in[]="<ol>";$out[]="[list=1]";
$in[]="</ol>";$out[]="[/list]";
$in[]="<pre>";$out[]="[pre]";
$in[]="</pre>";$out[]="[/pre]";
$in[]="</br>";$out[]="\n";
$in[]="<br/>";$out[]="\n";
$in[]="<br>";$out[]="\n";
$in[]="&gt;";$out[]=">";
$in[]="&lt;";$out[]="<";
$in[]="&amp;";$out[]="&";
return str_replace($in, $out, $text);
}
function html_to_bbcode($text) {
$text = sanitize_html($text);
$text = image_as_bb($text);
$text = link_as_bb($text);
$text = formatting_as_bb($text);
return $text;
}
?>

View File

@ -1016,17 +1016,18 @@ function show_post_moderation_links(
}
}
function check_create_thread_access($user, $forum) {
function user_can_create_thread($user, $forum) {
if (!$user) return false;
if ($forum->is_dev_blog){
if (
(!$user->prefs->privilege(S_SCIENTIST)) &&
(!$user->prefs->privilege(S_DEV)) &&
(!$user->prefs->privilege(S_ADMIN))
) {
error_page("This forum is marked as a development blog, only people directly working with the project may start a new thread here. <br/>However, you may post a reply to an existing thread.");
return false;
}
}
check_post_access($user, $forum);
return true;
}
function check_post_access($user, $forum) {

View File

@ -23,6 +23,10 @@ class BoincCategory {
$db = BoincDb::get();
return $db->lookup_id($id, 'category', 'BoincCategory');
}
static function lookup($clause) {
$db = BoincDb::get();
return $db->lookup('category', 'BoincCategory', $clause);
}
static function enum($clause=null) {
$db = BoincDb::get();
return $db->enum('category', 'BoincCategory', $clause);

119
html/inc/forum_rss.inc Normal file
View File

@ -0,0 +1,119 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/forum_db.inc");
require_once("../inc/boinc_db.inc");
require_once("../inc/util.inc");
require_once("../inc/text_transform.inc");
require_once("../project/project.inc");
function forum_rss($forumid, $userid, $truncate, $threads_only, $ndays) {
$clause = "forum=$forumid ";
if ($userid) {
$user = BoincUser::lookup_id($userid);
if (!$user) error_page("no such user");
$clause .= " and owner=$userid";
}
$tlimit = time() - $ndays*86400;
if ($threads_only) {
$q = "$clause and status=0 and hidden=0 and sticky=0 and create_time > $tlimit order by create_time desc";
} else {
$q = "$clause and status=0 and hidden=0 and sticky=0 and timestamp > $tlimit order by timestamp desc";
}
$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 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>
<rss version=\"2.0\">
<channel>
<title>".$description."</title>
<link>".URL_BASE."</link>
<description>$description</description>
<copyright>".COPYRIGHT_HOLDER."</copyright>
<lastBuildDate>".$create_date."</lastBuildDate>
<language>".$language."</language>
<image>
<url>".$channel_image."</url>
<title>".PROJECT."</title>
<link>".URL_BASE."</link>
</image>
";
// 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';
$t = bb2html($post->content, true);
if ($truncate) {
if (strlen($post->content) > 256) {
$t = substr($post->content, 0, 256).". . .";
}
}
$t = htmlspecialchars($t);
echo "<item>
<title>".strip_tags($thread->title)."</title>
<link>$unique_url</link>
<guid isPermaLink=\"true\">$unique_url</guid>
<description>$t</description>
<pubDate>$post_date</pubDate>
</item>
";
}
echo "
</channel>
</rss>
";
}
?>

View File

@ -16,33 +16,66 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
function news_item($date, $text, $title="") {
require_once("../project/project.inc");
function news_item($date, $title, $text) {
if ($title) {
echo "<span class=news_title>$title</span>\n";
}
$d = time_str($date);
$text = bb2html($text);
echo "
<span class=news_title>$title</span>
<br><span class=news_date>$date</span>
<br><span class=news_date>$d</span>
<br><span class=news_content>$text</span>
<br>
<br><br>
";
}
function show_news($items, $n) {
if ($n > count($items)) {
$n = count($items);
function show_news($start, $count) {
if (defined("NEWS_FORUM_NAME")) {
$forum_name = NEWS_FORUM_NAME;
} else {
$forum_name = "News";
}
for ($i=0; $i<$n; $i++) {
$title = null;
if (isset($items[$i][2])) $title = $items[$i][2];
news_item($items[$i][0], $items[$i][1], $title);
$forum = BoincForum::lookup("parent_type=0 and title = '$forum_name'");
if (!$forum) {
echo "
No news forum. Run html/ops/create_forums.php.
";
return;
}
}
function show_old_news($items, $n) {
$tot = count($items);
for ($i=$n; $i<count($items); $i++) {
$j = $tot-$i;
echo "<a name=$j></a>\n";
news_item($items[$i][0], $items[$i][1]);
$lim = "";
if ($start) {
if ($count) {
$lim = "limit $start, $count";
} else {
$lim = "limit $start, 99999999";
}
} else if ($count) {
$lim = "limit $count";
}
$threads = BoincThread::enum("forum = $forum->id order by id desc $lim");
foreach ($threads as $thread) {
$posts = BoincPost::enum("thread=$thread->id order by id limit 1");
$post = $posts[0];
if (strstr($post->content, $thread->title)) {
$title = null;
} else {
$title = $thread->title;
}
news_item($thread->create_time, $title, $post->content);
}
if ($count) {
echo "<a href=\"old_news.php\">...more</a>";
}
echo "
<p class=\"smalltext\">
News is available as an
<a href=\"rss_main.php\">RSS feed</a> <img src=\"img/rss_icon.gif\" alt=\"RSS\">.</p>
";
}
$cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit

View File

@ -20,84 +20,14 @@ $cli_only = true;
require_once("../inc/db.inc");
require_once("../inc/util_ops.inc");
require_once('../inc/sanitize_html.inc');
require_once('../inc/bbcode_convert.inc');
db_init();
set_time_limit(0);
function image_as_bb($text){
// This function depends on sanitized HTML
$pattern = '@<img(.*) src=\"([^>^"]+)\"([^>]*)>@si';
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<img(.*) src='([^>^']+)'([^>]*)>@si";
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function link_as_bb($text){
/* This function depends on sanitized HTML */
// Build some regex (should be a *lot* faster)
$pattern = '@<a href=\"([^>]+)\">@si'; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<a href='([^>]+)'>@si"; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@</a>@si";
$replacement = '[/url]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function formatting_as_bb($text){
/* This function depends on sanitized HTML */
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<i>";$out[]="[i]";
$in[]="</i>";$out[]="[/i]";
$in[]="<u>";$out[]="[u]";
$in[]="</u>";$out[]="[/u]";
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<ul>";$out[]="[list]";
$in[]="</ul>";$out[]="[/list]";
$in[]="<ol>";$out[]="[list=1]";
$in[]="</ol>";$out[]="[/list]";
$in[]="<pre>";$out[]="[pre]";
$in[]="</pre>";$out[]="[/pre]";
$in[]="</br>";$out[]="\n";
$in[]="<br/>";$out[]="\n";
$in[]="<br>";$out[]="\n";
$in[]="&gt;";$out[]=">";
$in[]="&lt;";$out[]="<";
$in[]="&amp;";$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_post($post) {
$text = fix_text($post->content);
$text = html_to_bbcode($post->content);
if ($text != $post->content) {
$query = "update post set content = '".mysql_escape_string($text)."' where id=".$post->id;
//echo "$post->content\n\n";

View File

@ -18,85 +18,14 @@
$cli_only = true;
require_once("../inc/util_ops.inc");
require_once('../inc/sanitize_html.inc');
require_once('../inc/bbcode_convert.inc');
db_init();
set_time_limit(0);
function image_as_bb($text){
// This function depends on sanitized HTML
$pattern = '@<img(.*) src=\"([^>^"]+)\"([^>]*)>@si';
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<img(.*) src='([^>^']+)'([^>]*)>@si";
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function link_as_bb($text){
/* This function depends on sanitized HTML */
// Build some regex (should be a *lot* faster)
$pattern = '@<a href=\"([^>]+)\">@si'; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<a href='([^>]+)'>@si"; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@</a>@si";
$replacement = '[/url]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function formatting_as_bb($text){
/* This function depends on sanitized HTML */
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<i>";$out[]="[i]";
$in[]="</i>";$out[]="[/i]";
$in[]="<u>";$out[]="[u]";
$in[]="</u>";$out[]="[/u]";
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<ul>";$out[]="[list]";
$in[]="</ul>";$out[]="[/list]";
$in[]="<ol>";$out[]="[list=1]";
$in[]="</ol>";$out[]="[/list]";
$in[]="<pre>";$out[]="[pre]";
$in[]="</pre>";$out[]="[/pre]";
$in[]="</br>";$out[]="\n";
$in[]="<br/>";$out[]="\n";
$in[]="<br>";$out[]="\n";
$in[]="&gt;";$out[]=">";
$in[]="&lt;";$out[]="<";
$in[]="&amp;";$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_profile($profile) {
$text = fix_text($profile->response1);
$text = html_to_bbcode($profile->response1);
if ($text != $profile->response1) {
$query = "update profile set response1 = '".mysql_escape_string($text)."' where userid=".$profile->userid;
//echo "$profile->response1\n\n";

View File

@ -18,85 +18,14 @@
$cli_only = true;
require_once("../inc/util_ops.inc");
require_once('../inc/sanitize_html.inc');
require_once('../inc/bbcode_convert.inc');
db_init();
set_time_limit(0);
function image_as_bb($text){
// This function depends on sanitized HTML
$pattern = '@<img(.*) src=\"([^>^"]+)\"([^>]*)>@si';
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<img(.*) src='([^>^']+)'([^>]*)>@si";
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function link_as_bb($text){
/* This function depends on sanitized HTML */
// Build some regex (should be a *lot* faster)
$pattern = '@<a href=\"([^>]+)\">@si'; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<a href='([^>]+)'>@si"; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@</a>@si";
$replacement = '[/url]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function formatting_as_bb($text){
/* This function depends on sanitized HTML */
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<i>";$out[]="[i]";
$in[]="</i>";$out[]="[/i]";
$in[]="<u>";$out[]="[u]";
$in[]="</u>";$out[]="[/u]";
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<ul>";$out[]="[list]";
$in[]="</ul>";$out[]="[/list]";
$in[]="<ol>";$out[]="[list=1]";
$in[]="</ol>";$out[]="[/list]";
$in[]="<pre>";$out[]="[pre]";
$in[]="</pre>";$out[]="[/pre]";
$in[]="</br>";$out[]="\n";
$in[]="<br/>";$out[]="\n";
$in[]="<br>";$out[]="\n";
$in[]="&gt;";$out[]=">";
$in[]="&lt;";$out[]="<";
$in[]="&amp;";$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_profile($profile) {
$text = fix_text($profile->response2);
$text = html_to_bbcode($profile->response2);
if ($text != $profile->response2) {
$query = "update profile set response2 = '".mysql_escape_string($text)."' where userid=".$profile->userid;
//echo "$profile->response2\n\n";

View File

@ -18,85 +18,14 @@
$cli_only = true;
require_once("../inc/util_ops.inc");
require_once('../inc/sanitize_html.inc');
require_once('../inc/bbcode_convert.inc');
db_init();
set_time_limit(0);
function image_as_bb($text){
// This function depends on sanitized HTML
$pattern = '@<img(.*) src=\"([^>^"]+)\"([^>]*)>@si';
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<img(.*) src='([^>^']+)'([^>]*)>@si";
$replacement = '[img]$2[/img]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function link_as_bb($text){
/* This function depends on sanitized HTML */
// Build some regex (should be a *lot* faster)
$pattern = '@<a href=\"([^>]+)\">@si'; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@<a href='([^>]+)'>@si"; // Gives us the URL in $1...
$replacement = '[url=$1]'; // Turns that URL into a hyperlink
$text = preg_replace($pattern, $replacement, $text);
$pattern = "@</a>@si";
$replacement = '[/url]';
$text = preg_replace($pattern, $replacement, $text);
return $text;
}
function formatting_as_bb($text){
/* This function depends on sanitized HTML */
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<i>";$out[]="[i]";
$in[]="</i>";$out[]="[/i]";
$in[]="<u>";$out[]="[u]";
$in[]="</u>";$out[]="[/u]";
$in[]="<b>";$out[]="[b]";
$in[]="</b>";$out[]="[/b]";
$in[]="<ul>";$out[]="[list]";
$in[]="</ul>";$out[]="[/list]";
$in[]="<ol>";$out[]="[list=1]";
$in[]="</ol>";$out[]="[/list]";
$in[]="<pre>";$out[]="[pre]";
$in[]="</pre>";$out[]="[/pre]";
$in[]="</br>";$out[]="\n";
$in[]="<br/>";$out[]="\n";
$in[]="<br>";$out[]="\n";
$in[]="&gt;";$out[]=">";
$in[]="&lt;";$out[]="<";
$in[]="&amp;";$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";

View File

@ -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");

112
html/ops/news_convert.php Executable file
View File

@ -0,0 +1,112 @@
#!/usr/bin/env php
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// 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
";
?>

View File

@ -1,23 +0,0 @@
<?php
// each news item is an array:
// 0: date
// 1: content
// 2: title (optional)
// 3: category (optional)
// suggested values:
// "server status"
// "news"
// "emergency"
$project_news = array(
array("March 1, 2004, 13:50 GMT",
"Sample news item",
"Sample news item title"
),
array("March 2, 2004, 11:50 GMT",
"Another item",
"Another item title"
)
);
?>

View File

@ -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();

View File

@ -87,7 +87,11 @@ echo '
<td colspan=2>
';
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 "</td>
<td valign=top align=\"right\">

View File

@ -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. <br/>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);

View File

@ -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)) {
<p>
Include only posts by user ID <input name=userid> (default: all users).
<p>
Include only the <input name=nitems> most recent posts (default: 20).
Include only posts from the last <input name=ndays> days (default: 30).
<p>
Truncate posts <input type=checkbox name=truncate checked>
<p>
@ -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 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>
<rss version=\"2.0\">
<channel>
<title>".$description."</title>
<link>".URL_BASE."</link>
<description>".$description."</description>
<copyright>".COPYRIGHT_HOLDER."</copyright>
<lastBuildDate>".$create_date."</lastBuildDate>
<language>".$language."</language>
<image>
<url>".$channel_image."</url>
<title>".PROJECT."</title>
<link>".URL_BASE."</link>
</image>
";
// 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 "<item>
<title>".strip_tags($thread->title)."</title>
<link>$unique_url</link>
<guid isPermaLink=\"true\">$unique_url</guid>
<description>$t</description>
<pubDate>$post_date</pubDate>
</item>
";
}
// Close XML content
//
echo "
</channel>
</rss>
";
forum_rss($forumid, $userid, $truncate, $threads_only, $ndays);
?>

View File

@ -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();

33
html/user/rss_main.php Normal file
View File

@ -0,0 +1,33 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
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);
?>

View File

@ -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 "
<h2>News</h2>
<p>
";
show_news($project_news, 5);
if (count($project_news) > 5) {
echo "<a href=\"old_news.php\">...more</a>";
}
include("motd.php");
show_news(0, 5);
echo "
<p class=\"smalltext\">
News is available as an
<a href=\"rss_main.php\">RSS feed</a> <img src=\"img/rss_icon.gif\" alt=\"RSS\">.</p>
</td>
</tr></table>
";

31
html/user/sample_motd.php Normal file
View File

@ -0,0 +1,31 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2009 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
require_once("../inc/news.inc");
// change 0 to 1 to enable message
if (0) {
news_item(
filemtime("motd.php"),
"Title goes here",
"message body goes here"
);
}
?>

View File

@ -1,118 +0,0 @@
<?php
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// rss_main.php:
// RSS 2.0 feed for BOINC default server installation.
// Channel Main show the current news on project mainpage
// - for more informations about RSS see RSS 2.0 Specification:
// http://blogs.law.harvard.edu/tech/rss
// Check your page with http://feedvalidator.org/
// Get unix time that last modification was made to the news source
//
$last_mod_time=filemtime("../project/project_news.inc");
$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()) . " GMT");
header ("Last-Modified: " . $create_date);
header ("Content-Type: application/xml");
// Get or set display options
// - from 1 to 9 News could be set by option news, default is up to 9
//
$news = "9";
if (isset($_GET["news"])) $news=$_GET["news"];
if($news < "1" or $news > "9") {
$news = "9";
}
// include project constants and news file
//
require_once("../inc/text_transform.inc");
require_once("../project/project.inc");
require_once("../project/project_news.inc");
// Create channel header and open XML content
//
$description = "BOINC project ".PROJECT.": Main page News";
$channel_image = URL_BASE . "rss_image.gif";
$language = "en-us";
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>
<rss version=\"2.0\">
<channel>
<title>".PROJECT."</title>
<link>".URL_BASE."</link>
<description>".$description."</description>
<copyright>".COPYRIGHT_HOLDER."</copyright>
<lastBuildDate>".$create_date."</lastBuildDate>
<language>".$language."</language>
<image>
<url>".$channel_image."</url>
<title>".PROJECT."</title>
<link>".URL_BASE."</link>
</image>
";
// write news items
//
$tot = count($project_news);
$news = min($tot, $news);
for ($i=0; $i < $news; $i++) {
$j = $tot - $i;
$item = $project_news[$i];
if (count($item) < 2) continue;
$d = strtotime($item[0]);
$news_date=gmdate('D, d M Y H:i:s',$d) . ' GMT';
$unique_url=URL_BASE."all_news.php#$j";
if (isset($item[2])) {
$title = $item[2];
} else {
$title = "Project News ".$item[0];
}
$body = image_as_link($item[1]);
echo "<item>
<title>".$title."</title>
<link>$unique_url</link>
<guid isPermaLink=\"true\">$unique_url</guid>
<description><![CDATA[$body]]></description>
<pubDate>$news_date</pubDate>
";
if (isset($item[3])) {
$category = $item[3];
echo "
<category>$category</category>
";
}
echo "
</item>
";
}
// Close XML content
//
echo "
</channel>
</rss>
";
?>

View File

@ -321,6 +321,8 @@ def install_boinc_files(dest_dir, web_only):
install_glob(srcdir('html/user/*.png'), dir('html/user/img'))
install_glob(srcdir('html/user/*.gif'), dir('html/user/img'))
install_glob(srcdir('html/user/img/*.*'), dir('html/user/img'))
if not os.path.exists(dir('html/user/motd.php')):
shutil.copy(srcdir('html/user/sample_motd.php'), dir('html/user/motd.php'))
os.system("rm -f "+dir('html/languages/translations/*'))
install_glob(srcdir('html/languages/translations/*.po'), dir('html/languages/translations/'))
@ -491,8 +493,6 @@ class Project:
self.dir('html/project/project_news.inc'))
install(srcdir('html/project.sample/cache_parameters.inc'),
self.dir('html/project/cache_parameters.inc'))
install(srcdir('html/user', 'sample_rss_main.php'),
self.dir('html/user/rss_main.php'))
install(srcdir('html/ops', 'sample_server_status.php'),
self.dir('html/user/server_status.php'))
install(srcdir('tools/project.xml'), self.dir('project.xml'))

View File

@ -87,5 +87,12 @@ except:
os.system('cd '+INSTALL_DIR+'/html/ops; ./upgrade_db.php')
if os.path.exists(INSTALL_DIR+'/html/project/project_news.inc'):
print '''\
html/project/project_news.inc is deprecated.
Run html/ops/news_convert.php to convert project news to forum format.
'''
if not options.web_only:
print "Run `bin/start' to restart the project."