2005-02-02 03:01:29 +00:00
< ? php
/***************************************/
/* comment class and related functions */
/***************************************/
2006-09-01 02:27:31 +00:00
require_once ( BASE . " include/user.php " );
2005-02-02 03:01:29 +00:00
/**
* Comment class for handling comments
*/
class Comment {
var $iCommentId ;
2007-04-21 02:30:22 +00:00
// variables necessary for creating a comment
2005-02-02 03:01:29 +00:00
var $iParentId ;
var $sSubject ;
var $sBody ;
2007-04-21 02:30:22 +00:00
var $iVersionId ;
var $iAppId ;
2005-02-02 03:01:29 +00:00
var $sDateCreated ;
var $sHostname ;
var $oOwner ;
/**
* Constructor .
* If $iCommentId is provided , fetches comment .
*/
2007-09-08 22:38:20 +00:00
function Comment ( $iCommentId = null , $oRow = null )
2005-02-02 03:01:29 +00:00
{
2007-09-08 22:38:20 +00:00
if ( ! $iCommentId && ! $oRow )
return ;
if ( ! $oRow )
2005-02-02 03:01:29 +00:00
{
$sQuery = " SELECT appComments.*, appVersion.appId AS appId
FROM appComments , appVersion
WHERE appComments . versionId = appVersion . versionId
2006-06-27 19:16:27 +00:00
AND commentId = '?' " ;
$hResult = query_parameters ( $sQuery , $iCommentId );
2007-08-03 23:27:25 +00:00
$oRow = query_fetch_object ( $hResult );
2007-09-08 22:38:20 +00:00
}
if ( $oRow )
{
2005-02-02 03:01:29 +00:00
$this -> iCommentId = $oRow -> commentId ;
$this -> iParentId = $oRow -> parentId ;
$this -> iAppId = $oRow -> appId ;
$this -> iVersionId = $oRow -> versionId ;
$this -> sSubject = $oRow -> subject ;
$this -> sBody = $oRow -> body ;
$this -> sDateCreated = $oRow -> time ;
$this -> sHostname = $oRow -> hostname ;
$this -> oOwner = new User ( $oRow -> userId );
}
}
/*
* Creates a new comment .
* Informs interested people about the creation .
* Returns true on success , false on failure
*/
2007-04-21 18:05:32 +00:00
function create ()
2005-02-02 03:01:29 +00:00
{
2007-04-21 18:05:32 +00:00
$hResult = query_parameters ( " INSERT INTO appComments
( parentId , versionId , subject , " .
" body, userId, time, hostname)
VALUES ( '?' , '?' , '?' , '?' , '?' , ? , '?' ) " ,
$this -> iParentId , $this -> iVersionId ,
$this -> sSubject , $this -> sBody ,
2007-04-21 02:30:22 +00:00
$_SESSION [ 'current' ] -> iUserId ,
2006-06-24 04:20:32 +00:00
" NOW() " , get_remote ());
2005-02-02 03:01:29 +00:00
2006-06-24 04:20:32 +00:00
if ( $hResult )
2005-02-02 03:01:29 +00:00
{
2007-08-03 23:27:25 +00:00
$this -> comment ( query_appdb_insert_id ());
2006-06-29 15:54:29 +00:00
$sEmail = User :: get_notify_email_address_list ( $this -> iAppId , $this -> iVersionId );
2005-02-02 03:01:29 +00:00
$sEmail .= $this -> oOwner -> sEmail . " " ;
2005-08-24 01:36:12 +00:00
// fetches e-mails from parent comments, all parents are notified that a
// comment was added to the thread
2007-04-21 18:05:32 +00:00
$iParentId = $this -> iParentId ;
2005-02-02 03:01:29 +00:00
while ( $iParentId )
{
$oParent = new Comment ( $iParentId );
$sEmail .= $oParent -> oOwner -> sEmail . " " ;
$iParentId = $oParent -> iParentId ;
}
if ( $sEmail )
{
2005-08-24 01:36:12 +00:00
$aEmailArray = explode ( " " , $sEmail ); /* break the long email string into parts by spaces */
$aEmailArray = array_unique ( $aEmailArray ); /* remove duplicates */
/* build the single string of all emails up */
$sEmail = " " ;
foreach ( $aEmailArray as $key => $value )
{
$sEmail .= " $value " ;
}
2006-06-29 16:07:19 +00:00
$sSubject = " Comment for ' " . Application :: lookup_name ( $this -> iAppId ) . " " . Version :: lookup_name ( $this -> iVersionId ) . " ' added by " . $_SESSION [ 'current' ] -> sRealname ;
2006-04-28 00:53:01 +00:00
$sMsg = " To reply to this email please use the link provided below. \n " ;
$sMsg .= " DO NOT reply via your email client as it will not reach the person who wrote the comment \n " ;
2007-04-03 02:08:44 +00:00
$sMsg .= $this -> objectMakeUrl () . " \n " ;
2005-02-02 03:01:29 +00:00
$sMsg .= " \n " ;
$sMsg .= " Subject: " . $this -> sSubject . " \r \n " ;
$sMsg .= " \n " ;
$sMsg .= $this -> sBody . " \r \n " ;
mail_appdb ( $sEmail , $sSubject , $sMsg );
}
addmsg ( " Comment created. " , " green " );
return true ;
}
else
2006-06-24 04:20:32 +00:00
{
addmsg ( " Error while creating a new comment " , " red " );
2005-02-02 03:01:29 +00:00
return false ;
2006-06-24 04:20:32 +00:00
}
2005-02-02 03:01:29 +00:00
}
/**
* Update comment .
* FIXME : Informs interested people about the modification .
* Returns true on success and false on failure .
*/
function update ( $sSubject = null , $sBody = null , $iParentId = null , $iVersionId = null )
{
if ( $iParentId )
{
2006-06-27 19:16:27 +00:00
if ( ! query_parameters ( " UPDATE appComments SET parentId = '?' WHERE commentId = '?' " ,
$iParentId , $this -> iCommentId ))
2005-02-02 03:01:29 +00:00
return false ;
$this -> iParentId = $iParentId ;
}
if ( $iVersionId )
{
2006-06-27 19:16:27 +00:00
if ( ! query_parameters ( " UPDATE appComments SET versionId = '?' WHERE commentId = '?' " ,
$iVersionId , $this -> iCommentId ))
2005-02-02 03:01:29 +00:00
return false ;
$this -> iVersionId = $iVersionId ;
// FIXME: we need to refetch $this->iAppId.
}
if ( $sSubject )
{
2006-06-27 19:16:27 +00:00
if ( ! query_parameters ( " UPDATE appComments SET subject = '?' WHERE commentId = '?' " ,
$sSubject , $this -> iCommentId ))
2005-02-02 03:01:29 +00:00
return false ;
$this -> sSubject = $sSubject ;
}
if ( $sBody )
{
2006-06-27 19:16:27 +00:00
if ( ! query_parameters ( " UPDATE appComments SET body = '?' WHERE commentId = '?' " ,
$sBody , $this -> iCommentId ))
2005-02-02 03:01:29 +00:00
return false ;
$this -> sBody = $sBody ;
}
return true ;
}
/**
* Removes the current comment from the database .
* Informs interested people about the deletion .
* Returns true on success and false on failure .
*/
2007-09-14 23:02:12 -04:00
function delete ()
2005-02-02 03:01:29 +00:00
{
2006-06-27 19:16:27 +00:00
$hResult = query_parameters ( " DELETE FROM appComments WHERE commentId = '?' " , $this -> iCommentId );
2005-02-02 03:01:29 +00:00
if ( $hResult )
{
/* fixup the child comments so the parentId points to a valid parent comment */
2006-06-27 19:16:27 +00:00
$hResult = query_parameters ( " UPDATE appComments set parentId = '?' WHERE parentId = '?' " ,
$this -> iParentId , $this -> iCommentId );
2007-08-24 02:52:34 +00:00
2005-02-02 03:01:29 +00:00
return true ;
2007-08-24 02:52:34 +00:00
} else
{
2007-09-14 23:02:12 -04:00
return false ;
2005-02-02 03:01:29 +00:00
}
2007-08-24 02:52:34 +00:00
}
2006-07-09 00:48:33 +00:00
function get_comment_count_for_versionid ( $iVersionId )
{
$sQuery = " SELECT count(*) as cnt from appComments where versionId = '?' " ;
$hResult = query_parameters ( $sQuery , $iVersionId );
if ( ! $hResult ) return 0 ;
2007-08-03 23:27:25 +00:00
$oRow = query_fetch_object ( $hResult );
2006-07-09 00:48:33 +00:00
return $oRow -> cnt ;
}
2007-10-21 13:33:43 +02:00
function getOutputEditorValues ( $aClean )
{
$this -> sSubject = $aClean [ 'sSubject' ];
$this -> sBody = $aClean [ 'sBody' ];
$this -> iParentId = $aClean [ 'iThread' ];
2007-10-23 21:49:06 +02:00
if ( $aClean [ 'iVersionId' ])
$this -> iVersionId = $aClean [ 'iVersionId' ];
2007-10-21 13:33:43 +02:00
if ( ! $this -> oOwner )
$this -> oOwner = $_SESSION [ 'current' ];
if ( ! $this -> sDateCreated )
$this -> sDateCreated = date ( " l F jS Y, H:i " );
}
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
/**
* display a single comment ( in $oRow )
*/
function view_app_comment ( $oRow )
2007-10-21 13:33:43 +02:00
{
$oComment = new comment ( null , $oRow );
$oComment -> display ();
}
function display ()
2005-02-02 03:01:29 +00:00
{
2006-07-08 22:09:14 +00:00
echo html_frame_start ( '' , '98%' );
echo '<table width="100%" border="0" cellpadding="2" cellspacing="1">' , " \n " ;
// message header
2007-10-21 13:33:43 +02:00
echo " <tr bgcolor= \" #E0E0E0 \" ><td><a name=Comment- " . $this -> iCommentId . " ></a> \n " ;
echo " <b> " . $this -> sSubject . " </b><br /> \n " ;
echo " by " . forum_lookup_user ( $this -> oOwner -> iUserId ) . " on " . $this -> sDateCreated . " <br /> \n " ;
2006-07-08 22:09:14 +00:00
echo " </td></tr><tr><td> \n " ;
// body
2007-10-21 13:33:43 +02:00
echo htmlify_urls ( $this -> sBody ), " <br /><br /> \n " ;
2006-07-08 22:09:14 +00:00
2007-10-21 13:33:43 +02:00
$oVersion = new version ( $this -> iVersionId );
$oM = new objectManager ( " comment " , " Post new ocmment " );
$oM -> setReturnTo ( $oVersion -> objectMakeUrl ());
2006-07-08 22:09:14 +00:00
// reply post buttons
2007-10-22 17:07:31 +02:00
echo " [<a href= \" " . $oM -> makeUrl ( " add " ) . " &iVersionId= $this->iVersionId\ " >< small > post new </ small ></ a > ] \n " ;
2007-10-23 13:25:44 +02:00
echo " [<a href= \" " . $oM -> makeUrl ( " add " ) . " &iVersionId= $this->iVersionId " .
" &iThread= $this->iCommentId\ " >< small > reply to this </ small ></ a > ] \n " ;
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
echo " </td></tr> \n " ;
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
// delete message button, for admins
2007-10-21 13:33:43 +02:00
if ( $this -> canEdit ())
2006-07-08 22:09:14 +00:00
{
echo " <tr> " ;
2007-09-14 23:02:12 -04:00
echo " <td><form method= \" post \" name= \" sMessage \" action= \" " . BASE . " objectManager.php \" ><input type= \" submit \" value= \" Delete \" class= \" button \" > \n " ;
2007-10-21 13:33:43 +02:00
echo " <input type= \" hidden \" name= \" iId \" value= \" $this->iCommentId\ " /> " ;
2007-09-14 23:02:12 -04:00
echo " <input type= \" hidden \" name= \" sClass \" value= \" comment \" /> " ;
echo " <input type= \" hidden \" name= \" bQueued \" value= \" false \" /> " ;
echo " <input type= \" hidden \" name= \" sAction \" value= \" delete \" /> " ;
echo " <input type= \" hidden \" name= \" sTitle \" value= \" Delete comment \" /> " ;
echo " <input type= \" hidden \" name= \" sReturnTo \" value= \" " . $oVersion -> objectMakeUrl () . " \" /> " ;
2006-07-08 22:09:14 +00:00
echo " </form> \n " ;
echo " </td></tr> " ;
}
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
echo " </table> \n " ;
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
echo html_frame_end ();
}
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
/**
* grab comments for appId / versionId
* if parentId is not - 1 only comments for that thread are returned
*/
2006-07-20 03:19:23 +00:00
function grab_comments ( $iVersionId , $iParentId = null )
2006-07-08 22:09:14 +00:00
{
2006-07-20 03:52:02 +00:00
/* TODO: remove the logging when we figure out where the */
/* invalid $iVersionId is coming */
/* if $iVersionId is invalid we should log where we came from */
/* so we can debug the problem */
if ( $iVersionId == " " )
{
error_log :: logBackTrace ( " logging iVersionId oddity " );
return NULL ;
}
2006-07-08 22:09:14 +00:00
/* escape input so we can use query_appdb() without concern */
2007-08-03 23:27:25 +00:00
$iVersionId = query_escape_string ( $iVersionId );
$iParentId = query_escape_string ( $iParentId );
2006-06-27 19:16:27 +00:00
2006-07-20 03:19:23 +00:00
$sExtra = " " ;
2006-07-26 19:30:11 +00:00
/* NOTE: we must compare against NULL here because $iParentId of 0 is valid */
if ( $iParentId != NULL )
2006-07-20 03:19:23 +00:00
$sExtra = " AND parentId = ' " . $iParentId . " ' " ;
2005-02-02 03:01:29 +00:00
2006-07-20 03:19:23 +00:00
$sQuery = " SELECT from_unixtime(unix_timestamp(appComments.time), \" %W %M %D %Y, %k:%i \" ) as time, " .
2006-07-08 22:09:14 +00:00
" appComments.commentId, appComments.parentId, appComments.versionId, appComments.userId, appComments.subject, appComments.body, appVersion.appId " .
2006-07-20 03:19:23 +00:00
" FROM appComments, appVersion WHERE appComments.versionId = appVersion.versionId AND appComments.versionId = ' " . $iVersionId . " ' " .
$sExtra .
2006-07-08 22:09:14 +00:00
" ORDER BY appComments.time ASC " ;
2006-07-20 03:19:23 +00:00
$hResult = query_appdb ( $sQuery );
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
return $hResult ;
}
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
/**
* display nested comments
* handle is a db result set
*/
function do_display_comments_nested ( $hResult )
2005-02-02 03:01:29 +00:00
{
2007-08-03 23:27:25 +00:00
while ( $oRow = query_fetch_object ( $hResult ))
2005-02-02 03:01:29 +00:00
{
2006-07-08 22:09:14 +00:00
Comment :: view_app_comment ( $oRow );
$hResult2 = Comment :: grab_comments ( $oRow -> versionId , $oRow -> commentId );
2007-08-03 23:27:25 +00:00
if ( $hResult && query_num_rows ( $hResult2 ))
2006-07-08 22:09:14 +00:00
{
echo " <blockquote> \n " ;
Comment :: do_display_comments_nested ( $hResult2 );
echo " </blockquote> \n " ;
}
2005-02-02 03:01:29 +00:00
}
2006-07-08 22:09:14 +00:00
}
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
function display_comments_nested ( $versionId , $threadId )
{
$hResult = Comment :: grab_comments ( $versionId , $threadId );
Comment :: do_display_comments_nested ( $hResult );
}
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
/**
* display threaded comments
* handle is a db result set
*/
function do_display_comments_threaded ( $hResult , $is_main )
2005-02-02 03:01:29 +00:00
{
2006-07-08 22:09:14 +00:00
if ( ! $is_main )
echo " <ul> \n " ;
2005-02-02 03:01:29 +00:00
2007-08-03 23:27:25 +00:00
while ( $oRow = query_fetch_object ( $hResult ))
2005-02-02 03:01:29 +00:00
{
2006-07-08 22:09:14 +00:00
if ( $is_main )
{
Comment :: view_app_comment ( $oRow );
} else
{
echo '<li><a href="commentview.php?iAppId=' . $oRow -> appId . '&iVersionId=' . $oRow -> versionId . '&iThreadId=' . $oRow -> parentId . '"> ' .
$oRow -> subject . ' </a> by ' . forum_lookup_user ( $oRow -> userId ) . ' on ' . $oRow -> time . ' </li>' . " \n " ;
}
$hResult2 = Comment :: grab_comments ( $oRow -> versionId , $oRow -> commentId );
2007-08-03 23:27:25 +00:00
if ( $hResult2 && query_num_rows ( $hResult2 ))
2006-07-08 22:09:14 +00:00
{
echo " <blockquote> \n " ;
Comment :: do_display_comments_threaded ( $hResult2 , 0 );
echo " </blockquote> \n " ;
}
2005-02-02 03:01:29 +00:00
}
2007-09-14 23:02:12 -04:00
2006-07-08 22:09:14 +00:00
if ( ! $is_main )
echo " </ul> \n " ;
}
2005-02-02 03:01:29 +00:00
2007-09-14 23:02:12 -04:00
function canEdit ()
{
2007-09-17 10:24:57 +02:00
if ( $_SESSION [ 'current' ] -> hasPriv ( " admin " ))
return TRUE ;
$oVersion = new version ( $this -> iVersionId );
return $oVersion -> canEdit ();
2007-09-14 23:02:12 -04:00
}
function objectGetId ()
{
return $this -> iCommentId ;
}
function objectGetSubmitterId ()
{
return $this -> oOwner -> iUserId ;
}
function objectGetMailOptions ( $sAction , $bMailSubmitter , $bParentAction )
{
$oOptions = new mailOptions ();
if ( $sAction == " delete " && $bParentAction )
$oOptions -> bMailOnce = TRUE ;
return $oOptions ;
}
function objectGetMail ( $sAction , $bMailSubmitter , $bParentAction )
{
$sSubject = " " ;
$sMessage = " " ;
$aRecipients = null ;
$oVersion = new version ( $this -> iVersionId );
$sVerName = version :: fullName ( $this -> iVersionId );
if ( $bMailSubmitter )
{
switch ( $sAction )
{
case " delete " :
if ( $bParentAction )
{
$sSubject = " Comments for $sVerName deleted " ;
$sMessage = " Your comments for $sVerName were deleted because the " ;
$sMessage .= " version was removed from the database " ;
} else
{
$sSubject = " Comment for $sVerName deleted " ;
$sMessage = $oVersion -> objectMakeUrl () . " \n " ;
$sMessage .= " \n " ;
$sMessage .= " This comment was made on " . substr ( $this -> sDateCreated , 0 , 10 ) . " \n " ;
$sMessage .= " \n " ;
$sMessage .= " Subject: " . $this -> sSubject . " \r \n " ;
$sMessage .= " \n " ;
$sMessage .= $this -> sBody . " \r \n " ;
}
break ;
}
} else
{
switch ( $sAction )
{
case " delete " :
if ( ! $bParentAction )
{
$sSubject = " Comment for $sVerName deleted " ;
$sMessage = $oVersion -> objectMakeUrl () . " \n " ;
$sMessage .= " \n " ;
$sMessage .= " This comment was made on " . substr ( $this -> sDateCreated , 0 , 10 ) . " by " . $this -> oOwner -> sRealname . " \n " ;
$sMessage .= " \n " ;
$sMessage .= " Subject: " . $this -> sSubject . " \r \n " ;
$sMessage .= " \n " ;
$sMessage .= $this -> sBody . " \r \n " ;
}
break ;
}
$aRecipients = User :: get_notify_email_address_list ( $this -> iAppId , $this -> iVersionId );
}
return array ( $sSubject , $sMessage , $aRecipients );
}
2007-09-08 22:29:17 +00:00
function objectGetChildren ()
{
return array ();
}
2006-07-08 22:09:14 +00:00
function display_comments_threaded ( $versionId , $threadId = 0 )
{
$hResult = Comment :: grab_comments ( $versionId , $threadId );
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
Comment :: do_display_comments_threaded ( $hResult , 1 );
}
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
/**
* display flat comments
*/
function display_comments_flat ( $versionId )
2005-02-02 03:01:29 +00:00
{
2006-07-08 22:09:14 +00:00
$hResult = Comment :: grab_comments ( $versionId );
if ( $hResult )
2005-02-02 03:01:29 +00:00
{
2007-08-03 23:27:25 +00:00
while ( $oRow = query_fetch_object ( $hResult ))
2006-07-08 22:09:14 +00:00
{
Comment :: view_app_comment ( $oRow );
}
2005-02-02 03:01:29 +00:00
}
}
2006-07-08 22:09:14 +00:00
function view_app_comments ( $versionId , $threadId = 0 )
{
2007-01-04 02:35:01 +00:00
global $aClean ;
2006-06-17 06:10:10 +00:00
2006-07-08 22:09:14 +00:00
// count posts
$hResult = query_parameters ( " SELECT commentId FROM appComments WHERE versionId = '?' " , $versionId );
2007-08-03 23:27:25 +00:00
$messageCount = query_num_rows ( $hResult );
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
//start comment format table
echo html_frame_start ( " " , " 98% " , '' , 0 );
echo '<table width="100%" border="0" cellpadding="1" cellspacing="0">' , " \n " ;
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
echo '<tr><td bgcolor="#C0C0C0" align="center"><table border="0" cellpadding="0" cellspacing="0"><tr bgcolor="#C0C0C0">' , " \n " ;
2007-10-21 13:33:43 +02:00
$oVersion = new version ( $versionId );
2006-07-08 22:09:14 +00:00
// message display mode changer
if ( $_SESSION [ 'current' ] -> isLoggedIn ())
{
// FIXME we need to change this so not logged in users can change current view as well
if ( ! empty ( $aClean [ 'sCmode' ]))
$_SESSION [ 'current' ] -> setPref ( " comments:mode " , $aClean [ 'sCmode' ]);
$sel [ $_SESSION [ 'current' ] -> getPref ( " comments:mode " , " threaded " )] = 'selected' ;
2007-04-03 02:08:44 +00:00
echo '<td><form method="post" name="sMode" action="' .
$oVersion -> objectMakeUrl () . '">' , " \n " ;
2006-07-08 22:09:14 +00:00
echo " <b>Application Comments</b> $messageCount total comments " ;
echo '<b>Mode</b> <select name="sCmode" onchange="document.sMode.submit();">' , " \n " ;
echo ' <option value="flat" ' . $sel [ 'flat' ] . '>Flat</option>' , " \n " ;
echo ' <option value="threaded" ' . $sel [ 'threaded' ] . '>Threaded</option>' , " \n " ;
echo ' <option value="nested" ' . $sel [ 'nested' ] . '>Nested</option>' , " \n " ;
echo ' <option value="off" ' . $sel [ 'off' ] . '>No Comments</option>' , " \n " ;
echo '</select>' , " \n " ;
2007-04-03 02:08:44 +00:00
echo '</form></td>' , " \n " ;
2006-07-08 22:09:14 +00:00
}
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
// blank space
echo '<td> </td>' , " \n " ;
2007-10-21 13:33:43 +02:00
$oM = new objectManager ( " comment " , " Add comment " );
$oM -> setReturnTo ( $oVersion -> objectMakeUrl ());
2006-07-08 22:09:14 +00:00
// post new message button
2007-10-21 13:33:43 +02:00
echo '<td><form method="post" name="sMessage" action="objectManager.php">' ;
echo '<input type="hidden" name="sAction" value="add" />' ;
echo $oM -> makeUrlFormData ();
echo '<input type="submit" value="Post new comment" class="button"> ' , " \n " ;
2006-07-08 22:09:14 +00:00
echo '<input type="hidden" name="iVersionId" value="' . $versionId . '"></form></td>' , " \n " ;
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
//end comment format table
echo '</tr></table></td></tr>' , " \n " ;
echo '</table>' , " \n " ;
echo html_frame_end ();
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
if ( $messageCount > 0 )
{
echo '<p align="center">The following comments are owned by whoever posted them. WineHQ is not responsible for what they say.</p>' . " \n " ;
}
//start comments
echo '<table width="100%" border="0" cellpadding="2" cellspacing="1"><tr><td>' , " \n " ;
2005-02-02 03:01:29 +00:00
2006-07-08 22:09:14 +00:00
//hide or display depending on pref
if ( $_SESSION [ 'current' ] -> isLoggedIn ())
$mode = $_SESSION [ 'current' ] -> getPref ( " comments:mode " , " threaded " );
else
$mode = " threaded " ; /* default non-logged in users to threaded comment display mode */
2005-02-02 03:01:29 +00:00
2007-07-24 01:45:19 +00:00
if ( isset ( $aClean [ 'sMode' ]) && $aClean [ 'sMode' ] == " nested " )
2006-07-08 22:09:14 +00:00
$mode = " nested " ;
2006-03-24 05:01:48 +00:00
2006-07-08 22:09:14 +00:00
switch ( $mode )
{
2005-02-02 03:01:29 +00:00
case " flat " :
2006-07-08 22:09:14 +00:00
Comment :: display_comments_flat ( $versionId );
break ;
2005-02-02 03:01:29 +00:00
case " nested " :
2006-07-08 22:09:14 +00:00
Comment :: display_comments_nested ( $versionId , $threadId );
break ;
2005-02-02 03:01:29 +00:00
case " threaded " :
2006-07-08 22:09:14 +00:00
Comment :: display_comments_threaded ( $versionId , $threadId );
break ;
}
echo '</td></tr></table>' , " \n " ;
2007-04-03 02:08:44 +00:00
}
2007-10-21 13:33:43 +02:00
function allowAnonymousSubmissions ()
{
2007-10-24 00:33:52 +02:00
return FALSE ;
2007-10-21 13:33:43 +02:00
}
function objectGetCustomVars ( $sAction )
{
switch ( $sAction )
{
case " add " :
2007-10-22 17:07:31 +02:00
return array ( " iThread " , " iVersionId " );
2007-10-21 13:33:43 +02:00
default :
return null ;
}
}
2007-10-22 17:07:31 +02:00
function checkOutputEditorInput ( $aClean )
{
$sErrors = " " ;
if ( ! $aClean [ 'iVersionId' ])
$sErrors .= " <li>No version id defined; something may have gone wrong with the URL</li> \n " ;
if ( ! $aClean [ 'sBody' ])
$sErrors .= " <li>You need to enter a message!</li> \n " ;
return $sErrors ;
}
2007-10-21 13:33:43 +02:00
function outputEditor ( $aClean )
{
$sMesTitle = " <b>Post New Comment</b> " ;
if ( $aClean [ 'iThread' ] > 0 )
{
$hResult = query_parameters ( " SELECT * FROM appComments WHERE commentId = '?' " ,
$aClean [ 'iThread' ]);
$oRow = query_fetch_object ( $hResult );
if ( $oRow )
{
$sMesTitle = " <b>Replying To ...</b> $oRow->subject\n " ;
echo html_frame_start ( $oRow -> subject , 500 );
echo htmlify_urls ( $oRow -> body ), " <br /><br /> \n " ;
echo html_frame_end ();
2007-10-23 13:25:44 +02:00
/* Set default reply subject */
if ( ! $this -> sSubject )
{
// Only add RE: once
if ( eregi ( " RE: " , $oRow -> subject ))
$this -> sSubject = $oRow -> subject ;
else
$this -> sSubject = " RE: " . $oRow -> subject ;
}
2007-10-21 13:33:43 +02:00
}
}
echo " <p align= \" center \" >Enter your comment in the box below. " ;
echo " </br>Please do not paste large terminal or debug outputs here.</p> " ;
echo html_frame_start ( $sMesTitle , 500 , " " , 0 );
echo '<table width="100%" border=0 cellpadding=0 cellspacing=1>' , " \n " ;
echo " <tr class= \" color0 \" ><td align=right><b>From:</b> </td> \n " ;
echo " <td> " . $_SESSION [ 'current' ] -> sRealname . " </td></tr> \n " ;
echo " <tr class= \" color0 \" ><td align=right><b>Subject:</b> </td> \n " ;
echo " <td> <input type= \" text \" size= \" 35 \" name= \" sSubject \" value= \" " . $this -> sSubject . " \" /> </td></tr> \n " ;
echo " <tr class= \" color1 \" ><td colspan=2><textarea name= \" sBody \" cols= \" 70 \" rows= \" 15 \" wrap= \" virtual \" > " . $this -> sBody . " </textarea></td></tr> \n " ;
echo " </table> \n " ;
echo html_frame_end ();
echo " <input type= \" hidden \" name= \" iThread \" value= \" " . $aClean [ 'iThread' ] . " \" /> \n " ;
echo " <input type= \" hidden \" name= \" iVersionId \" value= \" " . $aClean [ 'iVersionId' ] . " \" /> \n " ;
}
function objectShowPreview ()
{
return TRUE ;
}
2007-04-03 02:08:44 +00:00
function objectMakeUrl ()
{
$oVersion = new version ( $this -> iVersionId );
$sUrl = $oVersion -> objectMakeUrl () . " #Comment- " . $this -> iCommentId ;
return $sUrl ;
}
2006-07-08 22:09:14 +00:00
}
/*
* Comment functions that are not part of the class
*/
function forum_lookup_user ( $iUserId )
{
if ( $iUserId > 0 )
{
$oUser = new User ( $iUserId );
if ( $_SESSION [ 'current' ] -> isLoggedIn ())
2007-03-24 18:36:43 +00:00
$sMailto = '<a href="' . BASE . 'contact.php?iRecipientId=' .
$oUser -> iUserId . '">' . $oUser -> sRealname . '</a>' ;
2006-07-08 22:09:14 +00:00
else
$sMailto = $oUser -> sRealname ;
}
if ( ! $iUserId || ! $oUser -> isLoggedIn ())
{
$sMailto = 'Anonymous' ;
2005-02-02 03:01:29 +00:00
}
2006-07-08 22:09:14 +00:00
return $sMailto ;
}
2005-02-02 03:01:29 +00:00
?>