2004-02-02 23:34:39 +00:00
< ? php
2008-08-05 22:43:14 +00:00
// 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/>.
2004-02-02 23:34:39 +00:00
2007-11-12 20:57:15 +00:00
require_once ( " ../inc/forum_db.inc " );
require_once ( " ../inc/pm.inc " );
2007-11-15 22:51:05 +00:00
require_once ( " ../inc/team.inc " );
2011-06-14 05:42:52 +00:00
require_once ( " ../inc/news.inc " );
2007-11-12 20:57:15 +00:00
require_once ( " ../inc/text_transform.inc " );
define ( 'THREADS_PER_PAGE' , 50 );
// sorting styles
define ( 'MODIFIED_NEW' , 1 );
define ( 'MODIFIED_OLD' , 2 );
define ( 'VIEWS_MOST' , 3 );
define ( 'REPLIES_MOST' , 4 );
define ( 'CREATE_TIME_NEW' , 5 );
define ( 'CREATE_TIME_OLD' , 6 );
define ( 'POST_SCORE' , 7 );
// names for the above
2011-02-09 23:42:05 +00:00
$thread_sort_styles [ CREATE_TIME_OLD ] = tra ( " Oldest first " );
$thread_sort_styles [ CREATE_TIME_NEW ] = tra ( " Newest first " );
$thread_sort_styles [ POST_SCORE ] = tra ( " Highest rated posts first " );
$forum_sort_styles [ MODIFIED_NEW ] = tra ( " Newest post first " );
$forum_sort_styles [ VIEWS_MOST ] = tra ( " Most views first " );
$forum_sort_styles [ REPLIES_MOST ] = tra ( " Most posts first " );
$forum_sort_styles [ CREATE_TIME_NEW ] = tra ( " Newest first " );
2007-11-12 20:57:15 +00:00
// values for thread.status
define ( 'THREAD_SOLVED' , 1 );
2004-02-02 23:34:39 +00:00
2004-09-04 23:37:49 +00:00
define ( 'AVATAR_WIDTH' , 100 );
define ( 'AVATAR_HEIGHT' , 100 );
2005-01-18 13:00:38 +00:00
2004-09-04 23:37:49 +00:00
define ( 'ST_NEW_TIME' , 1209600 ); //3600*24*14 - 14 days
define ( 'ST_NEW' , 'New member' );
2007-11-12 20:57:15 +00:00
define ( 'MAXIMUM_EDIT_TIME' , 3600 );
// allow edits of forums posts up till one hour after posting.
2004-09-04 23:37:49 +00:00
2006-06-16 23:53:56 +00:00
define ( 'MAX_FORUM_LOGGING_TIME' , 2419200 ); //3600*24*28 - 28 days
2004-02-02 23:34:39 +00:00
define ( 'NO_CONTROLS' , 0 );
define ( 'FORUM_CONTROLS' , 1 );
define ( 'HELPDESK_CONTROLS' , 2 );
define ( " EXCERPT_LENGTH " , " 120 " );
2005-04-20 20:56:58 +00:00
define ( 'NEW_IMAGE' , 'img/unread_post.png' );
define ( 'NEW_IMAGE_STICKY' , 'img/unread_sticky.png' );
2006-11-10 17:09:09 +00:00
define ( 'NEW_IMAGE_LOCKED' , 'img/unread_locked.png' );
define ( 'NEW_IMAGE_STICKY_LOCKED' , 'img/unread_sticky_locked.png' );
define ( 'IMAGE_STICKY' , 'img/sticky_post.png' );
define ( 'IMAGE_LOCKED' , 'img/locked_post.png' );
2011-04-11 06:46:22 +00:00
define ( 'IMAGE_HIDDEN' , 'img/hidden.png' );
2006-11-10 17:09:09 +00:00
define ( 'IMAGE_STICKY_LOCKED' , 'img/sticky_locked_post.png' );
2010-11-03 21:48:39 +00:00
define ( 'IMAGE_POST' , 'img/post.png' );
2004-10-10 03:04:29 +00:00
define ( 'NEW_IMAGE_HEIGHT' , '15' );
2005-04-20 20:56:58 +00:00
define ( 'EMPHASIZE_IMAGE' , 'img/emphasized_post.png' );
2004-10-25 22:04:15 +00:00
define ( 'EMPHASIZE_IMAGE_HEIGHT' , '15' );
2005-04-20 20:56:58 +00:00
define ( 'FILTER_IMAGE' , 'img/filtered_post.png' );
2004-12-18 18:13:46 +00:00
define ( 'FILTER_IMAGE_HEIGHT' , '15' );
2005-04-30 09:04:00 +00:00
define ( 'RATE_POSITIVE_IMAGE' , 'img/rate_positive.png' );
define ( 'RATE_POSITIVE_IMAGE_HEIGHT' , '9' );
define ( 'RATE_NEGATIVE_IMAGE' , 'img/rate_negative.png' );
define ( 'RATE_NEGATIVE_IMAGE_HEIGHT' , '9' );
2005-10-01 11:11:53 +00:00
define ( 'REPORT_POST_IMAGE' , 'img/report_post.png' );
define ( 'REPORT_POST_IMAGE_HEIGHT' , '9' );
2004-02-02 23:34:39 +00:00
define ( 'SOLUTION' , 'This answered my question' );
define ( 'SUFFERER' , 'I also have this question' );
define ( 'OFF_TOPIC' , 'Off-topic' );
2004-10-25 22:04:15 +00:00
define ( 'DEFAULT_LOW_RATING_THRESHOLD' , - 25 );
define ( 'DEFAULT_HIGH_RATING_THRESHOLD' , 5 );
2007-11-12 20:57:15 +00:00
// A list of what kind of special users exist
define ( 'S_MODERATOR' , 0 );
define ( 'S_ADMIN' , 1 );
define ( 'S_DEV' , 2 );
define ( 'S_TESTER' , 3 );
define ( 'S_VOLUNTEER' , 4 );
define ( 'S_VOLUNTEER_TESTER' , 5 );
define ( 'S_SCIENTIST' , 6 );
2010-08-20 19:04:09 +00:00
$special_user_bitfield [ S_MODERATOR ] = " Volunteer moderator " ;
2007-11-12 20:57:15 +00:00
$special_user_bitfield [ S_ADMIN ] = " Project administrator " ;
$special_user_bitfield [ S_DEV ] = " Project developer " ;
$special_user_bitfield [ S_TESTER ] = " Project tester " ;
$special_user_bitfield [ S_VOLUNTEER ] = " Volunteer developer " ;
$special_user_bitfield [ S_VOLUNTEER_TESTER ] = " Volunteer tester " ;
$special_user_bitfield [ S_SCIENTIST ] = " Project scientist " ;
2007-11-15 00:27:02 +00:00
// show a banner with search form on left and PM info on right
//
function show_forum_header ( $user ) {
2008-08-15 16:26:55 +00:00
echo " <form action= \" forum_search_action.php \" method= \" POST \" >
" ;
2010-12-21 17:15:57 +00:00
echo " <table cellpadding= \" 5 \" width= \" 100% \" class= \" forum_header \" > " ;
2008-08-15 16:26:55 +00:00
echo " <tr>
" ;
2014-03-15 22:33:38 +00:00
2007-11-15 00:27:02 +00:00
// Search
2008-08-07 20:43:52 +00:00
echo "
< td >
2007-11-15 00:27:02 +00:00
< input type = \ " hidden \" name= \" search_max_time \" value= \" 30 \" >
< input type = \ " hidden \" name= \" search_forum \" value= \" -1 \" >
< input type = \ " hidden \" name= \" search_sort \" value= \" 5 \" >
< input type = \ " text \" name= \" search_keywords \" >
2008-03-06 18:16:30 +00:00
< input class = \ " btn \" title= \" " . tra ( " Search for words in forum messages " ) . " \" type= \" submit \" value= \" " . tra ( " Search forums " ) . " \" ><br>
< span class = \ " smalltext \" ><a href= \" forum_search.php \" > " . tra ( " Advanced search " ) . " </a></span>
2008-08-07 20:43:52 +00:00
</ td >
2007-11-15 00:27:02 +00:00
" ;
2014-03-15 22:33:38 +00:00
2007-11-15 00:27:02 +00:00
if ( $user ) {
echo " <td align= \" right \" > \n " ;
2008-03-06 18:16:30 +00:00
echo " <p> " . tra ( " Private messages " ) . " : " , pm_notification ( $user );
2007-11-12 20:57:15 +00:00
echo " </td> \n " ;
}
2008-08-15 16:26:55 +00:00
echo " </tr>
" ;
2007-11-15 00:27:02 +00:00
end_table ();
2008-08-15 16:26:55 +00:00
echo " </form>
" ;
2007-11-15 00:27:02 +00:00
}
2004-09-04 23:37:49 +00:00
2007-11-15 00:27:02 +00:00
// Output the forum/thread title.
//
2007-11-22 04:13:59 +00:00
function show_forum_title ( $category , $forum , $thread , $link_thread = false ) {
2007-11-12 20:57:15 +00:00
if ( $category ) {
$is_helpdesk = $category -> is_helpdesk ;
} else {
$is_helpdesk = false ;
}
2010-11-03 21:48:39 +00:00
2007-11-12 20:57:15 +00:00
$where = $is_helpdesk ? tra ( " Questions and Answers " ) : tra ( " Message boards " );
$top_url = $is_helpdesk ? " forum_help_desk.php " : " forum_index.php " ;
2010-11-03 21:48:39 +00:00
2007-11-12 20:57:15 +00:00
if ( ! $forum && ! $thread ) {
2011-02-10 22:45:39 +00:00
echo " <span class= \" title \" > $where </span> \n " ;
2004-02-02 23:34:39 +00:00
2007-11-12 20:57:15 +00:00
} else if ( $forum && ! $thread ) {
echo " <span class=title> " ;
echo " <a href= \" $top_url\ " > $where </ a > : " ;
echo $forum -> title ;
2007-11-20 19:23:26 +00:00
echo " </span> " ;
2007-11-12 20:57:15 +00:00
} else if ( $forum && $thread ) {
2007-11-22 04:13:59 +00:00
echo " <span class=title>
< a href = \ " $top_url\ " > $where </ a > :
< a href = \ " forum_forum.php?id= " . $forum -> id . " \" > " , $forum -> title , " </a> :
" ;
if ( $link_thread ) {
2007-11-22 17:18:46 +00:00
echo " <a href=forum_thread.php?id= $thread->id > " ;
2007-11-22 04:13:59 +00:00
}
2007-11-12 20:57:15 +00:00
echo cleanup_title ( $thread -> title );
2007-11-22 04:13:59 +00:00
if ( $link_thread ) {
echo " </a> " ;
}
2007-11-20 19:23:26 +00:00
echo " </span> " ;
2007-11-12 20:57:15 +00:00
} else {
2010-11-03 21:48:39 +00:00
echo " Invalid thread ID " ;
2007-11-12 20:57:15 +00:00
}
}
2004-02-02 23:34:39 +00:00
2007-11-26 04:12:15 +00:00
function show_team_forum_title ( $forum , $thread = null , $link_thread = false ) {
2007-11-16 21:48:28 +00:00
$team = BoincTeam :: lookup_id ( $forum -> category );
2007-11-22 17:22:38 +00:00
echo " <span class=title>
2008-03-06 18:16:30 +00:00
< a href = \ " forum_index.php \" > " . tra ( " Message boards " ) . " </a> :
2007-11-16 21:48:28 +00:00
" ;
2007-11-20 19:23:26 +00:00
if ( $thread ) {
2007-11-26 04:12:15 +00:00
echo "
2008-03-06 18:16:30 +00:00
< a href = team_forum . php ? teamid = $team -> id > " .tra( " % 1 message board " , $team->name ). " </ a >
2007-11-26 04:12:15 +00:00
" ;
if ( $link_thread ) {
echo " : <a href=forum_thread.php?id= $thread->id > $thread->title </a> " ;
} else {
echo " : $thread->title " ;
}
} else {
2008-03-06 18:16:30 +00:00
echo tra ( " %1 message board " , $team -> name );
2007-11-20 19:23:26 +00:00
}
2007-11-22 17:22:38 +00:00
echo " </span> " ;
2007-11-16 21:48:28 +00:00
}
2011-09-05 17:29:53 +00:00
function start_forum_table ( $headings , $extra = null ) {
2007-11-12 20:57:15 +00:00
$span = null ;
2011-08-29 05:37:52 +00:00
start_table ( $extra . " width= \" 100% \" " );
2007-11-12 20:57:15 +00:00
echo " <tr> " ;
2004-02-02 23:34:39 +00:00
2007-11-12 20:57:15 +00:00
for ( $i = 0 ; $i < count ( $headings ); $i ++ ) {
if ( is_array ( $headings [ $i ])){
$title = $headings [ $i ][ 0 ];
$class = $headings [ $i ][ 1 ] ? $headings [ $i ][ 1 ] : " heading " ;
if ( isset ( $headings [ $i ][ 2 ])) {
$span = " colspan= \" " . $headings [ $i ][ 2 ] . " \" " ;
}
} else {
$title = $headings [ $i ];
$class = " heading " ;
$span = " " ;
}
2011-02-10 22:45:39 +00:00
echo " <th class= $class $span > $title </th> \n " ;
2007-11-12 20:57:15 +00:00
}
echo " </tr> \n " ;
}
2012-07-11 19:24:28 +00:00
function page_link ( $url , $page_num , $items_per_page , $text ) {
return " <a href= \" $url &start= " . $page_num * $items_per_page . " \" > $text </a> " ;
}
// return a string for navigating pages
2007-11-12 20:57:15 +00:00
//
2012-07-11 19:24:28 +00:00
function page_links ( $url , $nitems , $items_per_page , $start ){
2007-11-12 20:57:15 +00:00
// How many pages to potentially show before and after this one:
2012-07-11 19:24:28 +00:00
$preshow = 3 ;
$postshow = 3 ;
$x = " " ;
2007-11-12 20:57:15 +00:00
2012-07-11 19:24:28 +00:00
if ( $nitems <= $items_per_page ) return " " ;
$npages = ceil ( $nitems / $items_per_page );
$curpage = ceil ( $start / $items_per_page );
2007-11-12 20:57:15 +00:00
2012-07-11 19:24:28 +00:00
// If this is not the first page, display "previous"
//
if ( $curpage > 0 ){
$x .= page_link (
$url , $curpage - 1 , $items_per_page ,
tra ( " Previous " ) . " · "
);
}
2007-11-12 20:57:15 +00:00
2012-07-11 19:24:28 +00:00
if ( $curpage - $preshow > 0 ) {
$x .= page_link ( $url , 0 , $items_per_page , " 1 " );
2012-07-11 20:36:07 +00:00
if ( $curpage - $preshow > 1 ) {
$x .= " . . . " ;
} else {
$x .= " · " ;
}
2007-11-12 20:57:15 +00:00
}
2012-07-11 19:24:28 +00:00
// Display a list of pages surrounding this one
//
for ( $i = $curpage - $preshow ; $i <= $curpage + $postshow ; $i ++ ){
$page_str = ( string )( $i + 1 );
if ( $i < 0 ) continue ;
if ( $i >= $npages ) break ;
2007-11-12 20:57:15 +00:00
2012-07-11 19:24:28 +00:00
if ( $i == $curpage ) {
$x .= " <b> $page_str </b> " ;
} else {
$x .= page_link ( $url , $i , $items_per_page , $page_str );
}
2012-07-11 20:36:07 +00:00
if ( $i == $npages - 1 ) break ;
if ( $i == $curpage + $postshow ) break ;
2012-07-11 19:24:28 +00:00
$x .= " · " ;
}
if ( $curpage + $postshow < $npages - 1 ) {
$x .= " . . . " ;
$x .= page_link ( $url , $npages - 1 , $items_per_page , $npages );
}
// If there is a next page
//
if ( $curpage < $npages - 1 ){
$x .= page_link (
$url , $curpage + 1 , $items_per_page ,
" · " . tra ( " Next " )
);
}
2012-07-11 20:36:07 +00:00
$x .= " \n " ;
2012-07-11 19:24:28 +00:00
return $x ;
2007-11-12 20:57:15 +00:00
}
2006-07-10 17:18:42 +00:00
2007-11-12 20:57:15 +00:00
function thread_is_unread ( $user , $thread ) {
if ( ! $user ) return false ;
2008-08-09 19:27:17 +00:00
if ( $thread -> timestamp <= $user -> prefs -> mark_as_read_timestamp ) return false ;
2007-12-21 17:10:46 +00:00
$log = BoincForumLogging :: lookup ( $user -> id , $thread -> id );
2008-08-09 19:27:17 +00:00
if ( $log && ( $thread -> timestamp <= $log -> timestamp )) return false ;
2007-11-12 20:57:15 +00:00
return true ;
}
// Process a user-supplied title to remove HTML stuff
//
2005-01-09 21:52:22 +00:00
function cleanup_title ( $title ) {
2011-08-26 18:30:13 +00:00
$x = sanitize_tags ( bb2html ( $title ));
2009-12-18 04:32:30 +00:00
$x = trim ( $x );
2005-01-09 21:52:22 +00:00
if ( strlen ( $x ) == 0 ) return " (no title) " ;
else return $x ;
}
2007-11-15 22:51:05 +00:00
function can_reply ( $thread , $forum , $user ) {
if ( $thread -> locked ) {
if ( ! is_moderator ( $user , $forum )) return false ;
2004-09-05 19:26:27 +00:00
}
2007-11-15 22:51:05 +00:00
return true ;
2004-09-04 23:37:49 +00:00
}
2007-11-12 20:57:15 +00:00
// Show the posts in a thread for a user.
2012-07-12 18:07:06 +00:00
// If $start is null, enforce jump-to-first-unread
2007-11-12 20:57:15 +00:00
//
2007-10-30 23:34:26 +00:00
function show_posts (
2012-07-12 19:01:34 +00:00
$thread , $forum , $start , $postid , $sort_style , $filter , $logged_in_user
2007-10-30 23:34:26 +00:00
) {
2004-02-02 23:34:39 +00:00
$n = 1 ;
2012-08-02 16:17:10 +00:00
2012-07-11 05:27:31 +00:00
$num_to_show = 20 ;
if ( $logged_in_user && $logged_in_user -> prefs -> display_wrap_postcount > 0 ) {
$num_to_show = $logged_in_user -> prefs -> display_wrap_postcount ;
}
2012-07-11 19:24:28 +00:00
// let moderators see all posts, including hidden ones
2007-11-15 22:51:05 +00:00
//
if ( is_moderator ( $logged_in_user , $forum )) {
$show_hidden = true ;
2005-01-18 13:00:38 +00:00
} else {
2007-11-15 22:51:05 +00:00
$show_hidden = false ;
2005-01-18 13:00:38 +00:00
}
2012-07-11 19:24:28 +00:00
2007-11-15 22:51:05 +00:00
$posts = get_thread_posts ( $thread -> id , $sort_style , $show_hidden );
2012-07-11 19:24:28 +00:00
$latest_viewed = 0 ;
2012-07-11 20:36:07 +00:00
$forum_log = null ;
2007-10-30 23:34:26 +00:00
if ( $logged_in_user ) {
2012-07-11 20:36:07 +00:00
$forum_log = BoincForumLogging :: lookup ( $logged_in_user -> id , $thread -> id );
if ( $forum_log ) {
$latest_viewed = $forum_log -> timestamp ;
2012-07-11 19:24:28 +00:00
}
2007-10-30 23:34:26 +00:00
}
2004-02-02 23:34:39 +00:00
2012-10-18 07:17:16 +00:00
if ( $sort_style == CREATE_TIME_OLD ) {
2012-11-08 20:22:56 +00:00
// show the last page
//
2012-10-18 07:17:16 +00:00
$nposts = sizeof ( $posts );
2012-11-08 20:22:56 +00:00
if ( $nposts ) $nposts -= 1 ;
2012-10-18 07:17:16 +00:00
$page = ( int )( $nposts / $num_to_show );
$default_start = $page * $num_to_show ;
} else {
$default_start = 0 ;
}
2012-07-12 19:01:34 +00:00
// jump to a specific post if needed
2012-07-12 18:07:06 +00:00
//
2012-07-12 19:01:34 +00:00
$jump_to_post = null ;
2012-07-12 18:07:06 +00:00
if ( $start === null ) {
2012-07-12 19:01:34 +00:00
if ( $postid ) {
// jump to a specific post
//
$i = 0 ;
foreach ( $posts as $post ) {
if ( $post -> id == $postid ) {
$start = $i - ( $i % $num_to_show );
$jump_to_post = $post ;
break ;
}
$i ++ ;
}
if ( $start === null ) {
echo " Post $postid not found. " ;
return ;
}
2012-07-17 04:06:48 +00:00
} else if ( $logged_in_user && $logged_in_user -> prefs -> jump_to_unread ) {
2012-07-12 19:01:34 +00:00
// jump to the first unread post
//
2012-07-12 18:07:06 +00:00
$i = 0 ;
$ibest = 0 ;
foreach ( $posts as $post ) {
if ( $post -> timestamp > $latest_viewed ) {
2012-07-12 19:01:34 +00:00
if ( ! $jump_to_post || ( $post -> timestamp < $jump_to_post -> timestamp )) {
$jump_to_post = $post ;
2012-07-12 18:07:06 +00:00
$ibest = $i ;
}
}
$i ++ ;
}
2012-07-12 19:01:34 +00:00
if ( $jump_to_post ) {
2012-07-12 18:07:06 +00:00
$start = $ibest - ( $ibest % $num_to_show );
} else {
2012-10-18 07:17:16 +00:00
$start = $default_start ;
2012-07-12 18:07:06 +00:00
}
} else {
2012-10-18 07:17:16 +00:00
$start = $default_start ;
2012-07-12 18:07:06 +00:00
}
}
2012-07-11 19:24:28 +00:00
$page_nav = page_links (
" forum_thread.php?id= $thread->id &sort_style= $sort_style " ,
sizeof ( $posts ),
$num_to_show ,
$start
);
echo $page_nav ;
2012-07-11 05:27:31 +00:00
$num_shown = 0 ;
2012-07-11 05:37:43 +00:00
$num_skipped = 0 ;
2012-07-11 19:24:28 +00:00
$headings = array ( array ( tra ( " Author " ), " authorcol " ), array ( tra ( " Message " ), " " ));
start_forum_table ( $headings , " id= \" thread \" cellspacing=0 " );
2012-07-12 22:43:23 +00:00
$latest_shown_timestamp = 0 ;
2012-07-12 18:07:06 +00:00
foreach ( $posts as $post ) {
2012-07-11 19:24:28 +00:00
if ( $num_skipped < $start ) {
2012-07-11 05:37:43 +00:00
$num_skipped ++ ;
2012-07-11 05:27:31 +00:00
continue ;
}
if ( $num_shown == $num_to_show ) {
break ;
2007-10-30 23:34:26 +00:00
}
2012-07-11 05:27:31 +00:00
show_post (
2012-07-11 19:24:28 +00:00
$post , $thread , $forum , $logged_in_user , $latest_viewed , $n ,
2012-07-12 19:01:34 +00:00
FORUM_CONTROLS , $filter
2012-07-11 05:27:31 +00:00
);
$n = ( $n + 1 ) % 2 ;
2012-07-12 22:43:23 +00:00
if ( $post -> timestamp > $latest_shown_timestamp ) {
$latest_shown_timestamp = $post -> timestamp ;
2012-07-11 19:24:28 +00:00
}
2012-07-11 05:27:31 +00:00
$num_shown ++ ;
}
2012-07-11 19:24:28 +00:00
end_table ();
echo $page_nav ;
2005-01-09 21:52:22 +00:00
2012-07-12 19:01:34 +00:00
if ( $jump_to_post ) {
echo " <script>function jumpToUnread() { location.href='# " . $jump_to_post -> id . " ';}</script> " ;
2012-07-12 18:07:06 +00:00
} else {
echo " <script>function jumpToUnread() { };</script> " ;
2004-10-10 03:04:29 +00:00
}
2006-06-16 23:53:56 +00:00
2012-07-12 22:43:23 +00:00
if ( $logged_in_user ) {
if ( ! $forum_log || $latest_shown_timestamp > $forum_log -> timestamp ) {
BoincForumLogging :: replace (
$logged_in_user -> id , $thread -> id , $latest_shown_timestamp
);
}
2007-11-12 20:57:15 +00:00
}
2004-02-02 23:34:39 +00:00
}
2007-11-13 17:18:34 +00:00
function get_ignored_list ( $user ) {
return explode ( " | " , $user -> prefs -> ignorelist );
}
2007-11-12 20:57:15 +00:00
function add_ignored_user ( $user , $other_user ) {
$list = explode ( " | " , $user -> prefs -> ignorelist );
foreach ( $list as $key => $userid ) {
if ( $userid == $other_user -> id ) {
return true ;
}
}
$list [] = $other_user -> id ;
$x = implode ( " | " , array_values ( $list ));
return $user -> prefs -> update ( " ignorelist=' $x ' " );
}
function remove_ignored_user ( $user , $other_user ) {
$list = explode ( " | " , $user -> prefs -> ignorelist );
foreach ( $list as $key => $userid ) {
if ( $userid == $other_user -> id ) {
unset ( $list [ $key ]);
}
}
$x = implode ( " | " , array_values ( $list ));
return $user -> prefs -> update ( " ignorelist=' $x ' " );
}
function is_ignoring ( $user , $other_user ) {
$list = explode ( " | " , $user -> prefs -> ignorelist );
return in_array ( $other_user -> id , $list );
}
// Display an individual post
//
function show_post (
2012-07-11 19:24:28 +00:00
$post , $thread , $forum , $logged_in_user , $latest_viewed , $n ,
2012-07-11 05:37:43 +00:00
$controls = FORUM_CONTROLS , $filter = true
2007-11-12 20:57:15 +00:00
) {
2009-06-12 04:36:18 +00:00
global $country_to_iso3166_2 ;
2007-11-12 20:57:15 +00:00
$user = BoincUser :: lookup_id ( $post -> user );
BoincForumPrefs :: lookup ( $user );
2007-12-02 21:11:17 +00:00
if ( is_banished ( $user ) && ! is_moderator ( $logged_in_user , $forum )) {
return ;
}
2012-07-11 05:37:43 +00:00
2008-10-05 13:06:00 +00:00
// If the user no longer exists, skip the post
2012-07-11 05:37:43 +00:00
//
2008-10-05 13:06:00 +00:00
if ( ! $user ){
2009-09-29 21:58:54 +00:00
return ;
2008-10-05 13:06:00 +00:00
}
2007-11-12 20:57:15 +00:00
$config = get_config ();
$no_forum_rating = parse_bool ( $config , " no_forum_rating " );
2006-06-16 23:53:56 +00:00
2007-10-30 23:34:26 +00:00
$tokens = " " ;
2007-11-20 19:23:26 +00:00
$options = get_output_options ( $logged_in_user );
2014-03-14 07:20:07 +00:00
if ( is_admin ( $user )) {
2014-03-13 20:08:27 +00:00
$options -> htmlitems = false ;
}
2007-02-08 19:54:05 +00:00
2009-09-29 21:58:54 +00:00
// check whether the poster is on the list of people to ignore
2007-10-30 23:34:26 +00:00
//
2009-09-29 21:58:54 +00:00
$ignore_poster = false ;
2006-06-16 23:53:56 +00:00
if ( $logged_in_user ){
2007-11-12 20:57:15 +00:00
$tokens = url_tokens ( $logged_in_user -> authenticator );
if ( is_ignoring ( $logged_in_user , $user )){
2009-09-29 21:58:54 +00:00
$ignore_poster = true ;
2006-06-16 23:53:56 +00:00
}
2005-01-06 11:47:44 +00:00
}
2007-10-30 23:34:26 +00:00
2006-08-01 22:28:03 +00:00
// The creator can edit the post, but only in a specified amount of time
// (exception: a moderator can edit his/her posts at any time)
2006-08-01 21:45:05 +00:00
//
2006-08-01 22:28:03 +00:00
$can_edit = false ;
if ( $logged_in_user ) {
2007-11-12 20:57:15 +00:00
if ( $user -> id == $logged_in_user -> id ) {
2007-11-15 22:51:05 +00:00
if ( is_moderator ( $logged_in_user , $forum )) {
2006-08-01 22:28:03 +00:00
$can_edit = true ;
2007-11-16 20:52:42 +00:00
} else if ( can_reply ( $thread , $forum , $logged_in_user )) {
2007-11-12 20:57:15 +00:00
$time_limit = $post -> timestamp + MAXIMUM_EDIT_TIME ;
2006-08-01 22:28:03 +00:00
$can_edit = time () < $time_limit ;
2006-12-29 20:57:29 +00:00
} else {
$can_edit = false ;
2006-08-01 22:28:03 +00:00
}
}
}
2006-08-01 21:45:05 +00:00
2006-06-16 23:53:56 +00:00
// Print the special user lines, if any
2012-07-11 05:37:43 +00:00
//
2010-12-21 17:15:57 +00:00
global $special_user_bitfield ;
2005-05-11 08:59:42 +00:00
$fstatus = " " ;
2006-06-16 23:53:56 +00:00
$keys = array_keys ( $special_user_bitfield );
2008-10-05 16:00:11 +00:00
$is_posted_by_special = false ;
2006-06-16 23:53:56 +00:00
for ( $i = 0 ; $i < sizeof ( $special_user_bitfield ); $i ++ ) {
2008-10-05 13:06:00 +00:00
if ( $user -> prefs && $user -> prefs -> privilege ( $keys [ $i ])) {
2006-06-16 23:53:56 +00:00
$fstatus .= $special_user_bitfield [ $keys [ $i ]] . " <br> " ;
2009-09-29 21:58:54 +00:00
$is_posted_by_special = true ;
2005-09-20 17:54:52 +00:00
}
2004-09-04 23:37:49 +00:00
}
2008-10-05 16:00:11 +00:00
// Highlight special users if set in prefs;
2012-07-11 05:37:43 +00:00
//
2008-10-05 16:00:11 +00:00
if ( $logged_in_user && $logged_in_user -> prefs ){
2009-09-29 21:58:54 +00:00
$highlight = $logged_in_user -> prefs -> highlight_special && $is_posted_by_special ;
2008-10-05 16:00:11 +00:00
} else {
2009-09-29 21:58:54 +00:00
$highlight = $is_posted_by_special ;
2008-10-05 16:00:11 +00:00
}
echo "
< tr >
2010-11-03 21:48:39 +00:00
< td class = \ " leftcol " . ( $highlight ? " highlighted_ " : " " ) . " row $n\ " rowspan = \ " 3 \" >
2008-10-05 16:00:11 +00:00
< a name = \ " $post->id\ " ></ a >
< div class = \ " authorcol \" >
" ;
echo user_links ( $user );
echo " <br> " ;
2007-11-12 20:57:15 +00:00
if ( $user -> create_time > time () - ST_NEW_TIME ) $fstatus .= ST_NEW . " <br> " ;
2005-02-08 21:20:00 +00:00
if ( $fstatus ) echo " <font size= \" -2 \" > $fstatus </font> " ;
2004-12-21 23:06:31 +00:00
2006-06-16 23:53:56 +00:00
echo " <span class= \" authorinfo \" > " ;
2009-09-29 21:58:54 +00:00
if ( ! $filter || ! $ignore_poster ){
2008-10-05 13:06:00 +00:00
if ( $user -> prefs && $user -> prefs -> avatar != " " && ( ! $logged_in_user || ( $logged_in_user -> prefs -> hide_avatars == false ))) {
2009-06-12 16:35:08 +00:00
echo " <img class=authorinfo width= \" " . AVATAR_WIDTH . " \" height= \" " . AVATAR_HEIGHT . " \" src= \" " . $user -> prefs -> avatar . " \" alt= \" Avatar \" ><br> " ;
2005-01-09 21:52:22 +00:00
}
2007-03-27 14:43:00 +00:00
}
2011-08-29 05:37:52 +00:00
$url = " pm.php?action=new&userid= " . $user -> id ;
2007-11-12 20:57:15 +00:00
$name = $user -> name ;
2011-12-24 15:37:20 +00:00
show_button ( $url , tra ( " Send message " ), tra ( " Send %1 a private message " , $name ));
echo " <br> " . tra ( " Joined: %1 " , gmdate ( 'j M y' , $user -> create_time )), " <br> " ;
2007-11-12 20:57:15 +00:00
if ( ! isset ( $user -> nposts )) {
$user -> nposts = BoincPost :: count ( " user= $user->id " );
}
2007-05-15 10:06:38 +00:00
2008-08-09 16:39:20 +00:00
if ( function_exists ( 'project_forum_user_info' )){
2007-03-27 14:43:00 +00:00
project_forum_user_info ( $user );
2008-08-09 16:39:20 +00:00
} else {
2011-12-24 15:37:20 +00:00
echo tra ( " Posts: %1 " , $user -> nposts ) . " <br> " ;
2007-03-27 14:43:00 +00:00
// circumvent various forms of identity spoofing
// by displaying the user id of the poster.
2007-11-12 20:57:15 +00:00
//
2009-06-10 22:54:21 +00:00
//echo "ID: ".$user->id."<br>";
2008-08-09 16:39:20 +00:00
if ( ! no_computing ()) {
2011-12-24 15:37:20 +00:00
echo tra ( " Credit: %1 " , number_format ( $user -> total_credit )) . " <br> " ;
echo tra ( " RAC: %1 " , number_format ( $user -> expavg_credit )) . " <br> " ;
2008-08-09 16:39:20 +00:00
}
2013-02-11 23:07:51 +00:00
2009-06-12 04:26:01 +00:00
// to use this feature:
// - get flags from http://www.famfamfam.com/lab/icons/flags/famfamfam_flag_icons.zip
// - put the .png's in html/user/flags/
2013-02-11 23:07:51 +00:00
// - put define("COUNTRY_FLAGS", 1); in your html/project/project.inc
2009-06-12 04:26:01 +00:00
//
2009-06-12 04:36:18 +00:00
if ( defined ( " COUNTRY_FLAGS " )) {
2009-06-12 04:26:01 +00:00
if ( array_key_exists ( $user -> country , $country_to_iso3166_2 )) {
$code = $country_to_iso3166_2 [ $user -> country ];
2009-06-12 16:35:08 +00:00
echo " <img class=flag alt= \" $user->country\ " title = \ " $user->country\ " src = flags / $code . png >< br > \n " ;
2009-06-12 04:26:01 +00:00
}
}
2004-10-25 22:04:15 +00:00
}
2006-06-16 23:53:56 +00:00
echo " </span></div></td> " ;
2005-01-14 19:45:43 +00:00
2008-08-07 20:43:52 +00:00
echo " <td class= \" postheader \" > " ;
2006-06-16 23:53:56 +00:00
if ( $controls == FORUM_CONTROLS ) {
2007-11-12 20:57:15 +00:00
echo " <form action= \" forum_rate.php?post= " , $post -> id , " \" method= \" post \" > " ;
2005-11-24 16:26:05 +00:00
}
2004-09-04 23:37:49 +00:00
2012-07-11 19:24:28 +00:00
if ( $logged_in_user && $post -> timestamp > $latest_viewed ){
2011-12-24 15:37:20 +00:00
show_image ( NEW_IMAGE , tra ( " You haven't read this message yet " ), tra ( " Unread " ), NEW_IMAGE_HEIGHT );
2004-09-04 23:37:49 +00:00
}
2005-01-09 21:52:22 +00:00
2012-07-12 19:01:34 +00:00
echo " <a href= \" forum_thread.php?id= " . $thread -> id . " &postid= $post->id\ " > " .tra( " Message % 1 " , $post->id ). " </ a > - " ;
2011-12-24 15:37:20 +00:00
if ( $post -> hidden ) echo " <font color=red>[ " . tra ( " hidden " ) . " ] </font> " ;
echo tra ( " Posted: %1 " , pretty_time_str ( $post -> timestamp )), " " ;
2004-02-02 23:34:39 +00:00
2007-11-12 20:57:15 +00:00
if ( $post -> parent_post ) {
2012-07-12 19:01:34 +00:00
echo tra ( " - in response to " ) . " <a href= \" forum_thread.php?id= " . $thread -> id . " &postid= " . $post -> parent_post . " \" > " . tra ( " Message %1 " , $post -> parent_post ) . " </a>. " ;
2007-11-02 18:48:48 +00:00
}
if ( $can_edit && $controls != NO_CONTROLS ) {
2011-12-24 15:37:20 +00:00
show_button ( " forum_edit.php?id= " . $post -> id . " $tokens " , tra ( " Edit " ), tra ( " Edit this message " ));
2007-11-02 18:48:48 +00:00
}
2007-11-15 22:51:05 +00:00
if ( is_moderator ( $logged_in_user , $forum )) {
show_post_moderation_links ( $config , $logged_in_user , $post , $forum , $tokens );
2007-11-02 18:48:48 +00:00
}
2007-11-12 20:57:15 +00:00
if ( $post -> modified ) {
2011-12-24 15:37:20 +00:00
echo " <br> " . tra ( " Last modified: %1 " , pretty_time_Str ( $post -> modified ));
2007-11-02 18:48:48 +00:00
}
2009-09-29 21:58:54 +00:00
if ( $ignore_poster && $filter ){
2011-12-24 15:37:20 +00:00
echo " <br> " . tra ( " This post is not shown because the sender is on your 'ignore' list. Click %1here%2 to view this post " , " <a href= \" ?id= " . $thread -> id . " &filter=false# " . $post -> id . " \" > " , " </a> " );
2004-02-02 23:34:39 +00:00
}
2011-08-29 05:37:52 +00:00
if ( $controls == FORUM_CONTROLS ) {
echo " </form> \n " ;
}
2008-08-09 16:39:20 +00:00
echo " </td>
</ tr >
2008-10-05 16:00:11 +00:00
< tr class = \ " " . ( $highlight ? " highlighted_ " : " " ) . " row $n\ " >
2008-08-09 16:39:20 +00:00
< td class = \ " postbody \" >
" ;
2006-06-16 23:53:56 +00:00
2009-09-29 21:58:54 +00:00
if ( ! $filter || ! $ignore_poster ){
2007-11-12 20:57:15 +00:00
$posttext = $post -> content ;
2005-09-20 17:54:52 +00:00
// If the creator of this post has a signature and
// wants it to be shown for this post AND the logged in
// user has signatures enabled: show it
//
2007-11-12 20:57:15 +00:00
if ( $post -> signature && ( ! $logged_in_user || ! $logged_in_user -> prefs -> hide_signatures )){
$posttext .= " \n ____________ \n " . $user -> prefs -> signature ;
2005-09-20 17:54:52 +00:00
}
2007-11-20 19:23:26 +00:00
$posttext = output_transform ( $posttext , $options );
2005-05-13 19:11:04 +00:00
2005-05-17 08:53:29 +00:00
echo " <p> " , $posttext , " </p> " ;
2006-06-16 23:53:56 +00:00
echo " </td></tr><tr><td class= \" postfooter \" >ID: <i> " , $post -> id ;
2010-12-21 17:15:57 +00:00
if ( $no_forum_rating ) {
2012-12-19 00:38:40 +00:00
echo " · <a href= \" forum_report_post.php?post= " . $post -> id . " \" > " ;
2011-12-24 15:37:20 +00:00
show_image ( REPORT_POST_IMAGE , tra ( " Report this post as offensive " ), tra ( " Report as offensive " ), REPORT_POST_IMAGE_HEIGHT );
2008-08-07 21:43:02 +00:00
echo " </a> " ;
2006-07-10 17:18:42 +00:00
} else {
2007-11-12 20:57:15 +00:00
$rating = $post -> rating ();
2012-12-19 00:38:40 +00:00
echo " · " . tra ( " Rating: %1 " , $rating ) . " </i> · " . tra ( " rate: " ) . "
2007-11-12 20:57:15 +00:00
< a href = \ " forum_rate.php?post= " . $post -> id . " &choice=p $tokens\ " >
2007-11-01 20:41:24 +00:00
" ;
2011-12-24 15:37:20 +00:00
show_image ( RATE_POSITIVE_IMAGE , tra ( " Click if you like this message " ), tra ( " Rate + " ), RATE_POSITIVE_IMAGE_HEIGHT );
2011-08-29 05:37:52 +00:00
echo " </a> / <a href= \" forum_rate.php?post= " . $post -> id . " &choice=n $tokens\ " > " ;
2011-12-24 15:37:20 +00:00
show_image ( RATE_NEGATIVE_IMAGE , tra ( " Click if you don't like this message " ), tra ( " Rate - " ), RATE_NEGATIVE_IMAGE_HEIGHT );
2007-11-12 20:57:15 +00:00
echo " </a> <a href= \" forum_report_post.php?post= " . $post -> id . " \" > " ;
2011-12-24 15:37:20 +00:00
show_image ( REPORT_POST_IMAGE , tra ( " Report this post as offensive " ), tra ( " Report as offensive " ), REPORT_POST_IMAGE_HEIGHT );
2008-08-07 20:43:52 +00:00
echo " </a> " ;
2006-07-10 17:18:42 +00:00
}
2007-11-17 00:44:21 +00:00
if (( $controls == FORUM_CONTROLS ) && ( can_reply ( $thread , $forum , $logged_in_user ))) {
2011-02-10 22:45:39 +00:00
echo " " ;
2011-08-29 05:37:52 +00:00
$url = " forum_reply.php?thread= " . $thread -> id . " &post= " . $post -> id . " &no_quote=1#input " ;
2011-12-24 15:37:20 +00:00
show_button ( $url , tra ( " Reply " ), tra ( " Post a reply to this message " ));
2011-08-29 05:37:52 +00:00
$url = " forum_reply.php?thread= " . $thread -> id . " &post= " . $post -> id . " #input " ;
2011-12-24 15:37:20 +00:00
show_button ( $url , tra ( " Quote " ), tra ( " Post a reply by quoting this message " ));
2006-06-16 23:53:56 +00:00
}
2008-08-07 20:43:52 +00:00
echo " </td></tr> " ;
2007-06-22 13:19:56 +00:00
} else {
2008-08-07 20:43:52 +00:00
echo " </td></tr><tr><td class= \" postfooter \" > " ;
2004-02-02 23:34:39 +00:00
}
2010-11-08 17:56:39 +00:00
echo " <tr class= \" postseparator \" ><td colspan=2></td></tr> " ;
2004-02-02 23:34:39 +00:00
}
2007-11-20 19:23:26 +00:00
// Show a post and its context (e.g. for search results, user posts)
//
function show_post_and_context ( $post , $thread , $forum , $options , $n ) {
$thread = BoincThread :: lookup_id ( $post -> thread );
$forum = BoincForum :: lookup_id ( $thread -> forum );
$content = output_transform ( $post -> content , $options );
$when = time_diff_str ( $post -> timestamp , time ());
2014-04-24 16:41:59 +00:00
$user = BoincUser :: lookup_id ( $post -> user );
2007-11-20 19:23:26 +00:00
$title = cleanup_title ( $thread -> title );
$m = $n % 2 ;
if ( $post -> hidden ) {
2011-12-24 15:37:20 +00:00
$deleted = " <br><font color=red>[ " . tra ( " Hidden by a moderator " ) . " ]</font> " ;
2007-11-20 19:23:26 +00:00
} else {
$deleted = " " ;
}
echo "
< tr class = row $m >
< td >
$n )
" ;
switch ( $forum -> parent_type ) {
case 0 :
$category = BoincCategory :: lookup_id ( $forum -> category );
2011-09-27 07:35:26 +00:00
show_forum_title ( $category , $forum , $thread , true );
2007-11-20 19:23:26 +00:00
break ;
case 1 :
show_team_forum_title ( $forum );
break ;
}
echo "
2012-07-12 19:01:34 +00:00
( < a href = \ " forum_thread.php?id= " . $thread -> id . " &postid= " . $post -> id . " \" > " . tra ( " Message %1 " , $post -> id ) . " </a>)
2007-11-20 19:23:26 +00:00
< br >
2011-12-24 15:37:20 +00:00
" .tra( " Posted % 1 by % 2 " , $when , user_links( $user )). " $deleted
2007-11-20 19:23:26 +00:00
< hr >
$content
</ td ></ tr >
" ;
}
2007-12-02 21:11:17 +00:00
function is_banished ( $user ) {
2008-10-08 16:48:11 +00:00
if ( isset ( $user -> prefs )) {
return ( $user -> prefs -> banished_until > time ());
} else {
return false ;
}
2007-12-02 21:11:17 +00:00
}
2007-11-12 20:57:15 +00:00
function check_banished ( $user ) {
2007-12-02 21:11:17 +00:00
if ( is_banished ( $user )) {
2007-11-12 20:57:15 +00:00
error_page (
2011-12-24 15:37:20 +00:00
tra ( " You may not post or rate messages until %1 " , gmdate ( 'M j, Y' , $user -> prefs -> banished_until ))
2007-11-12 20:57:15 +00:00
);
2005-09-20 17:54:52 +00:00
}
2004-02-02 23:34:39 +00:00
}
2006-06-16 23:53:56 +00:00
function post_rules () {
2007-11-28 17:40:08 +00:00
if ( function_exists ( " project_forum_post_rules " )) {
$project_rules = project_forum_post_rules ();
} else {
$project_rules = " " ;
}
2011-12-24 15:37:20 +00:00
return tra ( "
2006-06-12 18:53:09 +00:00
< ul >
2006-09-25 18:51:50 +00:00
< li > Posts must be 'kid friendly' : they may not contain
content that is obscene , hate - related ,
sexually explicit or suggestive .
2006-06-12 18:53:09 +00:00
< li > No commercial advertisements .
2006-09-25 18:51:50 +00:00
< li > No links to web sites involving sexual content ,
gambling , or intolerance of others .
< li > No messages intended to annoy or antagonize other people ,
or to hijack a thread .
2006-06-12 18:53:09 +00:00
< li > No messages that are deliberately hostile or insulting .
< li > No abusive comments involving race , religion ,
2006-09-25 18:51:50 +00:00
nationality , gender , class or sexuality .
2011-12-24 15:37:20 +00:00
" ). $project_rules . "
2006-06-12 18:53:09 +00:00
</ ul >
2006-06-16 23:53:56 +00:00
" ;
}
function post_warning () {
return " <br><br>
2007-11-23 21:05:52 +00:00
< table >< tr >< td align = left >
2006-06-16 23:53:56 +00:00
< font size =- 2 >
2011-12-24 15:37:20 +00:00
" .tra( " Rules : " ).post_rules(). "
< a href = moderation . php > " .tra( " More info " ). " </ a >
2006-06-12 18:53:09 +00:00
</ font >
</ td ></ tr ></ table >
2005-02-16 00:24:53 +00:00
" ;
}
2007-12-30 22:02:16 +00:00
function notify_subscriber ( $thread , $user ) {
BoincForumPrefs :: lookup ( $user );
if ( $user -> prefs -> pm_notification == 1 ) {
send_reply_notification_email ( $thread , $user );
}
$now = time ();
$type = NOTIFY_SUBSCRIBED_POST ;
BoincNotify :: replace ( " userid= $user->id , create_time= $now , type= $type , opaque= $thread->id " );
}
2007-11-12 20:57:15 +00:00
// Various functions for adding/hiding/unhiding stuff.
// These take care of counts and timestamps.
// Don't do these things directly - use these functions
//
function create_post ( $content , $parent_id , $user , $forum , $thread , $signature ) {
$content = substr ( $content , 0 , 64000 );
2013-11-23 06:46:19 +00:00
$content = BoincDb :: escape_string ( $content );
2007-11-12 20:57:15 +00:00
$now = time ();
$sig = $signature ? 1 : 0 ;
$id = BoincPost :: insert ( " (thread, user, timestamp, content, parent_post, signature) values ( $thread->id , $user->id , $now , ' $content ', $parent_id , $sig ) " );
if ( ! $id ) return null ;
2007-12-30 22:02:16 +00:00
// notify subscribed users
2007-11-12 20:57:15 +00:00
//
$subs = BoincSubscription :: enum ( " threadid= $thread->id " );
foreach ( $subs as $sub ) {
if ( $user -> id == $sub -> userid ) continue ;
$user2 = BoincUser :: lookup_id ( $sub -> userid );
2008-10-12 15:32:12 +00:00
if ( $user2 ) {
notify_subscriber ( $thread , $user2 );
}
2006-08-08 20:32:37 +00:00
}
2009-08-18 20:44:12 +00:00
$user -> prefs -> update ( " posts=posts+1 " );
2007-11-12 20:57:15 +00:00
$thread -> update ( " replies=replies+1, timestamp= $now " );
$forum -> update ( " posts=posts+1, timestamp= $now " );
2012-08-01 17:57:56 +00:00
return $id ;
2006-08-08 20:32:37 +00:00
}
2008-07-01 16:34:51 +00:00
// call this when hide or delete a post;
// it sets timestamp to time of last non-hidden post
//
function update_thread_timestamp ( $thread ) {
$posts = BoincPost :: enum ( " thread= $thread->id and hidden=0 order by timestamp desc limit 1 " );
if ( count ( $posts ) > 0 ) {
$post = $posts [ 0 ];
$thread -> update ( " timestamp= $post->timestamp " );
}
}
function update_forum_timestamp ( $forum ) {
$threads = BoincThread :: enum ( " forum= $forum->id and hidden=0 order by timestamp desc limit 1 " );
if ( count ( $threads ) > 0 ) {
$thread = $threads [ 0 ];
$forum -> update ( " timestamp= $thread->timestamp " );
}
}
2011-06-14 05:42:52 +00:00
function create_thread ( $title , $content , $user , $forum , $signature , $export ) {
2007-11-12 20:57:15 +00:00
$title = trim ( $title );
2011-08-26 18:30:13 +00:00
$title = sanitize_tags ( $title );
2013-11-23 06:46:19 +00:00
$title = BoincDb :: escape_string ( $title );
2007-11-12 20:57:15 +00:00
$now = time ();
2011-06-14 05:42:52 +00:00
$status = 0 ;
if ( is_news_forum ( $forum ) && ! $export ) {
$status = 1 ;
}
$id = BoincThread :: insert ( " (forum, owner, title, create_time, timestamp, replies, status) values ( $forum->id , $user->id , ' $title ', $now , $now , -1, $status ) " );
2007-11-12 20:57:15 +00:00
if ( ! $id ) return null ;
$thread = BoincThread :: lookup_id ( $id );
create_post ( $content , 0 , $user , $forum , $thread , $signature );
$forum -> update ( " threads=threads+1 " );
return $thread ;
}
function hide_post ( $post , $thread , $forum ) {
2008-07-01 16:34:51 +00:00
$ret = $post -> update ( " hidden=1 " );
if ( ! $ret ) return $ret ;
2007-11-12 20:57:15 +00:00
$thread -> update ( " replies=replies-1 " );
2008-07-01 16:34:51 +00:00
$forum -> update ( " posts=posts-1 " );
update_thread_timestamp ( $thread );
update_forum_timestamp ( $forum );
return true ;
2007-11-12 20:57:15 +00:00
}
function unhide_post ( $post , $thread , $forum ) {
2008-07-01 16:34:51 +00:00
$ret = $post -> update ( " hidden=0 " );
if ( ! $ret ) return $ret ;
$thread -> update ( " replies=replies+1 " );
$forum -> update ( " posts=posts+1 " );
update_thread_timestamp ( $thread );
update_forum_timestamp ( $forum );
return true ;
2007-11-12 20:57:15 +00:00
}
2007-11-23 00:51:01 +00:00
function delete_post ( $post , $thread , $forum ) {
$post -> delete ();
2008-06-19 03:44:27 +00:00
if ( ! $post -> hidden ) {
$thread -> update ( " replies=replies-1 " );
$forum -> update ( " posts=posts-1 " );
}
2007-11-23 00:51:01 +00:00
$count = BoincPost :: count ( " thread= $thread->id " );
if ( $count == 0 ) {
2014-04-17 05:54:17 +00:00
if ( ! $thread -> hidden ) {
$forum -> update ( " threads=threads-1 " );
}
2007-11-23 00:51:01 +00:00
$thread -> delete ();
2008-07-01 16:34:51 +00:00
} else {
update_thread_timestamp ( $thread );
2007-11-23 00:51:01 +00:00
}
2014-04-17 05:54:17 +00:00
return true ;
}
function delete_thread ( $thread , $forum ) {
$nposts = BoincPost :: count ( " thread= $thread->id and hidden=0 " );
$forum -> update ( " posts=posts- $nposts " );
BoincPost :: delete_aux ( " thread= $thread->id " );
if ( ! $thread -> hidden ) {
$forum -> update ( " threads=threads-1 " );
}
$thread -> delete ();
2007-11-23 00:51:01 +00:00
}
2011-02-08 21:38:16 +00:00
// delete all forum records related to user
//
function forum_delete_user ( $user ) {
$pp = BoincPost :: enum ( " user= $user->id " );
2011-02-03 23:27:30 +00:00
foreach ( $pp as $p ) {
$t = BoincThread :: lookup_id ( $p -> thread );
$f = BoincForum :: lookup_id ( $t -> forum );
if ( $t && $f ) {
delete_post ( $p , $t , $f );
}
}
2011-02-08 21:38:16 +00:00
$ss = BoincSubscription :: enum ( " userid= $user->id " );
foreach ( $ss as $s ) {
BoincSubscription :: delete ( $s -> userid , $s -> threadid );
}
$p = BoincForumPrefs :: lookup_userid ( $user -> id );
$p -> delete ();
2011-02-03 23:27:30 +00:00
}
2007-11-12 20:57:15 +00:00
function move_post ( $post , $old_thread , $old_forum , $new_thread , $new_forum ) {
$post -> update ( " thread= $new_thread->id " );
$old_thread -> update ( " replies=replies-1 " );
2008-07-01 16:34:51 +00:00
$new_thread -> update ( " replies=replies+1 " );
2007-11-12 20:57:15 +00:00
$old_forum -> update ( " posts=posts-1 " );
2008-07-01 16:34:51 +00:00
$new_forum -> update ( " posts=posts+1 " );
update_thread_timestamp ( $old_thread );
update_thread_timestamp ( $new_thread );
update_forum_timestamp ( $old_forum );
update_forum_timestamp ( $new_forum );
return true ;
2007-11-12 20:57:15 +00:00
}
function hide_thread ( $thread , $forum ) {
2008-07-01 16:34:51 +00:00
$ret = $thread -> update ( " hidden=1 " );
if ( ! $ret ) return $ret ;
2007-11-12 20:57:15 +00:00
$forum -> update ( " threads=threads-1 " );
2008-07-01 16:34:51 +00:00
$forum -> update ( " posts=posts- $thread->replies -1 " );
update_forum_timestamp ( $forum );
return true ;
2007-11-12 20:57:15 +00:00
}
function unhide_thread ( $thread , $forum ) {
2008-07-01 16:34:51 +00:00
$ret = $thread -> update ( " hidden=0 " );
if ( ! $ret ) return $ret ;
$forum -> update ( " threads=threads+1, posts=posts+ $thread->replies +1 " );
update_forum_timestamp ( $forum );
2011-02-14 21:01:37 +00:00
return true ;
2007-11-12 20:57:15 +00:00
}
function move_thread ( $thread , $old_forum , $new_forum ) {
$now = time ();
$old_forum -> update ( " threads=threads-1, posts=posts- $thread->replies -1 " );
$new_forum -> update ( " threads=threads+1, posts=posts+ $thread->replies +1, timestamp= $now " );
return $thread -> update ( " forum= $new_forum->id " );
}
// $show_hidden: 1 if it is a moderator reading
// Error page if this function returns NULL.
// $forumID - int
// $min - int
// $nRec - int
// $sort_style - string (checked by switch statement)
// $show_hidden - bool (not directly passed to SQL)
// $sticky - bool (not directly passed to SQL)
//
function get_forum_threads (
$forumID , $start =- 1 , $nRec =- 1 , $sort_style = MODIFIED_NEW ,
$show_hidden = 0 , $sticky = 1
) {
//if (! (is_numeric($forumID) && is_numeric($min) && is_numeric($nRec))) {
// return NULL; // Something is wrong here.
//}
$sql = 'forum = ' . $forumID ;
if ( $sticky ){
$stickysql = " sticky DESC, " ;
}
if ( ! $show_hidden ) {
$sql .= ' AND hidden = 0' ;
}
switch ( $sort_style ) {
case MODIFIED_NEW :
$sql .= ' ORDER BY ' . $stickysql . 'timestamp DESC' ;
break ;
case MODIFIED_OLD :
$sql .= ' ORDER BY ' . $stickysql . 'timestamp ASC' ;
break ;
case VIEWS_MOST :
$sql .= ' ORDER BY ' . $stickysql . 'views DESC' ;
break ;
case REPLIES_MOST :
$sql .= ' ORDER BY ' . $stickysql . 'replies DESC' ;
break ;
case CREATE_TIME_NEW :
$sql .= ' ORDER by ' . $stickysql . 'create_time desc' ;
break ;
case CREATE_TIME_OLD :
$sql .= ' ORDER by ' . $stickysql . 'create_time asc' ;
break ;
case 'sufferers' :
$sql .= ' ORDER by ' . $stickysql . 'sufferers desc' ;
break ;
case 'activity' :
$sql .= ' ORDER by ' . $stickysql . 'activity desc' ;
break ;
case 'score' :
$sql .= ' ORDER by ' . $stickysql . 'score desc' ;
break ;
default :
$sql .= ' ORDER BY ' . $stickysql . 'timestamp DESC' ;
break ;
}
if ( $start > - 1 ) {
$sql .= ' LIMIT ' . $start ;
if ( $nRec > - 1 ) {
$sql .= ', ' . $nRec ;
}
} else if ( $nRec > - 1 ) {
$sql .= ' LIMIT ' . $nRec ;
}
return BoincThread :: enum ( $sql );
}
// $show_hidden = true when it is a moderator reading
// error_page if this function returns NULL.
// $sort_style - string (checked by switch statement)
// $show_hidden - bool (not directly passed to SQL)
//
2007-11-15 22:51:05 +00:00
function get_thread_posts ( $threadid , $sort_style , $show_hidden ) {
2007-11-12 20:57:15 +00:00
$sql = " thread= $threadid " ;
if ( ! $show_hidden ) {
$sql .= ' AND hidden = 0' ;
}
switch ( $sort_style ) {
case CREATE_TIME_NEW :
$sql .= ' ORDER BY timestamp desc' ;
break ;
case CREATE_TIME_OLD :
$sql .= ' ORDER BY timestamp asc' ;
break ;
case POST_SCORE :
$sql .= ' ORDER BY score DESC' ;
break ;
default :
$sql .= ' ORDER BY timestamp asc' ;
2010-12-21 17:15:57 +00:00
break ;
2007-11-12 20:57:15 +00:00
}
return BoincPost :: enum ( $sql );
}
2014-04-17 05:54:17 +00:00
// Show links for post moderation actions;
// logged in user has moderation rights.
2007-11-12 20:57:15 +00:00
//
2007-11-15 22:51:05 +00:00
function show_post_moderation_links (
$config , $logged_in_user , $post , $forum , $tokens
2007-11-12 20:57:15 +00:00
){
2007-11-15 22:51:05 +00:00
$moderators_allowed_to_ban = parse_bool ( $config , " moderators_allowed_to_ban " );
$moderators_vote_to_ban = parse_bool ( $config , " moderators_vote_to_ban " );
if ( $post -> hidden ) {
2011-12-24 15:37:20 +00:00
show_button ( " forum_moderate_post_action.php?action=unhide&id= " . $post -> id . " $tokens " , tra ( " Unhide " ), tra ( " Unhide this post " ));
2007-11-15 22:51:05 +00:00
} else {
2011-12-24 15:37:20 +00:00
show_button ( " forum_moderate_post.php?action=hide&id= " . $post -> id . " $tokens " , tra ( " Hide " ), tra ( " Hide this post " ));
2007-11-12 20:57:15 +00:00
}
2007-11-15 22:51:05 +00:00
2011-02-10 22:45:39 +00:00
show_button (
2011-08-29 05:37:52 +00:00
" forum_moderate_post.php?action=move&id= " . $post -> id . " $tokens " ,
2011-12-24 15:37:20 +00:00
tra ( " Move " ), tra ( " Move post to a different thread " )
2007-11-15 22:51:05 +00:00
);
if ( $forum -> parent_type == 0 ) {
2014-04-17 05:54:17 +00:00
if ( is_admin ( $logged_in_user ) || $moderators_allowed_to_ban ) {
2011-12-24 15:37:20 +00:00
show_button ( " forum_moderate_post.php?action=banish_user&id= " . $post -> id . " &userid= " . $post -> user . " $tokens " , tra ( " Banish author " ));
2007-11-15 22:51:05 +00:00
}
2014-04-17 05:54:17 +00:00
if ( $moderators_vote_to_ban ) {
2007-11-15 22:51:05 +00:00
require_once ( " ../inc/forum_banishment_vote.inc " );
if ( vote_is_in_progress ( $post -> user )) {
2011-07-26 15:13:10 +00:00
show_button (
2011-08-29 05:37:52 +00:00
" forum_banishment_vote.php?action=yes&userid= " . $post -> user ,
2011-12-24 15:37:20 +00:00
tra ( " Vote to banish author " )
2011-07-26 15:13:10 +00:00
);
show_button (
2011-08-29 05:37:52 +00:00
" forum_banishment_vote.php?action=no&userid= " . $post -> user ,
2011-12-24 15:37:20 +00:00
tra ( " Vote not to banish author " )
2011-07-26 15:13:10 +00:00
);
2007-11-15 22:51:05 +00:00
} else {
2011-07-26 15:13:10 +00:00
show_button (
2011-08-29 05:37:52 +00:00
" forum_banishment_vote.php?action=start&userid= " . $post -> user ,
2011-12-24 15:37:20 +00:00
tra ( " Start vote to banish author " )
2011-07-26 15:13:10 +00:00
);
2007-11-15 22:51:05 +00:00
}
}
2014-04-17 05:54:17 +00:00
if ( is_admin ( $logged_in_user )) {
show_button ( " forum_moderate_post.php?action=delete&id= " . $post -> id . " $tokens " , tra ( " Delete " ), tra ( " Delete this post " ));
}
2007-11-12 20:57:15 +00:00
}
2007-11-15 22:51:05 +00:00
}
2014-04-17 05:54:17 +00:00
// is the given user allowed to
// - add threads to News forum
// - use HTML in posts
// - delete threads and posts
2014-03-14 07:20:07 +00:00
//
function is_admin ( $user ) {
2014-03-15 22:33:38 +00:00
if ( ! $user ) return false ;
if ( $user -> prefs -> privilege ( S_SCIENTIST )) return true ;
if ( $user -> prefs -> privilege ( S_DEV )) return true ;
if ( $user -> prefs -> privilege ( S_ADMIN )) return true ;
return false ;
2014-03-14 07:20:07 +00:00
}
2009-12-16 22:35:08 +00:00
function user_can_create_thread ( $user , $forum ) {
if ( ! $user ) return false ;
2014-03-14 07:20:07 +00:00
if ( $forum -> is_dev_blog && ! is_admin ( $user )) {
return false ;
2007-11-12 20:57:15 +00:00
}
2009-12-16 22:35:08 +00:00
return true ;
2007-11-15 22:51:05 +00:00
}
function check_post_access ( $user , $forum ) {
switch ( $forum -> parent_type ) {
case 0 :
if ( $user -> prefs -> privilege ( S_MODERATOR )) return ;
2007-11-12 20:57:15 +00:00
break ;
2007-11-15 22:51:05 +00:00
case 1 :
$team = BoincTeam :: lookup_id ( $forum -> category );
if ( is_team_admin ( $user , $team )) return ;
// non-team-members can't post
//
if ( $user -> teamid != $team -> id ) {
2011-12-24 15:37:20 +00:00
error_page ( tra ( " Only team members can post to the team message board " ));
2007-11-15 22:51:05 +00:00
}
2007-11-12 20:57:15 +00:00
break ;
}
2007-11-15 22:51:05 +00:00
// If user haven't got enough credit (according to forum regulations)
// We do not tell the (ab)user how much this is -
// no need to make it easy for them to break the system.
//
if ( $user -> total_credit < $forum -> post_min_total_credit || $user -> expavg_credit < $forum -> post_min_expavg_credit ) {
error_page ( tra ( " In order to create a new thread in %1 you must have a certain amount of credit. This is to prevent and protect against abuse of the system. " , $forum -> title ));
2007-11-12 20:57:15 +00:00
}
2007-11-15 22:51:05 +00:00
// If the user is posting faster than forum regulations allow
// Tell the user to wait a while before creating any more posts
//
2007-12-19 21:28:58 +00:00
if ( time () - $user -> prefs -> last_post < $forum -> post_min_interval ) {
2007-11-15 22:51:05 +00:00
error_page ( tra ( " You cannot create any more threads right now. Please wait a while before trying again. This delay has been enforced to protect against abuse of the system. " ));
2007-11-12 20:57:15 +00:00
}
}
2007-11-15 22:51:05 +00:00
function check_reply_access ( $user , $forum , $thread ) {
if ( $thread -> locked && ! is_moderator ( $user , $forum )) {
error_page (
2011-12-24 15:37:20 +00:00
tra ( " This thread is locked. Only forum moderators and administrators are allowed to post there. " )
2007-11-15 22:51:05 +00:00
);
2007-11-12 20:57:15 +00:00
}
2007-11-15 22:51:05 +00:00
if ( $thread -> hidden ) {
error_page (
2011-12-24 15:37:20 +00:00
tra ( " Can't post to a hidden thread. " )
2007-11-15 22:51:05 +00:00
);
2007-11-12 20:57:15 +00:00
}
2007-11-15 22:51:05 +00:00
check_post_access ( $user , $forum );
}
2014-04-17 05:54:17 +00:00
// is the given user allowed to moderate the given forum? this includes
// - post to locked threads
// - see hidden threads and posts
// - edit their posts at any time
// - hide/unhide/move threads and posts
2007-11-15 22:51:05 +00:00
function is_moderator ( $user , $forum ) {
if ( ! $user ) return false ;
2010-04-29 15:28:27 +00:00
$type = $forum ? $forum -> parent_type : 0 ;
switch ( $type ) {
2007-11-15 22:51:05 +00:00
case 0 :
if ( $user -> prefs -> privilege ( S_MODERATOR )) return true ;
if ( $user -> prefs -> privilege ( S_ADMIN )) return true ;
if ( $user -> prefs -> privilege ( S_DEV )) return true ;
2010-04-09 20:27:42 +00:00
if ( $user -> prefs -> privilege ( S_SCIENTIST )) return true ;
2007-11-15 22:51:05 +00:00
break ;
case 1 :
2007-11-18 04:10:37 +00:00
if ( $user -> prefs -> privilege ( S_ADMIN )) return true ;
2007-11-15 22:51:05 +00:00
$team = BoincTeam :: lookup_id ( $forum -> category );
return is_team_admin ( $user , $team );
break ;
2006-12-29 20:57:29 +00:00
}
2007-11-15 22:51:05 +00:00
return false ;
2006-12-29 20:57:29 +00:00
}
2007-11-22 04:13:59 +00:00
function show_thread_and_context_header () {
2011-08-25 05:08:47 +00:00
start_forum_table ( array (
tra ( " Thread " ),
tra ( " Posts " ),
tra ( " Author " ),
tra ( " Views " ),
" <nobr> " . tra ( " Last post " ) . " </nobr> "
));
2007-11-22 04:13:59 +00:00
}
// show a 1-line summary of thread and its forum.
// Used for search results and subscription list
//
2008-08-07 20:43:52 +00:00
function show_thread_and_context ( $thread , $user , $i ) {
2007-11-22 04:13:59 +00:00
$thread_forum = BoincForum :: lookup_id ( $thread -> forum );
2007-11-25 04:47:54 +00:00
if ( ! $thread_forum ) return ;
if ( ! is_forum_visible_to_user ( $thread_forum , $user )) return ;
2007-11-22 04:13:59 +00:00
$owner = BoincUser :: lookup_id ( $thread -> owner );
2008-08-07 20:43:52 +00:00
$j = $i % 2 ;
echo " <tr class=row $j ><td> \n " ;
2007-11-22 04:13:59 +00:00
switch ( $thread_forum -> parent_type ) {
case 0 :
$category = BoincCategory :: lookup_id ( $thread_forum -> category );
show_forum_title ( $category , $thread_forum , $thread , true );
break ;
case 1 :
show_team_forum_title ( $thread_forum , $thread );
break ;
}
echo '
2010-11-03 21:48:39 +00:00
</ td >< td class = " numbers " > '.($thread->replies+1).' </ td >
2008-08-12 17:08:14 +00:00
< td > '.user_links($owner).' </ td >
2010-11-03 21:48:39 +00:00
< td class = " numbers " > '.$thread->views.' </ td >
< td class = " lastpost " > '.time_diff_str($thread->timestamp, time()).' </ td >
2007-11-22 04:13:59 +00:00
</ tr >
' ;
}
// see if thread is in subscription list
//
function is_subscribed ( $thread , $subs ) {
foreach ( $subs as $sub ) {
if ( $sub -> threadid == $thread -> id ) return true ;
}
return false ;
}
2007-11-25 04:47:54 +00:00
function is_forum_visible_to_user ( $forum , $user ) {
if ( $forum -> parent_type == 1 ) {
if ( parse_config ( get_config (), " <team_forums_members_only> " )) {
if ( ! $user ) return false ;
if ( $user -> teamid != $forum -> category ) return false ;
}
}
return true ;
}
2007-12-30 22:02:16 +00:00
function subscribed_post_email_line ( $notify ) {
$thread = BoincThread :: lookup_id ( $notify -> opaque );
return " There are new posts in the thread ' $thread->title ' " ;
}
function subscribed_post_web_line ( $notify ) {
$thread = BoincThread :: lookup_id ( $notify -> opaque );
2011-12-24 15:37:20 +00:00
return tra ( " New posts in the thread %1 " , " <a href=forum_thread.php?id= $thread->id > $thread->title </a> " );
2007-12-30 22:02:16 +00:00
}
2008-01-04 22:59:21 +00:00
function subscribe_rss ( $notify , & $title , & $msg , & $url ) {
$thread = BoincThread :: lookup_id ( $notify -> opaque );
2011-12-24 15:37:20 +00:00
$title = tra ( " New posts in subscribed thread " );
$msg = tra ( " There are new posts in the thread '%1' " , $thread -> title );
2008-01-04 22:59:21 +00:00
$url = URL_BASE . " forum_thread.php?id= $thread->id " ;
}
2007-11-25 04:47:54 +00:00
2008-01-08 00:34:55 +00:00
function show_mark_as_read_button ( $user ) {
if ( $user ) {
$return = urlencode ( current_url ());
$tokens = url_tokens ( $user -> authenticator );
2011-08-29 05:37:52 +00:00
$url = " forum_index.php?read=1 $tokens &return= $return " ;
2011-09-23 17:18:33 +00:00
show_button ( $url ,
tra ( " Mark all threads as read " ),
tra ( " Mark all threads in all message boards as read. " )
);
2008-01-08 00:34:55 +00:00
}
}
2010-03-26 05:34:14 +00:00
function remove_subscriptions_forum ( $userid , $forumid ) {
$subs = BoincSubscription :: enum ( " userid= $userid " );
foreach ( $subs as $sub ) {
$thread = BoincThread :: lookup_id ( $sub -> threadid );
if ( $thread && $thread -> forum == $forumid ) {
BoincSubscription :: delete ( $userid , $thread -> id );
}
}
2010-03-28 23:47:17 +00:00
$notices = BoincNotify :: enum ( " userid= $userid and type= " . NOTIFY_SUBSCRIBED_POST );
foreach ( $notices as $n ) {
$thread = BoincThread :: lookup_id ( $n -> opaque );
if ( $thread && $thread -> forum == $forumid ) {
$n -> delete ();
}
}
2010-03-26 05:34:14 +00:00
}
function remove_subscriptions_thread ( $userid , $threadid ) {
BoincSubscription :: delete ( $userid , $threadid );
2010-03-28 23:47:17 +00:00
BoincNotify :: delete_aux ( " userid= $userid and type= " . NOTIFY_SUBSCRIBED_POST . " and opaque= $threadid " );
2010-03-26 05:34:14 +00:00
}
2013-05-13 19:29:07 +00:00
function parse_forum_cookie () {
$x = array ( " " , " " );
if ( isset ( $_COOKIE [ 'sorting' ])) {
$a = explode ( " | " , $_COOKIE [ 'sorting' ]);
if ( array_key_exists ( 0 , $a )) {
$x [ 0 ] = $a [ 0 ];
}
if ( array_key_exists ( 1 , $a )) {
$x [ 1 ] = $a [ 1 ];
}
}
return $x ;
}
2004-02-02 23:34:39 +00:00
?>