From e1bdfc0ee80a8ca0bea53e2553f2188089220a3a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 16 Dec 2009 22:35:08 +0000 Subject: [PATCH] - 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 --- checkin_notes | 43 ++++++++++ html/inc/bbcode_convert.inc | 93 ++++++++++++++++++++ html/inc/forum.inc | 7 +- html/inc/forum_db.inc | 4 + html/inc/forum_rss.inc | 119 ++++++++++++++++++++++++++ html/inc/news.inc | 69 +++++++++++---- html/ops/bbcode_convert.php | 74 +--------------- html/ops/bbcode_convert_response1.php | 75 +--------------- html/ops/bbcode_convert_response2.php | 75 +--------------- html/ops/bbcode_convert_signature.php | 75 +--------------- html/ops/create_forums.php | 11 +-- html/ops/news_convert.php | 112 ++++++++++++++++++++++++ html/project.sample/project_news.inc | 23 ----- html/user/all_news.php | 3 +- html/user/forum_forum.php | 6 +- html/user/forum_post.php | 7 +- html/user/forum_rss.php | 109 ++--------------------- html/user/old_news.php | 3 +- html/user/rss_main.php | 33 +++++++ html/user/sample_index.php | 11 +-- html/user/sample_motd.php | 31 +++++++ html/user/sample_rss_main.php | 118 ------------------------- py/Boinc/setup_project.py | 4 +- tools/upgrade | 7 ++ 24 files changed, 535 insertions(+), 577 deletions(-) create mode 100644 html/inc/bbcode_convert.inc create mode 100644 html/inc/forum_rss.inc create mode 100755 html/ops/news_convert.php delete mode 100644 html/project.sample/project_news.inc create mode 100644 html/user/rss_main.php create mode 100644 html/user/sample_motd.php delete mode 100644 html/user/sample_rss_main.php diff --git a/checkin_notes b/checkin_notes index 597da684ec..82fd73ba3c 100644 --- a/checkin_notes +++ b/checkin_notes @@ -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 diff --git a/html/inc/bbcode_convert.inc b/html/inc/bbcode_convert.inc new file mode 100644 index 0000000000..5632f04f36 --- /dev/null +++ b/html/inc/bbcode_convert.inc @@ -0,0 +1,93 @@ +. + +require_once('../inc/sanitize_html.inc'); + +function image_as_bb($text){ + // This function depends on sanitized HTML + + $pattern = '@^"]+)\"([^>]*)>@si'; + $replacement = '[img]$2[/img]'; + $text = preg_replace($pattern, $replacement, $text); + + $pattern = "@]*)>@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 = '@]+)\">@si'; // Gives us the URL in $1... + $replacement = '[url=$1]'; // Turns that URL into a hyperlink + $text = preg_replace($pattern, $replacement, $text); + $pattern = "@@si"; // Gives us the URL in $1... + $replacement = '[url=$1]'; // Turns that URL into a hyperlink + $text = preg_replace($pattern, $replacement, $text); + + $pattern = "@@si"; + $replacement = '[/url]'; + $text = preg_replace($pattern, $replacement, $text); + return $text; +} + +function formatting_as_bb($text){ + /* This function depends on sanitized HTML */ + $in[]="";$out[]="[b]"; + $in[]="";$out[]="[/b]"; + + $in[]="";$out[]="[i]"; + $in[]="";$out[]="[/i]"; + + $in[]="";$out[]="[u]"; + $in[]="";$out[]="[/u]"; + + $in[]="";$out[]="[b]"; + $in[]="";$out[]="[/b]"; + + $in[]="
    ";$out[]="[list]"; + $in[]="
";$out[]="[/list]"; + + $in[]="
    ";$out[]="[list=1]"; + $in[]="
";$out[]="[/list]"; + + $in[]="
";$out[]="[pre]";
+    $in[]="
";$out[]="[/pre]"; + + $in[]="
";$out[]="\n"; + $in[]="
";$out[]="\n"; + $in[]="
";$out[]="\n"; + $in[]=">";$out[]=">"; + $in[]="<";$out[]="<"; + $in[]="&";$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; +} + +?> diff --git a/html/inc/forum.inc b/html/inc/forum.inc index fce86157b7..0f92aa3896 100644 --- a/html/inc/forum.inc +++ b/html/inc/forum.inc @@ -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.
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) { diff --git a/html/inc/forum_db.inc b/html/inc/forum_db.inc index e042b65b36..2cc1c69bdf 100644 --- a/html/inc/forum_db.inc +++ b/html/inc/forum_db.inc @@ -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); diff --git a/html/inc/forum_rss.inc b/html/inc/forum_rss.inc new file mode 100644 index 0000000000..12b40c788e --- /dev/null +++ b/html/inc/forum_rss.inc @@ -0,0 +1,119 @@ +. + +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 " + + + ".$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'; + $t = bb2html($post->content, true); + if ($truncate) { + if (strlen($post->content) > 256) { + $t = substr($post->content, 0, 256).". . ."; + } + } + $t = htmlspecialchars($t); + echo " + ".strip_tags($thread->title)." + $unique_url + $unique_url + $t + $post_date + + "; + } + + echo " + + + "; +} + +?> diff --git a/html/inc/news.inc b/html/inc/news.inc index 7cdf013e7d..44995a2618 100644 --- a/html/inc/news.inc +++ b/html/inc/news.inc @@ -16,33 +16,66 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . -function news_item($date, $text, $title="") { +require_once("../project/project.inc"); + +function news_item($date, $title, $text) { + if ($title) { + echo "$title\n"; + } + $d = time_str($date); + $text = bb2html($text); echo " - $title -
$date +
$d
$text -
+

