2004-02-02 23:34:39 +00:00
< ? php
2005-01-12 13:39:05 +00:00
$cvs_version_tracker [] = " \$ Id $ " ; //Generated automatically - do not edit
2004-02-02 23:34:39 +00:00
require_once ( '../inc/db.inc' );
require_once ( '../inc/sanitize_html.inc' );
2004-05-24 03:40:38 +00:00
require_once ( '../inc/time.inc' );
2004-02-02 23:34:39 +00:00
2004-09-04 23:37:49 +00:00
define ( 'AVATAR_WIDTH' , 100 );
define ( 'AVATAR_HEIGHT' , 100 );
define ( 'ST_ADMIN' , 'Project administrator' );
define ( 'ST_MODERATOR' , 'Forum moderator' );
2004-12-22 03:07:21 +00:00
define ( 'ST_DEV' , 'Project developer' );
define ( 'ST_TEST' , 'Project tester' );
2004-09-04 23:37:49 +00:00
define ( 'ST_VOLDEV' , 'Volunteer developer' );
2004-12-22 03:07:21 +00:00
define ( 'ST_VOLTEST' , 'Volunteer tester' );
2004-09-04 23:37:49 +00:00
define ( 'ST_SCIENT' , 'Project scientist' );
define ( 'ST_NEW_TIME' , 1209600 ); //3600*24*14 - 14 days
define ( 'ST_NEW' , 'New member' );
define ( 'FORUM_OPEN_LINK_IN_NEW_WINDOW' , 1 );
2004-09-05 19:26:27 +00:00
define ( 'MAX_FORUM_LOGGING_TIME' , 604800 ); //3600*24*7 - 7 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 " );
2004-10-10 03:04:29 +00:00
define ( 'NEW_IMAGE' , 'unread_post.png' );
define ( 'NEW_IMAGE_HEIGHT' , '15' );
2004-10-25 22:04:15 +00:00
define ( 'EMPHASIZE_IMAGE' , 'emphasized_post.png' );
define ( 'EMPHASIZE_IMAGE_HEIGHT' , '15' );
2004-12-18 18:13:46 +00:00
define ( 'FILTER_IMAGE' , 'filtered_post.png' );
define ( 'FILTER_IMAGE_HEIGHT' , '15' );
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 );
2004-02-02 23:34:39 +00:00
$forum_sort_styles [ 'modified-new' ] = " Most recent post first " ;
$forum_sort_styles [ 'modified-old' ] = " Least recent post first " ;
//$forum_sort_styles['activity-most'] = "Most recent activity first";
$forum_sort_styles [ 'views-most' ] = " Most views first " ;
$forum_sort_styles [ 'replies-most' ] = " Most posts first " ;
2004-09-04 23:37:49 +00:00
$thread_sort_styles [ 'timestamp' ] = " Newest first " ;
$thread_sort_styles [ 'timestamp_asc' ] = " Oldest first " ;
$thread_sort_styles [ 'score' ] = " Highest rated first " ;
2004-02-02 23:34:39 +00:00
$faq_sort_styles [ 'create_time' ] = " Most recent question first " ;
$faq_sort_styles [ 'timestamp' ] = " Most recent answer first " ;
2004-03-26 18:37:46 +00:00
$faq_sort_styles [ 'activity' ] = " Most frequently asked first " ;
2004-02-02 23:34:39 +00:00
$answer_sort_styles [ 'score' ] = " Highest score first " ;
$answer_sort_styles [ 'timestamp' ] = " Most recent first " ;
2004-09-04 23:37:49 +00:00
$answer_sort_styles [ 'timestamp_asc' ] = " Oldest first " ;
2004-02-02 23:34:39 +00:00
$thread_filter_styles [ '2' ] = " \" Very helpful \" " ;
$thread_filter_styles [ '1' ] = " At least \" helpful \" " ;
$thread_filter_styles [ '0' ] = " At least \" neutral \" " ;
$thread_filter_styles [ '-1' ] = " At least \" unhelpful \" " ;
$thread_filter_styles [ '-2' ] = " All posts " ;
$post_ratings [ '2' ] = " Very helpful (+2) " ;
$post_ratings [ '1' ] = " Helpful (+1) " ;
$post_ratings [ '0' ] = " Neutral " ;
2004-12-28 05:25:44 +00:00
$post_ratings [ '-1' ] = " Not helpful (-1) " ;
2004-02-02 23:34:39 +00:00
$post_ratings [ '-2' ] = " Off topic (-2) " ;
2005-01-09 21:52:22 +00:00
// process a user-supplied title to remove HTML stuff
//
function cleanup_title ( $title ) {
$x = trim ( htmlspecialchars ( strip_tags ( $title )));
if ( strlen ( $x ) == 0 ) return " (no title) " ;
else return $x ;
}
2004-02-02 23:34:39 +00:00
function getCategories () {
$langID = ( ! empty ( $_SESSION [ 'lang' ][ 'id' ])) ? $_SESSION [ 'lang' ][ 'id' ] : 1 ;
$sql = " SELECT * FROM category WHERE lang = " . $langID . " AND is_helpdesk = 0 ORDER BY orderID ASC " ;
return mysql_query ( $sql );
}
function getHelpDeskCategories () {
$sql = " SELECT * FROM category WHERE is_helpdesk = 1 ORDER BY orderID ASC " ;
return mysql_query ( $sql );
}
function getForums ( $categoryID ) {
$sql = 'SELECT * FROM forum WHERE category = ' . $categoryID . ' ORDER BY orderID ASC' ;
return mysql_query ( $sql );
}
2005-01-14 01:54:52 +00:00
function getThreads ( $forumID , $min =- 1 , $nRec =- 1 , $sort_style = 'modified-new' , $filteron = 1 ) {
/* Calling function: Set $filteron to 0 if it is a moderator reading */
2004-02-02 23:34:39 +00:00
$sql = 'SELECT * FROM thread WHERE forum = ' . $forumID ;
2005-01-14 01:54:52 +00:00
if ( $filteron ) {
$sql .= ' AND hidden = 0' ;
}
2004-02-02 23:34:39 +00:00
switch ( $sort_style ) {
case 'modified-new' :
$sql .= ' ORDER BY timestamp DESC' ;
break ;
case 'modified-old' :
$sql .= ' ORDER BY timestamp ASC' ;
break ;
case 'views-most' :
$sql .= ' ORDER BY views DESC' ;
break ;
case 'replies-most' :
$sql .= ' ORDER BY replies DESC' ;
break ;
case 'create_time' :
$sql .= ' ORDER by create_time desc' ;
break ;
case 'timestamp' :
$sql .= ' ORDER by timestamp desc' ;
break ;
case 'sufferers' :
$sql .= ' ORDER by sufferers desc' ;
break ;
case 'activity' :
$sql .= ' ORDER by activity desc' ;
break ;
case 'score' :
$sql .= ' ORDER by score desc' ;
break ;
}
if ( $min > - 1 ) {
$sql .= ' LIMIT ' . $min ;
if ( $nRec > - 1 ) {
$sql .= ', ' . $nRec ;
}
} else if ( $nRec > - 1 ) {
$sql .= ' LIMIT ' . $nRec ;
}
return mysql_query ( $sql );
}
2005-01-14 01:54:52 +00:00
function getPosts ( $threadID , $min = - 1 , $nRec = - 1 , $sort_style = " timestamp " , $filteron = 1 ) {
/* Calling function: Set $filteron = 0 when it is a moderator reading */
2004-02-02 23:34:39 +00:00
$sql = 'SELECT * FROM post WHERE thread = ' . $threadID ;
2005-01-14 02:51:26 +00:00
if ( $filteron ) {
2005-01-14 01:54:52 +00:00
$sql .= ' AND hidden = 0' ;
}
2004-02-02 23:34:39 +00:00
switch ( $sort_style ) {
case 'timestamp' :
2005-01-14 01:54:52 +00:00
$sql .= ' ORDER BY timestamp desc' ;
2004-02-02 23:34:39 +00:00
break ;
case 'timestamp_asc' :
2005-01-14 01:54:52 +00:00
$sql .= ' ORDER BY timestamp asc' ;
2004-02-02 23:34:39 +00:00
break ;
case 'score' :
2005-01-14 01:54:52 +00:00
$sql .= ' ORDER BY score DESC' ;
2004-02-02 23:34:39 +00:00
break ;
}
if ( $min > - 1 ) {
$sql .= ' LIMIT ' . $min ;
if ( $nRec > - 1 ) {
$sql .= ', ' . $nRec ;
}
} elseif ( $nRec > - 1 ) {
$sql .= ' LIMIT ' . $nRec ;
}
return mysql_query ( $sql );
}
/* specific database functions */
function getCategory ( $categoryID ) {
$sql = " SELECT * FROM category WHERE id = " . $categoryID ;
$result = mysql_query ( $sql );
if ( $result ) {
return mysql_fetch_object ( $result );
} else {
return NULL ;
}
}
function getForum ( $forumID ) {
$sql = " SELECT * FROM forum WHERE id = " . $forumID ;
$result = mysql_query ( $sql );
if ( $result ) {
return mysql_fetch_object ( $result );
} else {
return NULL ;
}
}
function getThread ( $threadID ) {
$sql = " SELECT * FROM thread WHERE id = " . $threadID ;
$result = mysql_query ( $sql );
if ( $result ) {
return mysql_fetch_object ( $result );
} else {
return NULL ;
}
}
function getPost ( $postID ) {
$sql = " SELECT * FROM post WHERE id = " . $postID ;
$result = mysql_query ( $sql );
if ( $result ) {
return mysql_fetch_object ( $result );
} else {
return NULL ;
}
}
// Returns the post that started the thread with id = $threadId
function getFirstPost ( $threadID ) {
$sql = " SELECT * FROM post WHERE thread = " . $threadID . " ORDER BY id ASC limit 1 " ;
$result = mysql_query ( $sql );
if ( $result ) {
return mysql_fetch_object ( $result );
} else {
return NULL ;
}
}
2004-09-04 23:37:49 +00:00
function getForumPreferences ( $user ){
$sql = " SELECT * FROM forum_preferences WHERE userid = ' " . $user -> id . " ' " ;
$result = mysql_query ( $sql );
if ( mysql_num_rows ( $result ) > 0 ) {
$prefs = mysql_fetch_object ( $result );
2004-10-10 03:04:29 +00:00
//Todo - find out how to simply merge two objects instead of specifying all the fields manually here
$user -> avatar = $prefs -> avatar ;
$user -> hide_avatars = $prefs -> hide_avatars ;
$user -> sorting = $prefs -> sorting ;
$user -> images_as_links = $prefs -> images_as_links ;
$user -> signature = $prefs -> signature ;
$user -> posts = $prefs -> posts ;
$user -> avatar_type = $prefs -> avatar_type ;
$user -> no_signature_by_default = $prefs -> no_signature_by_default ;
$user -> link_popup = $prefs -> link_popup ;
$user -> mark_as_read_timestamp = $prefs -> mark_as_read_timestamp ;
$user -> special_user = $prefs -> special_user ;
$user -> jump_to_unread = $prefs -> jump_to_unread ;
$user -> hide_signatures = $prefs -> hide_signatures ;
2004-10-25 22:04:15 +00:00
$user -> rated_posts = $prefs -> rated_posts ;
2005-01-09 21:52:22 +00:00
$user -> low_rating_threshold = $prefs -> low_rating_threshold ;
$user -> high_rating_threshold = $prefs -> high_rating_threshold ;
2005-01-06 11:47:44 +00:00
$user -> ignorelist = $prefs -> ignorelist ;
2004-10-10 03:04:29 +00:00
$user -> forum_preferences = 1 ;
2005-01-09 21:52:22 +00:00
//Set defaults in certain cases:
if ( $user -> low_rating_threshold == 0 and $user -> high_rating_threshold == 0 ){
$user -> low_rating_threshold = DEFAULT_LOW_RATING_THRESHOLD ;
$user -> high_rating_threshold = DEFAULT_HIGH_RATING_THRESHOLD ;
}
2004-09-04 23:37:49 +00:00
} else {
mysql_query ( " insert into forum_preferences set userid=' " . $user -> id . " ' " );
2004-10-10 03:04:29 +00:00
$user -> forum_preferences = 0 ;
2004-09-04 23:37:49 +00:00
}
return $user ;
}
2004-10-25 22:04:15 +00:00
function getHasRated ( $user , $postid ){
return ( strstr ( $user -> rated_posts , " | " . $postid ));
}
function setHasRated ( $user , $postid ){
mysql_query ( " UPDATE forum_preferences SET rated_posts = concat('| $postid ',rated_posts) WHERE userid = ' " . $user -> id . " ' " );
return mysql_error ();
}
2004-09-04 23:37:49 +00:00
function getSortStyle ( $user , $place ){
2004-09-05 19:26:27 +00:00
if ( $user -> id != " " ){
2004-10-10 03:04:29 +00:00
list ( $forum , $thread , $faq , $answer ) = explode ( " | " , $user -> sorting );
2004-09-05 19:26:27 +00:00
} else {
list ( $forum , $thread , $faq , $answer ) = explode ( " | " , $_COOKIE [ 'sorting' ]);
}
2004-09-04 23:37:49 +00:00
return $$place ;
}
function setSortStyle ( $user , $place , $new_style ){
2004-09-05 19:26:27 +00:00
if ( $user -> id != " " ){
2004-10-10 03:04:29 +00:00
list ( $forum , $thread , $faq , $answer ) = explode ( " | " , $user -> sorting );
$$place = $new_style ;
$user -> sorting = implode ( " | " , array ( $forum , $thread , $faq , $answer ));
$sql = " UPDATE forum_preferences SET sorting = ' " . $user -> sorting . " ' where userid = ' " . $user -> id . " ' " ;
mysql_query ( $sql );
2004-09-05 19:26:27 +00:00
} else {
list ( $forum , $thread , $faq , $answer ) = explode ( " | " , $_COOKIE [ 'sorting' ]);
2004-10-10 03:04:29 +00:00
$$place = $new_style ;
2004-09-05 19:26:27 +00:00
setcookie ( 'sorting' , implode ( " | " , array ( $forum , $thread , $faq , $answer )), time () + 3600 * 24 * 365 );
2005-01-09 21:52:22 +00:00
}
2004-09-04 23:37:49 +00:00
}
function getThreadLastVisited ( $user , $thread ){
2004-10-10 03:04:29 +00:00
if ( $user -> id == " " ){ //Disable read/unread stuff for users that are not logged in
$user -> thread_last_visited = time (); //Always display as visited
return $user ;
2004-09-05 19:26:27 +00:00
}
2004-09-04 23:37:49 +00:00
$sql = " SELECT timestamp from forum_logging where userid=' " . $user -> id . " ' and threadid=' " . $thread -> id . " ' " ;
$result = mysql_query ( $sql );
if ( $result ) {
2004-10-10 03:04:29 +00:00
$data = mysql_fetch_object ( $result );
$user -> thread_last_visited = $data -> timestamp ;
2004-09-04 23:37:49 +00:00
} else {
}
$user -> thread_last_visited = max ( time () - MAX_FORUM_LOGGING_TIME , $user -> thread_last_visited , $user -> mark_as_read_timestamp );
//echo $user->thread_last_visited." - ".time();
return $user ;
}
function setThreadLastVisited ( $user , $thread , $timestamp = " " ){
if ( $timestamp == " " ){ $timestamp = time ();};
$sql = " REPLACE DELAYED into forum_logging set userid=' " . $user -> id . " ', threadid=' " . $thread -> id . " ', timestamp=' $timestamp ' " ;
mysql_query ( $sql );
}
2004-02-02 23:34:39 +00:00
function incThreadViews ( $threadID ) {
$sql = " UPDATE thread SET views = views + 1 WHERE id = " . $threadID . " LIMIT 1 " ;
mysql_query ( $sql );
}
2004-09-04 23:37:49 +00:00
function cleanup_forum_log (){
$sql = " SELECT timestamp FROM forum_logging where userid=0 and threadid=0 " ;
$result = mysql_query ( $sql );
if ( mysql_num_rows ( $result ) > 0 ) {
2004-10-10 03:04:29 +00:00
$data = mysql_fetch_object ( $result );
if ( $data -> timestamp < time () - MAX_FORUM_LOGGING_TIME ){
$sql = " DELETE FROM forum_logging where timestamp<' " . ( time () - MAX_FORUM_LOGGING_TIME ) . " ' and userid != 0 " ;
mysql_query ( $sql );
echo mysql_error ();
$sql = " REPLACE INTO forum_logging set userid=0, threadid=0, timestamp=' " . time () . " ' " ;
mysql_query ( $sql );
}
2004-09-04 23:37:49 +00:00
} else {
2004-10-10 03:04:29 +00:00
//No cleanup timestamp found, make one:
$sql = " INSERT INTO forum_logging set userid=0, threadid=0, timestamp=0 " ;
mysql_query ( $sql );
echo mysql_error ();
2004-09-04 23:37:49 +00:00
}
}
2004-02-02 23:34:39 +00:00
/* Forum modifying functions. */
2004-10-10 03:04:29 +00:00
function createThread ( $forumID , $ownerID , $title , $content , $add_signature = false ) {
2004-02-02 23:34:39 +00:00
$title = addslashes ( sanitize_html ( $title ));
2004-10-10 03:04:29 +00:00
$content = addslashes ( sanitize_html ( stripslashes ( $content )));
2004-02-02 23:34:39 +00:00
2005-01-09 21:52:22 +00:00
$title = strip_tags ( trim ( $title ));
if ( strlen ( $title ) == 0 ) {
echo " empty title \n " ;
2004-05-30 21:47:11 +00:00
return 0 ;
}
$sql = " insert into thread (forum, owner, title, create_time, timestamp) VALUES ( " . $forumID . " , " . $ownerID . " , ' " . $title . " ', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()) " ;
2004-02-02 23:34:39 +00:00
$result = mysql_query ( $sql );
if ( ! $result ) return false ;
$threadID = mysql_insert_id ();
2005-01-09 09:33:06 +00:00
addPost ( $threadID , $ownerID , NULL , $content , $add_signature );
2004-02-02 23:34:39 +00:00
2004-09-04 23:37:49 +00:00
$sql = " UPDATE forum_preferences SET posts = posts + 1 WHERE userid = " . $ownerID . " LIMIT 1 " ;
2004-02-02 23:34:39 +00:00
mysql_query ( $sql );
$sql = " UPDATE forum SET threads = threads + 1, posts = posts + 1, timestamp = UNIX_TIMESTAMP() WHERE id = " . $forumID . " LIMIT 1 " ;
mysql_query ( $sql );
return $threadID ;
}
2004-10-10 03:04:29 +00:00
function replyToThread ( $threadID , $userID , $content , $parent_post = NULL , $add_signature = false ) {
2004-02-02 23:34:39 +00:00
$thread = getThread ( $threadID );
$content = addslashes ( sanitize_html ( stripslashes ( $content )));
2004-10-10 03:04:29 +00:00
addPost ( $threadID , $userID , $parent_post , $content , $add_signature );
2004-02-02 23:34:39 +00:00
2004-09-04 23:37:49 +00:00
$sql = " UPDATE forum_preferences SET posts = posts + 1 WHERE userid = " . $userID . " LIMIT 1 " ;
2004-02-02 23:34:39 +00:00
mysql_query ( $sql );
$sql = " UPDATE thread SET replies = replies + 1, timestamp = UNIX_TIMESTAMP() WHERE id = " . $threadID . " LIMIT 1 " ;
mysql_query ( $sql );
$sql = " UPDATE forum SET posts = posts + 1, timestamp = UNIX_TIMESTAMP() WHERE id = " . $thread -> forum . " LIMIT 1 " ;
mysql_query ( $sql );
}
2004-10-10 03:04:29 +00:00
function addPost ( $threadID , $userID , $parentID , $content , $add_signature = false ) {
if ( $add_signature ){ $sig = 1 ;} else { $sig = 0 ;};
2004-02-02 23:34:39 +00:00
if ( $parentID ) {
2004-10-10 03:04:29 +00:00
$sql = " INSERT INTO post (thread, user, timestamp, content, parent_post, signature) VALUES ( " . $threadID . " , " . $userID . " , UNIX_TIMESTAMP(), ' " . $content . " ', " . $parentID . " , " . $sig . " ) " ;
2004-02-02 23:34:39 +00:00
} else {
2004-10-10 03:04:29 +00:00
$sql = " INSERT INTO post (thread, user, timestamp, content, signature) VALUES ( " . $threadID . " , " . $userID . " , UNIX_TIMESTAMP(), ' " . $content . " ', " . $sig . " ) " ;
2004-02-02 23:34:39 +00:00
}
$result = mysql_query ( $sql );
if ( ! $result ) return false ;
return true ;
}
function updatePost ( $postID , $content ) {
$x = addslashes ( sanitize_html ( stripslashes ( $content )));
$sql = " UPDATE post SET content = \" $x\ " , modified = UNIX_TIMESTAMP () WHERE id = " . $postID ;
$result = mysql_query ( $sql );
if ( ! $result ) return false ;
return true ;
}
2004-03-26 22:56:45 +00:00
function updateThread ( $threadID , $title ) {
2004-06-13 17:58:18 +00:00
$title = addslashes ( sanitize_html ( stripslashes ( $title )));
$title = trim ( $title );
if ( strlen ( $title ) == 0 ) {
return false ;
}
$sql = " UPDATE thread SET title = \" $title\ " WHERE id = " . $threadID ;
2004-03-26 22:56:45 +00:00
$result = mysql_query ( $sql );
if ( ! $result ) return false ;
return true ;
2005-01-09 21:52:22 +00:00
}
2004-03-26 22:56:45 +00:00
2004-02-02 23:34:39 +00:00
/* display functions */
function show_posts ( $thread , $sort_style , $filter , $show_controls = true , $do_coloring = true , $is_helpdesk = false ) {
global $logged_in_user ;
$n = 1 ;
if ( $show_controls && ! $is_helpdesk ) {
$controls = FORUM_CONTROLS ;
} else if ( $show_controls && $is_helpdesk ) {
$controls = HELPDESK_CONTROLS ;
} else {
$controls = NO_CONTROLS ;
}
$posts = getPosts ( $thread -> id , - 1 , - 1 , $sort_style );
2004-09-04 23:37:49 +00:00
$logged_in_user = getThreadLastVisited ( $logged_in_user , $thread );
setThreadLastVisited ( $logged_in_user , $thread );
2005-01-09 21:52:22 +00:00
2004-02-02 23:34:39 +00:00
$firstPost = getFirstPost ( $thread -> id );
if ( $is_helpdesk ) {
if ( $firstPost ) {
2005-01-07 18:27:06 +00:00
show_post ( $firstPost , $thread , $logged_in_user , $n , $controls , true , $filter );
2004-10-10 03:04:29 +00:00
if ( $firstPost -> timestamp > $logged_in_user -> thread_last_visited ){
$first_unread_post = $firstPost ;
}
2004-02-02 23:34:39 +00:00
}
}
while ( $post = mysql_fetch_object ( $posts )) {
2004-10-25 22:04:15 +00:00
if ( ! $is_helpdesk || ( $is_helpdesk && $post -> id != $firstPost -> id )) {
show_post ( $post , $thread , $logged_in_user , $n , $controls , false , $filter );
if ( $do_coloring ) $n = ( $n + 1 ) % 2 ;
if (( $post -> timestamp > $logged_in_user -> thread_last_visited ) && (( $post -> timestamp < $first_unread_post -> timestamp ) || $first_unread_post -> timestamp == 0 )){
$first_unread_post = $post ;
2004-02-02 23:34:39 +00:00
}
}
}
2005-01-09 21:52:22 +00:00
2004-10-10 03:04:29 +00:00
if ( $logged_in_user -> jump_to_unread ){
if ( $first_unread_post -> id != " " ){
echo " <script>function jumpToUnread() { location.href='# " . $first_unread_post -> id . " ';}</script> " ;
} else {
echo " <script>function jumpToUnread() { };</script> " ;
}
}
2004-02-02 23:34:39 +00:00
}
2004-10-25 22:04:15 +00:00
function show_post ( $post , $thread , $logged_in_user , $n , $controls = FORUM_CONTROLS , $separate = false , $filter = true ) {
2005-01-09 21:52:22 +00:00
global $post_ratings ; // <------ Old obsolete rating method (remove someday)
2004-02-02 23:34:39 +00:00
$user = lookup_user_id ( $post -> user );
2004-09-04 23:37:49 +00:00
$user = getForumPreferences ( $user );
2004-10-10 03:04:29 +00:00
$data = mysql_query ( " SELECT userid FROM profile WHERE userid = " . $user -> id ); //Lookup existance of profile for user
$user -> has_profile = ( mysql_numrows ( $data ) > 0 ); //and store this info in the user object
$user -> has_avatar = ( $user -> avatar != " " ); //for later access
2005-01-06 11:47:44 +00:00
//If the user that made this post is on the list of people to ignore, change thresholds to be more strict
if ( in_array ( $user -> id , explode ( " | " , $logged_in_user -> ignorelist ))){
2005-01-09 21:52:22 +00:00
$user_is_on_ignorelist = true ;
$rated_below_threshold = ( $logged_in_user -> high_rating_threshold > ( $post -> score * $post -> votes ));
$rated_above_threshold = ( $logged_in_user -> high_rating_threshold + abs ( $logged_in_user -> low_rating_threshold ) < ( $post -> score * $post -> votes ));
} else { //Use normal threshold values
2005-01-06 11:47:44 +00:00
$rated_below_threshold = ( $logged_in_user -> low_rating_threshold > ( $post -> score * $post -> votes ));
2005-01-09 21:52:22 +00:00
$rated_above_threshold = ( $logged_in_user -> high_rating_threshold < ( $post -> score * $post -> votes ));
2005-01-06 11:47:44 +00:00
}
2004-02-02 23:34:39 +00:00
$can_edit = $logged_in_user && $user -> id == $logged_in_user -> id ;
echo "
2004-09-04 23:37:49 +00:00
< tr class = \ " row $n\ " valign = \ " top \" >
2004-02-02 23:34:39 +00:00
< td >
2004-09-04 23:37:49 +00:00
< a name = \ " $post->id\ " ></ a >
2004-02-02 23:34:39 +00:00
" ;
2004-02-24 04:05:13 +00:00
echo user_links ( $user , URL_BASE );
2005-01-09 21:52:22 +00:00
2004-10-10 03:04:29 +00:00
if ( $user -> special_user ) { //If this user is somehow special
if ( $user -> special_user == 1 ) $fstatus = ST_ADMIN ; //this is displayed in the forums
if ( $user -> special_user == 2 ) $fstatus = ST_MODERATOR ; //so that people know who they are
if ( $user -> special_user == 3 ) $fstatus = ST_DEV ; //talking to.
if ( $user -> special_user == 4 ) $fstatus = ST_VOLDEV ;
if ( $user -> special_user == 5 ) $fstatus = ST_SCIENT ;
2004-12-22 01:12:10 +00:00
if ( $user -> special_user == 6 ) $fstatus = ST_TEST ;
2004-12-22 01:54:09 +00:00
if ( $user -> special_user == 7 ) $fstatus = ST_VOLTEST ;
2004-10-10 03:04:29 +00:00
/*...*/
2004-09-04 23:37:49 +00:00
} else {
2004-10-10 03:04:29 +00:00
if ( $user -> create_time > time () - ST_NEW_TIME ) $fstatus = ST_NEW ;
/*...*/
2004-09-04 23:37:49 +00:00
}
2004-12-18 18:13:46 +00:00
if ( $fstatus ) echo " <br><font size= \" -2 \" > $fstatus </font> " ;
2004-12-21 23:06:31 +00:00
echo " <br><font size= \" -2 \" > " , $user -> id , " </font> " ; // Try and circumvent various forms of
// of identity spoofing by displaying the
2005-01-09 21:52:22 +00:00
// user id of the poster, its cheep, easy,
2004-12-21 23:06:31 +00:00
// and doesn't require any additional database
// calls.
2004-10-25 22:04:15 +00:00
if ( ! $filter || ! $rated_below_threshold ){
2004-12-18 18:13:46 +00:00
echo " <p><font size= \" -2 \" > " ;
2005-01-09 21:52:22 +00:00
if ( $user -> has_avatar and $logged_in_user -> hide_avatars != 1 ) {
echo " <img width= \" " . AVATAR_WIDTH . " \" height= \" " . AVATAR_HEIGHT . " \" src= \" " . $user -> avatar . " \" alt= \" Avatar \" ><br> " ;
}
echo " Joined: " , gmdate ( 'M j, Y' , $user -> create_time ), " <br>Posts: " , $user -> posts , " </font></p> " ;
2004-10-25 22:04:15 +00:00
}
2004-09-04 23:37:49 +00:00
echo "
2004-02-02 23:34:39 +00:00
</ td >
< td >
" ;
if ( $controls == FORUM_CONTROLS || $controls == HELPDESK_CONTROLS ) {
2004-05-30 21:47:11 +00:00
echo " <form action= \" forum_rate.php?post= " , $post -> id , " \" method= \" post \" > " ;
2004-02-02 23:34:39 +00:00
}
2005-01-09 21:52:22 +00:00
2004-02-02 23:34:39 +00:00
echo "
2004-12-18 18:13:46 +00:00
< table width = \ " 100% \" cellpadding=0 cellspacing=0 border=0>
2004-05-30 21:47:11 +00:00
< tr valign = top >
2004-12-18 18:13:46 +00:00
< td align = left style = \ " border:0px \" ><font size=-2> " ; //cellborder=0 deleted - what did it do?
2004-09-04 23:37:49 +00:00
if ( $post -> timestamp > $logged_in_user -> thread_last_visited ){
2004-10-10 03:04:29 +00:00
echo " <img src= \" " . NEW_IMAGE . " \" alt= \" Unread post \" height= \" " . NEW_IMAGE_HEIGHT . " \" > " ;
2004-09-04 23:37:49 +00:00
}
2004-10-25 22:04:15 +00:00
if ( $rated_above_threshold ){
echo " <img src= \" " . EMPHASIZE_IMAGE . " \" alt= \" ! \" height= \" " . EMPHASIZE_IMAGE_HEIGHT . " \" > " ;
}
2005-01-09 21:52:22 +00:00
echo "
2004-02-02 23:34:39 +00:00
Posted : " , pretty_time_str( $post->timestamp );
;
2004-12-18 18:13:46 +00:00
if ( $post -> parent_post ) echo " - in response to <a href= \" # $post->parent_post\ " > Message ID $post -> parent_post </ a >. " ;
if ( $can_edit && $controls != NO_CONTROLS ) echo " <a href= \" forum_edit.php?id= $post->id\ " > [ Edit this post ] </ a > " ;
2004-02-02 23:34:39 +00:00
if ( $post -> modified ) echo " <br>Last modified: " , pretty_time_Str ( $post -> modified );
2004-10-25 22:04:15 +00:00
if ( $rated_below_threshold && $filter ){
2005-01-09 21:52:22 +00:00
if ( $user_is_on_ignorelist ) $andtext = " and the user is on your ignore list " ;
echo " <br>This post has been filtered (rating: " . ( $post -> score * $post -> votes ) . " ) $andtext , press <a href= \" ?id= " . $thread -> id . " &filter=false# " . $post -> id . " \" >here</a> to view this thread without filtering " ;
2004-10-25 22:04:15 +00:00
}
2005-01-09 21:52:22 +00:00
2004-12-18 18:13:46 +00:00
echo " \n </font></td> \n " ;
2004-02-02 23:34:39 +00:00
if ( $controls == FORUM_CONTROLS ) {
2005-01-09 21:52:22 +00:00
//no special controls in forum
2004-02-02 23:34:39 +00:00
} else if ( $controls == HELPDESK_CONTROLS && $separate ) {
echo "
< td align = \ " right \" style= \" border:0px \" >
2004-05-30 21:47:11 +00:00
< input type = submit name = submit value = \ " " , SUFFERER , " \" >
2004-02-02 23:34:39 +00:00
</ td >
" ;
} else if ( $controls == HELPDESK_CONTROLS && ! $separate ) {
echo "
< td align = \ " right \" style= \" border:0px \" >
< input type = \ " submit \" name= \" submit \" value= \" " , SOLUTION , " \" >
< input type = \ " submit \" name= \" submit \" value= \" " , OFF_TOPIC , " \" >
</ td >
" ;
}
echo " </tr> \n </table> \n " ;
if ( $controls == FORUM_CONTROLS || $controls == HELPDESK_CONTROLS ) {
echo " </form> " ;
}
2004-09-04 23:37:49 +00:00
2005-01-09 21:52:22 +00:00
//If either filtering is turned off of this post is not below the threshold
if ( ! $filter || ! $rated_below_threshold ){
2004-10-25 22:04:15 +00:00
$posttext = nl2br ( stripslashes ( $post -> content ));
if ( $post -> signature && ! $logged_in_user -> hide_signatures ){ //If the creator of this post has a signature and
$posttext .= nl2br ( " \n " . stripslashes ( $user -> signature )); //wants it to be shown for this post AND the logged in
} //user has signatures enabled: show it
2005-01-09 21:52:22 +00:00
2004-10-25 22:04:15 +00:00
if ( $logged_in_user -> images_as_links == 1 ){
$posttext = image_as_link ( $posttext );
}
if ( $logged_in_user -> link_popup == 1 ){
$posttext = externalize_links ( $posttext );
}
echo " <p> " , $posttext , " </p> " ;
2004-12-18 18:13:46 +00:00
echo " <table width= \" 100% \" cellspacing=0 cellpadding=0>
2004-10-25 22:04:15 +00:00
< tr valign = \ " bottom \" >
2004-12-18 18:13:46 +00:00
< td style = \ " border:0px; \" ><font size=-2><i>ID: " , $post -> id ;
2004-10-25 22:04:15 +00:00
if ( $controls == HELPDESK_CONTROLS && $separate ) {
2004-12-18 18:13:46 +00:00
echo " </i></font></td> " ;
2004-10-25 22:04:15 +00:00
} else if ( $controls == HELPDESK_CONTROLS && ! $separate ) {
2005-01-07 18:27:06 +00:00
echo " / Score: " , round (( $post -> score * $post -> votes ), 0 ), " </i></font></td> " ;
2004-10-25 22:04:15 +00:00
} else {
2005-01-06 18:48:07 +00:00
echo " / Rating: " , round ( intval (( $post -> score * $post -> votes ) + 0.01 ), 0 ), " </i> - rate: <a href= \" forum_rate.php?post= " . $post -> id . " &choice=p \" >+</a> / <a href= \" forum_rate.php?post= " . $post -> id . " &choice=n \" >-</a></font></td> " ;
2004-10-25 22:04:15 +00:00
}
2005-01-09 21:52:22 +00:00
2004-10-25 22:04:15 +00:00
if ( $controls == FORUM_CONTROLS ) {
2004-12-18 18:13:46 +00:00
echo " <td align= \" right \" style= \" border:0px \" >[<a href= \" forum_reply.php?thread= " . $thread -> id . " &post= " . $post -> id . " #input \" >Reply to this post</a>]</td> " ;
2004-10-25 22:04:15 +00:00
} else if ( $controls == HELPDESK_CONTROLS && ! $separate ) {
2004-12-18 18:13:46 +00:00
echo " <td align= \" right \" style= \" border:0px \" >[<a href= \" forum_reply.php?thread= " . $thread -> id . " &post= " . $post -> id . " &helpdesk=1#input \" >Reply to this answer</a>]</td> " ;
2004-10-25 22:04:15 +00:00
}
2005-01-09 21:52:22 +00:00
echo " </tr></table> " ;
2004-02-02 23:34:39 +00:00
}
2004-10-25 22:04:15 +00:00
echo " </td></tr> " ;
2004-02-02 23:34:39 +00:00
if ( $separate ) {
echo "
</ table >
< br >< br >
2004-05-30 21:47:11 +00:00
< table border = 0 cellpadding = 5 cellspacing = 0 width = 100 %>
2004-02-02 23:34:39 +00:00
< tr >
2004-05-30 21:47:11 +00:00
< th > Author </ th >
2004-02-02 23:34:39 +00:00
< th > Answers </ th >
" ;
}
}
/* utility functions */
2004-09-04 23:37:49 +00:00
function externalize_links ( $text ){
$i = 0 ; $linkpos = true ;
2004-10-10 03:04:29 +00:00
while ( true ){ //Find a link
2004-09-04 23:37:49 +00:00
$linkpos = strpos ( $text , " <a " , $i );
2004-10-10 03:04:29 +00:00
if ( $linkpos === false ) break ;
2004-10-12 18:05:38 +00:00
$out .= substr ( $text , $i , $linkpos - $i ) . " <a target= \" _new \" " ; //Replace with target='_new'
2004-10-10 03:04:29 +00:00
$i = $linkpos + 3 ;
2004-09-04 23:37:49 +00:00
}
$out .= substr ( $text , $i );
return $out ;
}
function image_as_link ( $text ){
/* This function depends on sanitized HTML - always use KSES or equivalent before using this */
$i = 0 ;
2004-10-10 03:04:29 +00:00
while ( true ){ //Find an image
$imgpos = strpos ( $text , " <img " , $i );
if ( $imgpos === false ) break ;
$out .= substr ( $text , $i , $imgpos - $i ) . " <a href= " ; //Replace with link start
$temp1 = strpos ( $text , " src= " , $imgpos ) + 5 ; //Find the image source
$temp2 = strpos ( $text , " > " , $imgpos ) + 1 ; //Or the end of the tag
if ( $temp1 < $temp2 ){ //If source was found within tag
$temp3 = strpos ( $text , " \" " , $temp1 ); //Find the end of source
$out .= substr ( $text , $temp1 , $temp3 - $temp1 ); //output the source
}
$out .= " >[Image link]</a> " ;
$i = $temp2 ; //Now move to end of tag to continue
}
$out .= substr ( $text , $i ); //Output the rest
2004-09-04 23:37:49 +00:00
return $out ;
}
2005-01-09 21:52:22 +00:00
2004-09-04 23:37:49 +00:00
2004-02-02 23:34:39 +00:00
function start_forum_table ( $headings , $span = NULL ) {
echo "
< p style = \ " text-align:center \" >
2004-12-18 18:13:46 +00:00
< table border = 0 cellpadding = 5 cellspacing = 0 width = \ " 100% \" >
2004-02-02 23:34:39 +00:00
< tr >
" ;
for ( $i = 0 ; $i < count ( $headings ); $i ++ ) {
$cell = " <th " ;
if ( $span ) {
$cell = $cell . " colspan= $span " ;
}
$cell = $cell . " > " ;
echo $cell , $headings [ $i ], " </th> \n " ;
}
echo " </tr> \n " ;
}
function end_forum_table () {
2004-12-18 18:13:46 +00:00
echo " </table> \n " ;
2004-02-02 23:34:39 +00:00
}
// generate a "select" element from an array of values
//
2004-09-04 23:37:49 +00:00
function select_from_array ( $name , $array , $selection ) {
$out = " <select name= \" $name\ " > " ;
2004-02-02 23:34:39 +00:00
foreach ( $array as $key => $value ) {
2004-09-04 23:37:49 +00:00
$out .= " <option " ;
2004-02-02 23:34:39 +00:00
if ( $key == $selection ) {
2004-09-04 23:37:49 +00:00
$out .= " selected " ;
2004-02-02 23:34:39 +00:00
}
2004-09-04 23:37:49 +00:00
$out .= " value= \" " . $key . " \" > " . $value . " </option> " ;
2004-02-02 23:34:39 +00:00
}
2004-09-04 23:37:49 +00:00
$out .= " </select> " ;
return $out ;
}
function show_select_from_array ( $name , $array , $selection ) {
echo select_from_array ( $name , $array , $selection );
2004-02-02 23:34:39 +00:00
}
function show_forum_title ( $forum = NULL , $thread = NULL , $helpdesk = false ) {
echo " <p> \n " ;
if ( ! $forum && ! $thread ) {
echo " <p class= \" title \" > " ;
if ( $helpdesk ) {
echo " Questions and problems</p> " ;
} else {
echo " Message boards</p> " ;
}
} else if ( $forum && ! $thread ) {
echo " <span class=title> " ;
if ( $helpdesk ) {
2004-12-18 18:13:46 +00:00
echo " <a href= \" forum_help_desk.php \" > " , " Questions and problems</a> : " ;
2004-02-02 23:34:39 +00:00
} else {
2004-12-18 18:13:46 +00:00
echo " <a href= \" forum_index.php \" > " , " Message boards</a> : " ;
2004-02-02 23:34:39 +00:00
}
echo $forum -> title ;
echo " </span><br> " ;
} else if ( $forum && $thread ) {
echo " <span class=title> " ;
if ( $helpdesk ) {
2004-12-18 18:13:46 +00:00
echo " <a href= \" forum_help_desk.php \" > " , " Questions and problems</a> : " ;
2004-02-02 23:34:39 +00:00
} else {
2004-12-18 18:13:46 +00:00
echo " <a href= \" forum_index.php \" > " , " Message boards</a> : " ;
2004-02-02 23:34:39 +00:00
}
2004-12-18 18:13:46 +00:00
echo " <a href= \" forum_forum.php?id= $forum->id\ " > " , $forum->title , " </ a > : " ;
2005-01-09 21:52:22 +00:00
echo cleanup_title ( $thread -> title );
2004-02-02 23:34:39 +00:00
echo " </span><br> " ;
} else {
echo " Invalid input to show_forum_title<br> " ;
}
echo " </p> \n " ;
}
// show a thread with its context (e.g. for search results)
//
function show_thread ( $thread , $n ) {
$forum = getForum ( $thread -> forum );
$category = getCategory ( $forum -> category );
$first_post = getFirstPost ( $thread -> id );
2005-01-09 21:52:22 +00:00
$title = cleanup_title ( $thread -> title );
2004-02-02 23:34:39 +00:00
$where = $category -> is_helpdesk ? " Questions and answers " : " Message boards " ;
2004-05-31 19:15:23 +00:00
$top_url = $category -> is_helpdesk ? " forum_help_desk.php " : " forum_index.php " ;
2004-02-02 23:34:39 +00:00
$excerpt = sub_sentence ( stripslashes ( $first_post -> content ), ' ' , EXCERPT_LENGTH , true );
$posted = time_diff_str ( $thread -> create_time , time ());
$last = time_diff_str ( $thread -> timestamp , time ());
$m = $n % 2 ;
echo "
2004-12-18 18:13:46 +00:00
< tr class = \ " row $m\ " >
< td >< font size = \ " -2 \" >
2004-02-02 23:34:39 +00:00
$n ) Posted $posted
< br >
Last response $last
</ td >
< td valign = top >
2004-12-18 18:13:46 +00:00
< a href = \ " $top_url\ " > $where </ a > : $category -> name :
< a href = \ " forum_forum.php?id= $forum->id\ " > $forum -> title </ a > :
< a href = \ " forum_thread.php?id= $thread->id\ " > $title </ a >
2004-02-02 23:34:39 +00:00
< br >
2004-12-18 18:13:46 +00:00
< font size = \ " -2 \" > $excerpt </font>
2004-02-02 23:34:39 +00:00
</ td >
</ tr >
" ;
}
// show a post with its context (e.g. for search results)
//
function show_post2 ( $post , $n ) {
$thread = getThread ( $post -> thread );
$forum = getForum ( $thread -> forum );
$category = getCategory ( $forum -> category );
$where = $category -> is_helpdesk ? " Questions and answers " : " Message boards " ;
2004-05-31 19:15:23 +00:00
$top_url = $category -> is_helpdesk ? " forum_help_desk.php " : " forum_index.php " ;
2004-02-02 23:34:39 +00:00
$content = nl2br ( stripslashes ( $post -> content ));
$when = time_diff_str ( $post -> timestamp , time ());
$user = lookup_user_id ( $post -> user );
2005-01-09 21:52:22 +00:00
$title = cleanup_title ( $thread -> title );
2004-02-02 23:34:39 +00:00
$m = $n % 2 ;
echo "
< tr class = row $m >
< td >
2004-12-18 18:13:46 +00:00
$n ) < a href = \ " $top_url\ " > $where </ a > : $category -> name :
< a href = \ " forum_forum.php?id= $forum->id\ " > $forum -> title </ a > :
< a href = \ " forum_thread.php?id= $thread->id\ " > $title </ a >
2004-02-02 23:34:39 +00:00
< br >
Posted $when by $user -> name
< hr >
$content
</ td >
</ tr >
" ;
}
2004-05-24 03:40:38 +00:00
function show_forum_summary ( $forum ) {
$x = time_diff_str ( $forum -> timestamp , time ());
echo "
2004-11-14 17:49:16 +00:00
< tr class = row1 style = \ " text-align:right \" >
2004-05-24 03:40:38 +00:00
< td class = indent style = \ " text-align:left \" >
2004-11-14 17:49:16 +00:00
< span style = \ " font-weight:bold \" >
2004-12-18 18:13:46 +00:00
< a href = \ " forum_forum.php?id= $forum->id\ " > " , $forum->title ,
2004-05-24 03:40:38 +00:00
" </a></span>
2004-11-14 17:49:16 +00:00
< br >< font size =- 2 > " , $forum->description , "
2004-05-24 03:40:38 +00:00
</ td >
< td > " , $forum->threads , " </ td >
< td > " , $forum->posts , " </ td >
< td > " , $x , " </ td >
</ tr >
" ;
}
2004-02-02 23:34:39 +00:00
?>