"; } -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\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 "...more"; + } + echo " +

+ News is available as an + RSS feed \"RSS\".

+ "; } $cvs_version_tracker[]="\$Id$"; //Generated automatically - do not edit diff --git a/html/ops/bbcode_convert.php b/html/ops/bbcode_convert.php index 1d80517e2c..341aff5c99 100644 --- a/html/ops/bbcode_convert.php +++ b/html/ops/bbcode_convert.php @@ -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 = '@^"]+)\"([^>]*)>@si'; - $replacement = '[img]$2[/img]'; - $text = preg_replace($pattern, $replacement, $text); - - $pattern = "@]*)>@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 = '@]+)\">@si'; // Gives us the URL in $1... - $replacement = '[url=$1]'; // Turns that URL into a hyperlink - $text = preg_replace($pattern, $replacement, $text); - $pattern = "@@si"; // Gives us the URL in $1... - $replacement = '[url=$1]'; // Turns that URL into a hyperlink - $text = preg_replace($pattern, $replacement, $text); - - $pattern = "@@si"; - $replacement = '[/url]'; - $text = preg_replace($pattern, $replacement, $text); - return $text; -} - -function formatting_as_bb($text){ - /* This function depends on sanitized HTML */ - $in[]="";$out[]="[b]"; - $in[]="";$out[]="[/b]"; - - $in[]="";$out[]="[i]"; - $in[]="";$out[]="[/i]"; - - $in[]="";$out[]="[u]"; - $in[]="";$out[]="[/u]"; - - $in[]="";$out[]="[b]"; - $in[]="";$out[]="[/b]"; - - $in[]="
    ";$out[]="[list]"; - $in[]="
";$out[]="[/list]"; - - $in[]="
    ";$out[]="[list=1]"; - $in[]="
";$out[]="[/list]"; - - $in[]="
";$out[]="[pre]";
-    $in[]="
";$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_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"; diff --git a/html/ops/bbcode_convert_response1.php b/html/ops/bbcode_convert_response1.php index e77bde1de2..f05c2ce704 100644 --- a/html/ops/bbcode_convert_response1.php +++ b/html/ops/bbcode_convert_response1.php @@ -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 = '@^"]+)\"([^>]*)>@si'; - $replacement = '[img]$2[/img]'; - $text = preg_replace($pattern, $replacement, $text); - - $pattern = "@]*)>@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 = '@]+)\">@si'; // Gives us the URL in $1... - $replacement = '[url=$1]'; // Turns that URL into a hyperlink - $text = preg_replace($pattern, $replacement, $text); - $pattern = "@@si"; // Gives us the URL in $1... - $replacement = '[url=$1]'; // Turns that URL into a hyperlink - $text = preg_replace($pattern, $replacement, $text); - - $pattern = "@@si"; - $replacement = '[/url]'; - $text = preg_replace($pattern, $replacement, $text); - return $text; -} - -function formatting_as_bb($text){ - /* This function depends on sanitized HTML */ - $in[]="";$out[]="[b]"; - $in[]="";$out[]="[/b]"; - - $in[]="";$out[]="[i]"; - $in[]="";$out[]="[/i]"; - - $in[]="";$out[]="[u]"; - $in[]="";$out[]="[/u]"; - - $in[]="";$out[]="[b]"; - $in[]="";$out[]="[/b]"; - - $in[]="
    ";$out[]="[list]"; - $in[]="
";$out[]="[/list]"; - - $in[]="
    ";$out[]="[list=1]"; - $in[]="
";$out[]="[/list]"; - - $in[]="
";$out[]="[pre]";
-    $in[]="
";$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_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"; diff --git a/html/ops/bbcode_convert_response2.php b/html/ops/bbcode_convert_response2.php index 504d7a6eac..1e8c7ecb89 100644 --- a/html/ops/bbcode_convert_response2.php +++ b/html/ops/bbcode_convert_response2.php @@ -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 = '@^"]+)\"([^>]*)>@si'; - $replacement = '[img]$2[/img]'; - $text = preg_replace($pattern, $replacement, $text); - - $pattern = "@]*)>@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 = '@]+)\">@si'; // Gives us the URL in $1... - $replacement = '[url=$1]'; // Turns that URL into a hyperlink - $text = preg_replace($pattern, $replacement, $text); - $pattern = "@@si"; // Gives us the URL in $1... - $replacement = '[url=$1]'; // Turns that URL into a hyperlink - $text = preg_replace($pattern, $replacement, $text); - - $pattern = "@@si"; - $replacement = '[/url]'; - $text = preg_replace($pattern, $replacement, $text); - return $text; -} - -function formatting_as_bb($text){ - /* This function depends on sanitized HTML */ - $in[]="";$out[]="[b]"; - $in[]="";$out[]="[/b]"; - - $in[]="";$out[]="[i]"; - $in[]="";$out[]="[/i]"; - - $in[]="";$out[]="[u]"; - $in[]="";$out[]="[/u]"; - - $in[]="";$out[]="[b]"; - $in[]="";$out[]="[/b]"; - - $in[]="
    ";$out[]="[list]"; - $in[]="
";$out[]="[/list]"; - - $in[]="
    ";$out[]="[list=1]"; - $in[]="
";$out[]="[/list]"; - - $in[]="
";$out[]="[pre]";
-    $in[]="
";$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_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"; diff --git a/html/ops/bbcode_convert_signature.php b/html/ops/bbcode_convert_signature.php index 88b401846a..36cf31e982 100644 --- a/html/ops/bbcode_convert_signature.php +++ b/html/ops/bbcode_convert_signature.php @@ -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 = '@^"]+)\"([^>]*)>@si'; - $replacement = '[img]$2[/img]'; - $text = preg_replace($pattern, $replacement, $text); - - $pattern = "@]*)>@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 = '@]+)\">@si'; // Gives us the URL in $1... - $replacement = '[url=$1]'; // Turns that URL into a hyperlink - $text = preg_replace($pattern, $replacement, $text); - $pattern = "@@si"; // Gives us the URL in $1... - $replacement = '[url=$1]'; // Turns that URL into a hyperlink - $text = preg_replace($pattern, $replacement, $text); - - $pattern = "@@si"; - $replacement = '[/url]'; - $text = preg_replace($pattern, $replacement, $text); - return $text; -} - -function formatting_as_bb($text){ - /* This function depends on sanitized HTML */ - $in[]="";$out[]="[b]"; - $in[]="";$out[]="[/b]"; - - $in[]="";$out[]="[i]"; - $in[]="";$out[]="[/i]"; - - $in[]="";$out[]="[u]"; - $in[]="";$out[]="[/u]"; - - $in[]="";$out[]="[b]"; - $in[]="";$out[]="[/b]"; - - $in[]="
    ";$out[]="[list]"; - $in[]="
";$out[]="[/list]"; - - $in[]="
    ";$out[]="[list=1]"; - $in[]="
";$out[]="[/list]"; - - $in[]="
";$out[]="[pre]";
-    $in[]="
";$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 "

News

"; -show_news($project_news, 5); -if (count($project_news) > 5) { - echo "...more"; -} +include("motd.php"); +show_news(0, 5); echo " -

- News is available as an - RSS feed \"RSS\".

"; diff --git a/html/user/sample_motd.php b/html/user/sample_motd.php new file mode 100644 index 0000000000..98d095baa4 --- /dev/null +++ b/html/user/sample_motd.php @@ -0,0 +1,31 @@ +. + +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" + ); +} + +?> diff --git a/html/user/sample_rss_main.php b/html/user/sample_rss_main.php deleted file mode 100644 index f31503a09b..0000000000 --- a/html/user/sample_rss_main.php +++ /dev/null @@ -1,118 +0,0 @@ -. - - -// 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 " - - - ".PROJECT." - ".URL_BASE." - ".$description." - ".COPYRIGHT_HOLDER." - ".$create_date." - ".$language." - - ".$channel_image." - ".PROJECT." - ".URL_BASE." - -"; - -// 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 " - ".$title." - $unique_url - $unique_url - - $news_date - "; - if (isset($item[3])) { - $category = $item[3]; - echo " - $category - "; - } - echo " - - "; -} - -// Close XML content -// -echo " - - -"; - -?> diff --git a/py/Boinc/setup_project.py b/py/Boinc/setup_project.py index 68c6d156e2..3776e89dd3 100644 --- a/py/Boinc/setup_project.py +++ b/py/Boinc/setup_project.py @@ -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')) diff --git a/tools/upgrade b/tools/upgrade index c5034ba1e2..9979122c87 100755 --- a/tools/upgrade +++ b/tools/upgrade @@ -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."