2006-12-02 04:36:16 +00:00
< ? php
/*
2010-03-09 22:40:21 +00:00
* e107 website system
*
2013-03-24 18:59:18 +01:00
* Copyright ( c ) 2008 - 2013 e107 Inc ( e107 . org )
2010-03-09 22:40:21 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
* Forum class
*
2006-12-02 04:36:16 +00:00
*/
2008-12-20 23:59:00 +00:00
2013-03-12 20:35:04 -07:00
/* Forum Header File */
if ( ! defined ( 'e107_INIT' )) { exit ; }
2013-03-13 02:39:00 -07:00
$jscode = <<< EON
2013-03-12 20:35:04 -07:00
$ ( document ) . ready ( function ()
{
2013-03-13 02:39:00 -07:00
$ ( 'a[data-forum-action], input[data-forum-action]' ) . on ( 'click' , function ( e )
2013-03-12 20:35:04 -07:00
{
var action = $ ( this ) . attr ( 'data-forum-action' );
var thread = $ ( this ) . attr ( 'data-forum-thread' );
2013-03-13 02:39:00 -07:00
var post = $ ( this ) . attr ( 'data-forum-post' );
var text = $ ( '#forum-quickreply-text' ) . val ();
2013-03-14 04:05:33 -07:00
var insert = $ ( this ) . attr ( 'data-forum-insert' );
2013-03-13 02:39:00 -07:00
2013-03-12 20:35:04 -07:00
if ( action != 'stick' && action != 'unstick' )
{
e . preventDefault ();
}
var script = $ ( this ) . attr ( " src " );
$ . ajax ({
type : " POST " ,
url : script ,
2013-03-14 04:05:33 -07:00
data : { thread : thread , action : action , post : post , text : text , insert : insert },
2013-03-13 02:39:00 -07:00
success : function ( data ) {
2013-03-14 02:26:47 -07:00
// alert(data);
2013-03-12 20:35:04 -07:00
var d = $ . parseJSON ( data );
2013-03-13 02:39:00 -07:00
if ( d )
2013-03-12 20:35:04 -07:00
{
2013-03-13 02:39:00 -07:00
if ( d . msg )
{
alert ( d . msg );
}
2013-03-14 16:25:24 -07:00
if ( action == 'quickreply' && d . status == 'ok' )
2013-03-13 02:39:00 -07:00
{
2013-03-14 05:36:52 -07:00
// alert(d.html);
2013-03-14 16:25:24 -07:00
if ( d . html != false )
{
$ ( '#forum-viewtopic li:last' ) . after ( d . html ) . hide () . slideDown ( 800 );
}
2013-03-14 02:26:47 -07:00
$ ( '#forum-quickreply-text' ) . val ( '' );
2013-03-13 02:39:00 -07:00
return ;
}
if ( d . hide )
{
var t = '#thread-' + thread ;
2013-03-14 16:25:24 -07:00
var p = '#post-' + post ;
2013-03-14 16:30:33 -07:00
// alert(p);
2013-03-13 02:39:00 -07:00
$ ( t ) . hide ( 'slow' );
2013-03-14 16:25:24 -07:00
$ ( p ) . hide ( 'slow' ) . slideUp ( 800 );
2013-03-13 02:39:00 -07:00
}
2013-03-12 20:35:04 -07:00
}
}
});
// return false;
});
});
EON ;
2013-03-13 02:39:00 -07:00
e107 :: js ( 'inline' , $jscode , 'jquery' );
2013-03-12 20:35:04 -07:00
2013-03-21 19:46:27 -07:00
e107 :: lan ( 'forum' , 'English_front' );
2013-03-14 04:05:33 -07:00
// include_lan(e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum.php');
2013-03-14 02:26:47 -07:00
include_once ( e_PLUGIN . 'forum/templates/forum_icons_template.php' );
2013-03-12 20:35:04 -07:00
2009-09-08 02:00:48 +00:00
class e107forum
2006-12-02 04:36:16 +00:00
{
2010-03-09 22:40:21 +00:00
// var $fieldTypes = array();
private $userViewed , $permList ;
2010-03-10 01:23:57 +00:00
public $modArray , $prefs ;
2008-11-26 19:59:06 +00:00
2013-03-28 00:43:00 -07:00
public function __construct ( $update = false )
2008-11-26 19:59:06 +00:00
{
2010-03-09 22:40:21 +00:00
$this -> e107 = e107 :: getInstance ();
2013-03-13 02:39:00 -07:00
$tp = e107 :: getParser ();
2010-03-09 22:40:21 +00:00
$this -> userViewed = array ();
$this -> modArray = array ();
2013-03-28 00:43:00 -07:00
if ( $update === false )
{
$this -> loadPermList ();
}
2010-03-09 22:40:21 +00:00
$this -> prefs = e107 :: getPlugConfig ( 'forum' );
if ( ! $this -> prefs -> get ( 'postspage' )) {
$this -> setDefaults ();
}
2013-03-12 20:35:04 -07:00
2013-03-13 02:39:00 -07:00
2013-03-14 02:26:47 -07:00
// var_dump($this->prefs);
/*
$this -> fieldTypes [ 'forum_post' ][ 'post_user' ] = 'int' ;
$this -> fieldTypes [ 'forum_post' ][ 'post_forum' ] = 'int' ;
$this -> fieldTypes [ 'forum_post' ][ 'post_datestamp' ] = 'int' ;
$this -> fieldTypes [ 'forum_post' ][ 'post_edit_datestamp' ] = 'int' ;
$this -> fieldTypes [ 'forum_post' ][ 'post_edit_user' ] = 'int' ;
$this -> fieldTypes [ 'forum_post' ][ 'post_thread' ] = 'int' ;
$this -> fieldTypes [ 'forum_post' ][ 'post_options' ] = 'escape' ;
$this -> fieldTypes [ 'forum_post' ][ 'post_attachments' ] = 'escape' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_user' ] = 'int' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_lastpost' ] = 'int' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_lastuser' ] = 'int' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_sticky' ] = 'int' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_forum_id' ] = 'int' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_active' ] = 'int' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_datestamp' ] = 'int' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_views' ] = 'int' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_replies' ] = 'int' ;
$this -> fieldTypes [ 'forum_thread' ][ 'thread_options' ] = 'escape' ;
$this -> fieldTypes [ 'forum' ][ 'forum_lastpost_user' ] = 'int' ;
*/
}
2013-03-31 00:06:21 -07:00
2013-04-18 18:25:20 -07:00
function getAttachmentPath ( $user , $create = false )
2013-03-31 00:06:21 -07:00
{
2013-03-31 00:43:18 -07:00
$user = intval ( $user );
2013-03-31 00:06:21 -07:00
$tp = e107 :: getParser ();
$baseDir = e_MEDIA . 'plugins/forum/attachments/' ;
$baseDir .= ( $user ) ? " user_ " . $tp -> leadingZeros ( $user , 6 ) : " anon " ;
2013-04-18 18:25:20 -07:00
if ( $create == true && ! is_dir ( $baseDir ))
{
mkdir ( $baseDir , 0755 );
}
2013-03-31 00:06:21 -07:00
$baseDir .= " / " ;
return $baseDir ;
}
function sendFile ( $data )
{
$sql = e107 :: getDb ();
$fid = intval ( $data [ 'dl' ]);
$array = $sql -> retrieve ( 'forum_post' , 'post_user,post_attachments' , 'post_id=' . intval ( $data [ 'id' ]));
2013-03-31 05:55:08 -07:00
$attach = e107 :: serialize ( $array [ 'post_attachments' ]);
2013-03-31 00:06:21 -07:00
$file = $this -> getAttachmentPath ( $array [ 'post_user' ]) . varset ( $attach [ 'file' ][ $fid ]);
e107 :: getFile () -> send ( $file );
}
2013-03-14 02:26:47 -07:00
2013-03-14 04:05:33 -07:00
/**
* Handle the Ajax quick - reply .
*/
2013-03-14 02:26:47 -07:00
function ajaxQuickReply ()
{
2013-03-13 02:39:00 -07:00
$tp = e107 :: getParser ();
2013-03-14 02:26:47 -07:00
if ( varset ( $_POST [ 'action' ]) == 'quickreply' && vartrue ( $_POST [ 'text' ]))
{
2013-03-14 04:05:33 -07:00
2013-03-14 02:26:47 -07:00
$postInfo = array ();
$postInfo [ 'post_ip' ] = e107 :: getIPHandler () -> getIP ( FALSE );
2013-03-14 04:05:33 -07:00
2013-03-14 02:26:47 -07:00
if ( USER )
{
$postInfo [ 'post_user' ] = USERID ;
2013-03-14 04:05:33 -07:00
2013-03-14 02:26:47 -07:00
}
else
{
$postInfo [ 'post_user_anon' ] = $_POST [ 'anonname' ];
}
2013-03-14 04:05:33 -07:00
$postInfo [ 'post_entry' ] = $_POST [ 'text' ];
$postInfo [ 'post_forum' ] = intval ( $_POST [ 'post' ]);
$postInfo [ 'post_datestamp' ] = time ();
$postInfo [ 'post_thread' ] = intval ( $_POST [ 'thread' ]);
2013-03-13 02:39:00 -07:00
2013-03-14 16:25:24 -07:00
$postInfo [ 'post_id' ] = $this -> postAdd ( $postInfo ); // save it.
2013-03-14 02:26:47 -07:00
$postInfo [ 'user_name' ] = USERNAME ;
$postInfo [ 'user_email' ] = USEREMAIL ;
$postInfo [ 'user_image' ] = USERIMAGE ;
2013-03-19 19:04:32 -07:00
$postInfo [ 'user_signature' ] = USERSIGNATURE ;
2013-03-14 04:05:33 -07:00
if ( $_POST [ 'insert' ] == 1 )
{
$tmpl = e107 :: getTemplate ( 'forum' , 'forum_viewtopic' , 'replies' );
$sc = e107 :: getScBatch ( 'view' , 'forum' );
$sc -> setScVar ( 'postInfo' , $postInfo );
$ret [ 'html' ] = $tp -> parseTemplate ( $tmpl , true , vartrue ( $forum_shortcodes )) . " \n " ;
}
else
{
$ret [ 'html' ] = false ;
}
2013-03-14 02:26:47 -07:00
$ret [ 'status' ] = 'ok' ;
$ret [ 'msg' ] = " Your post has been added " ;
2013-03-13 02:39:00 -07:00
2013-03-14 02:26:47 -07:00
//echo $ret;
echo json_encode ( $ret );
}
2013-03-13 02:39:00 -07:00
2013-03-14 02:26:47 -07:00
exit ;
}
function ajaxModerate ()
{
2013-03-14 16:25:24 -07:00
if ( ! vartrue ( $_POST [ 'thread' ]) && ! vartrue ( $_POST [ 'post' ]))
2013-03-12 20:35:04 -07:00
{
exit ;
}
$id = intval ( $_POST [ 'thread' ]);
2013-03-14 16:25:24 -07:00
// print_r($_POST);
2013-03-12 20:35:04 -07:00
$ret = array ( 'hide' => false , 'msg' => '' , 'status' => null );
switch ( $_POST [ 'action' ])
{
case 'delete' :
if ( $this -> threadDelete ( $id ))
{
$ret [ 'msg' ] = 'Deleted Thread #' . $id ;
$ret [ 'hide' ] = true ;
$ret [ 'status' ] = 'ok' ;
}
else
{
$ret [ 'msg' ] = " Couldn't Delete the Thread " ;
$ret [ 'status' ] = 'error' ;
}
break ;
2013-03-13 02:39:00 -07:00
case 'deletepost' :
if ( ! $postId = vartrue ( $_POST [ 'post' ]))
{
2013-03-14 16:25:24 -07:00
echo " No Post " ;
2013-03-13 02:39:00 -07:00
exit ;
}
if ( $this -> postDelete ( $postId ))
{
2013-03-14 16:25:24 -07:00
$ret [ 'msg' ] = 'Deleted Post #' . $postId ;
2013-03-13 02:39:00 -07:00
$ret [ 'hide' ] = true ;
$ret [ 'status' ] = 'ok' ;
}
else
{
2013-03-14 16:25:24 -07:00
$ret [ 'msg' ] = " Couldn't Delete the Post # " . $postId ;
2013-03-13 02:39:00 -07:00
$ret [ 'status' ] = 'error' ;
}
break ;
2013-03-12 20:35:04 -07:00
case 'lock' :
2013-03-24 18:59:18 +01:00
if ( e107 :: getDb () -> update ( 'forum_thread' , 'thread_active=0 WHERE thread_id=' . $id ))
2013-03-12 20:35:04 -07:00
{
$ret [ 'msg' ] = FORLAN_CLOSE ;
$ret [ 'status' ] = 'ok' ;
}
else
{
$ret [ 'msg' ] = " failed to close thread " ;
$ret [ 'status' ] = 'error' ;
}
break ;
case 'unlock' :
2013-03-24 18:59:18 +01:00
if ( e107 :: getDb () -> update ( 'forum_thread' , 'thread_active=1 WHERE thread_id=' . $id ))
2013-03-12 20:35:04 -07:00
{
$ret [ 'msg' ] = FORLAN_OPEN ;
$ret [ 'status' ] = 'ok' ;
}
else
{
$ret [ 'msg' ] = " failed to open thread " ;
$ret [ 'status' ] = 'error' ;
}
break ;
case 'stick' :
2013-03-24 18:59:18 +01:00
if ( e107 :: getDb () -> update ( 'forum_thread' , 'thread_sticky=1 WHERE thread_id=' . $id ))
2013-03-12 20:35:04 -07:00
{
$ret [ 'msg' ] = FORLAN_STICK ;
$ret [ 'status' ] = 'ok' ;
}
else
{
$ret [ 'msg' ] = " failed to stick thread " ;
$ret [ 'status' ] = 'error' ;
}
break ;
case 'unstick' :
2013-03-24 18:59:18 +01:00
if ( e107 :: getDb () -> update ( 'forum_thread' , 'thread_sticky=0 WHERE thread_id=' . $id ))
2013-03-12 20:35:04 -07:00
{
$ret [ 'msg' ] = FORLAN_UNSTICK ;
$ret [ 'status' ] = 'ok' ;
}
else
{
$ret [ 'msg' ] = " failed to unstick thread " ;
$ret [ 'status' ] = 'error' ;
}
2013-03-13 02:39:00 -07:00
break ;
2013-03-12 20:35:04 -07:00
default :
$ret [ 'status' ] = 'error' ;
$ret [ 'msg' ] = 'No action selected' ;
break ;
}
echo json_encode ( $ret );
exit ;
2013-03-14 02:26:47 -07:00
}
2013-03-12 20:35:04 -07:00
2013-03-14 02:26:47 -07:00
2013-03-13 02:39:00 -07:00
2011-04-26 11:27:36 +00:00
private function loadPermList ()
2008-11-26 19:59:06 +00:00
{
2010-03-09 22:40:21 +00:00
$e107 = e107 :: getInstance ();
2009-09-08 02:00:48 +00:00
if ( $tmp = $e107 -> ecache -> retrieve_sys ( 'forum_perms' ))
2008-11-26 19:59:06 +00:00
{
$this -> permList = $e107 -> arrayStorage -> ReadArray ( $tmp );
}
else
{
2011-04-26 11:27:36 +00:00
$this -> _getForumPermList ();
2009-09-08 02:00:48 +00:00
$tmp = $e107 -> arrayStorage -> WriteArray ( $this -> permList , false );
$e107 -> ecache -> set_sys ( 'forum_perms' , $tmp );
2008-11-26 19:59:06 +00:00
}
unset ( $tmp );
}
2010-03-13 20:38:40 +00:00
2013-03-12 20:35:04 -07:00
2011-04-26 11:27:36 +00:00
public function getForumPermList ( $what = null )
{
if ( null !== $what ) return ( isset ( $this -> permList [ $what ]) ? $this -> permList [ $what ] : null );
return $this -> permList ;
}
2013-03-12 20:35:04 -07:00
2010-03-09 22:40:21 +00:00
private function setDefaults ()
{
$this -> prefs -> set ( 'show_topics' , '1' );
$this -> prefs -> set ( 'postfix' , '[more...]' );
$this -> prefs -> set ( 'poll' , '255' );
$this -> prefs -> set ( 'popular' , '10' );
$this -> prefs -> set ( 'track' , '1' );
$this -> prefs -> set ( 'eprefix' , '[forum]' );
$this -> prefs -> set ( 'enclose' , '1' );
$this -> prefs -> set ( 'title' , 'Forums' );
$this -> prefs -> set ( 'postspage' , '10' );
$this -> prefs -> set ( 'threadspage' , '25' );
$this -> prefs -> set ( 'highlightsticky' , '1' );
}
2008-11-26 19:59:06 +00:00
2013-03-12 20:35:04 -07:00
2011-04-26 11:27:36 +00:00
private function _getForumPermList ()
2008-11-26 19:59:06 +00:00
{
2010-03-09 22:40:21 +00:00
$e107 = e107 :: getInstance ();
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2010-03-13 20:38:40 +00:00
2008-11-26 19:59:06 +00:00
$this -> permList = array ();
$qryList = array ();
2010-03-09 22:40:21 +00:00
$qryList [ 'view' ] = "
2010-03-14 00:50:27 +00:00
SELECT f . forum_id , f . forum_parent
2008-11-26 19:59:06 +00:00
FROM `#forum` AS f
LEFT JOIN `#forum` AS fp ON f . forum_parent = fp . forum_id AND fp . forum_class IN ( " .USERCLASS_LIST. " )
WHERE f . forum_class IN ( " .USERCLASS_LIST. " ) AND f . forum_parent != 0 AND fp . forum_id IS NOT NULL
" ;
2010-03-09 22:40:21 +00:00
$qryList [ 'post' ] = "
2010-03-14 00:50:27 +00:00
SELECT f . forum_id , f . forum_parent
2008-11-26 19:59:06 +00:00
FROM `#forum` AS f
LEFT JOIN `#forum` AS fp ON f . forum_parent = fp . forum_id AND fp . forum_postclass IN ( " .USERCLASS_LIST. " )
WHERE f . forum_postclass IN ( " .USERCLASS_LIST. " ) AND f . forum_parent != 0 AND fp . forum_id IS NOT NULL
" ;
2010-03-09 22:40:21 +00:00
$qryList [ 'thread' ] = "
2010-03-14 00:50:27 +00:00
SELECT f . forum_id , f . forum_parent
2008-11-26 19:59:06 +00:00
FROM `#forum` AS f
LEFT JOIN `#forum` AS fp ON f . forum_parent = fp . forum_id AND fp . forum_threadclass IN ( " .USERCLASS_LIST. " )
WHERE f . forum_threadclass IN ( " .USERCLASS_LIST. " ) AND f . forum_parent != 0 AND fp . forum_id IS NOT NULL
" ;
foreach ( $qryList as $key => $qry )
{
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $qry ))
2008-11-26 19:59:06 +00:00
{
2010-03-14 00:50:27 +00:00
$tmp = array ();
2013-03-24 18:59:18 +01:00
while ( $row = $sql -> fetch ())
2008-11-26 19:59:06 +00:00
{
2010-03-14 00:50:27 +00:00
$tmp [ $row [ 'forum_id' ]] = 1 ;
$tmp [ $row [ 'forum_parent' ]] = 1 ;
2008-11-26 19:59:06 +00:00
}
2010-03-14 00:50:27 +00:00
ksort ( $tmp );
$this -> permList [ $key ] = array_keys ( $tmp );
$this -> permList [ $key . '_list' ] = implode ( ',' , array_keys ( $tmp ));
2008-11-26 19:59:06 +00:00
}
}
2008-11-27 03:02:26 +00:00
}
2008-11-26 19:59:06 +00:00
2013-03-12 20:35:04 -07:00
2008-11-27 03:02:26 +00:00
function checkPerm ( $forumId , $type = 'view' )
{
return ( in_array ( $forumId , $this -> permList [ $type ]));
2008-11-26 19:59:06 +00:00
}
2013-03-12 20:35:04 -07:00
2008-12-05 01:30:56 +00:00
function threadViewed ( $threadId )
{
2009-09-08 02:00:48 +00:00
$e107 = e107 :: getInstance ();
2008-12-05 01:30:56 +00:00
if ( ! $this -> userViewed )
{
2009-09-08 02:00:48 +00:00
if ( isset ( $e107 -> currentUser [ 'user_plugin_forum_viewed' ]))
2008-12-05 01:30:56 +00:00
{
2009-09-08 02:00:48 +00:00
$this -> userViewed = explode ( ',' , $e107 -> currentUser [ 'user_plugin_forum_viewed' ]);
2008-12-05 01:30:56 +00:00
}
}
2008-12-18 17:10:48 +00:00
return ( is_array ( $this -> userViewed ) && in_array ( $threadId , $this -> userViewed ));
2008-12-05 01:30:56 +00:00
}
2013-03-12 20:35:04 -07:00
2008-12-05 01:30:56 +00:00
function getTrackedThreadList ( $id , $retType = 'array' )
{
2009-09-08 02:00:48 +00:00
$e107 = e107 :: getInstance ();
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-05 01:30:56 +00:00
$id = ( int ) $id ;
2013-03-24 18:59:18 +01:00
if ( $sql -> select ( 'forum_track' , 'track_thread' , 'track_userid = ' . $id ))
2008-12-05 01:30:56 +00:00
{
2013-03-24 18:59:18 +01:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2008-12-05 01:30:56 +00:00
{
$ret [] = $row [ 'track_thread' ];
}
return ( $retType == 'array' ? $ret : implode ( ',' , $ret ));
}
return false ;
}
2008-11-27 03:02:26 +00:00
/*
* Add a post to the db .
*
* If threadinfo is given , then we ' re adding a new thread .
* We must get thread_id to provide to postInfo after insertion
2008-11-29 01:24:27 +00:00
*/
function postAdd ( $postInfo , $updateThread = true , $updateForum = true )
2008-11-27 03:02:26 +00:00
{
2009-09-08 02:00:48 +00:00
// var_dump($postInfo);
2008-12-01 21:11:01 +00:00
//Future option, will just set to true here
$addUserPostCount = true ;
2008-12-07 04:16:39 +00:00
$result = false ;
2008-12-01 21:11:01 +00:00
2009-09-08 02:00:48 +00:00
$e107 = e107 :: getInstance ();
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2009-01-10 04:39:54 +00:00
$info = array ();
2010-03-09 22:40:21 +00:00
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
2009-01-09 16:22:08 +00:00
$info [ 'data' ] = $postInfo ;
2013-03-24 18:59:18 +01:00
$postId = $sql -> insert ( 'forum_post' , $info );
2008-11-29 01:24:27 +00:00
$forumInfo = array ();
2008-12-07 04:16:39 +00:00
if ( $postId && $updateThread )
2008-11-27 03:02:26 +00:00
{
$threadInfo = array ();
if ( varset ( $postInfo [ 'post_user' ]))
{
$threadInfo [ 'thread_lastuser' ] = $postInfo [ 'post_user' ];
2008-11-30 22:05:12 +00:00
$threadInfo [ 'thread_lastuser_anon' ] = '_NULL_' ;
2008-11-29 01:24:27 +00:00
$forumInfo [ 'forum_lastpost_user' ] = $postInfo [ 'post_user' ];
2008-11-30 22:05:12 +00:00
$forumInfo [ 'forum_lastpost_user_anon' ] = '_NULL_' ;
2008-11-27 03:02:26 +00:00
}
else
{
2008-11-29 01:24:27 +00:00
$threadInfo [ 'thread_lastuser' ] = 0 ;
2008-12-04 21:36:09 +00:00
$threadInfo [ 'thread_lastuser_anon' ] = $postInfo [ 'post_user_anon' ];
2008-11-29 01:24:27 +00:00
$forumInfo [ 'forum_lastpost_user' ] = 0 ;
2008-12-04 21:36:09 +00:00
$forumInfo [ 'forum_lastpost_user_anon' ] = $postInfo [ 'post_user_anon' ];
2008-11-27 03:02:26 +00:00
}
2008-11-29 01:24:27 +00:00
$threadInfo [ 'thread_lastpost' ] = $postInfo [ 'post_datestamp' ];
2008-12-02 21:34:18 +00:00
$threadInfo [ 'thread_total_replies' ] = 'thread_total_replies + 1' ;
2008-11-29 01:24:27 +00:00
2009-01-09 16:22:08 +00:00
$info = array ();
$info [ 'data' ] = $threadInfo ;
$info [ 'WHERE' ] = 'thread_id = ' . $postInfo [ 'post_thread' ];
2010-03-09 22:40:21 +00:00
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
2010-06-21 01:27:26 +00:00
$info [ '_FIELD_TYPES' ][ 'thread_total_replies' ] = 'cmd' ;
2009-01-09 16:22:08 +00:00
2013-03-24 18:59:18 +01:00
$result = $sql -> update ( 'forum_thread' , $info );
2008-11-29 01:24:27 +00:00
}
2008-12-01 21:11:01 +00:00
2008-12-09 21:46:14 +00:00
if (( $result || ! $updateThread ) && $updateForum )
2008-11-29 01:24:27 +00:00
{
if ( varset ( $postInfo [ 'post_user' ]))
{
$forumInfo [ 'forum_lastpost_user' ] = $postInfo [ 'post_user' ];
$forumInfo [ 'forum_lastpost_user_anon' ] = '_NULL_' ;
}
else
{
$forumInfo [ 'forum_lastpost_user' ] = 0 ;
2008-12-04 21:36:09 +00:00
$forumInfo [ 'forum_lastpost_user_anon' ] = $postInfo [ 'post_user_anon' ];
2008-11-29 01:24:27 +00:00
}
2009-01-09 16:22:08 +00:00
$info = array ();
2008-12-02 21:34:18 +00:00
//If we update the thread, then we assume it was a reply, otherwise we've added a reply only.
2010-03-09 22:40:21 +00:00
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum'];
2008-11-29 01:24:27 +00:00
if ( $updateThread )
{
$forumInfo [ 'forum_replies' ] = 'forum_replies+1' ;
2009-01-09 16:22:08 +00:00
$info [ '_FIELD_TYPES' ][ 'forum_replies' ] = 'cmd' ;
2008-11-29 01:24:27 +00:00
}
else
{
$forumInfo [ 'forum_threads' ] = 'forum_threads+1' ;
2009-01-09 16:22:08 +00:00
$info [ '_FIELD_TYPES' ][ 'forum_threads' ] = 'cmd' ;
2008-11-29 01:24:27 +00:00
}
2009-01-09 16:22:08 +00:00
$info [ 'data' ] = $forumInfo ;
$info [ 'data' ][ 'forum_lastpost_info' ] = $postInfo [ 'post_datestamp' ] . '.' . $postInfo [ 'post_thread' ];
$info [ 'WHERE' ] = 'forum_id = ' . $postInfo [ 'post_forum' ];
2013-03-24 18:59:18 +01:00
$result = $sql -> update ( 'forum' , $info );
2008-11-27 03:02:26 +00:00
}
2008-12-01 21:11:01 +00:00
if ( $result && USER && $addUserPostCount )
{
$qry = '
INSERT INTO `#user_extended` ( user_extended_id , user_plugin_forum_posts )
VALUES ( '.USERID.' , 1 )
ON DUPLICATE KEY UPDATE user_plugin_forum_posts = user_plugin_forum_posts + 1
' ;
2013-03-24 18:59:18 +01:00
$result = $sql -> gen ( $qry );
2008-12-01 21:11:01 +00:00
}
2008-12-07 04:16:39 +00:00
return $postId ;
2008-11-27 03:02:26 +00:00
}
2008-11-29 01:24:27 +00:00
2013-03-12 20:35:04 -07:00
2008-11-27 03:02:26 +00:00
function threadAdd ( $threadInfo , $postInfo )
{
2009-09-08 02:00:48 +00:00
$e107 = e107 :: getInstance ();
2009-01-09 16:22:08 +00:00
$info = array ();
2010-03-09 22:40:21 +00:00
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
2009-01-09 16:22:08 +00:00
$info [ 'data' ] = $threadInfo ;
2013-03-24 18:59:18 +01:00
if ( $newThreadId = e107 :: getDb () -> insert ( 'forum_thread' , $info ))
2009-01-09 16:22:08 +00:00
{
2009-01-10 04:39:54 +00:00
$postInfo [ 'post_thread' ] = $newThreadId ;
2008-12-07 04:16:39 +00:00
$newPostId = $this -> postAdd ( $postInfo , false );
2008-12-18 17:10:48 +00:00
$this -> threadMarkAsRead ( $newThreadId );
2008-12-07 04:16:39 +00:00
return array ( 'postid' => $newPostId , 'threadid' => $newThreadId );
2008-11-27 03:02:26 +00:00
}
2008-12-05 20:28:05 +00:00
return false ;
2008-11-27 03:02:26 +00:00
}
2008-11-29 01:24:27 +00:00
2013-03-12 20:35:04 -07:00
2010-03-13 20:38:40 +00:00
function threadMove ( $threadId , $newForumId , $threadTitle = '' , $titleType = 0 )
{
$sql = e107 :: getDb ();
$threadInfo = $this -> threadGet ( $threadId );
$oldForumId = $threadInfo [ 'thread_forum_id' ];
//Move thread to new forum, changing thread title if needed
if ( $threadTitle )
{
if ( $titleType == 0 )
{
//prepend to existing title
$threadTitle = " , thread_name = CONCAT(' { $threadTitle } ', thread_name) " ;
}
else
{
//Replace title
$threadTitle = " , thread_name = ' { $threadTitle } ' " ;
}
}
2013-03-12 20:35:04 -07:00
$sql -> update ( 'forum_thread' , " thread_forum_id= { $newForumId } { $threadTitle } WHERE thread_id= { $threadId } " );
2010-03-13 20:38:40 +00:00
//Move all posts to new forum
2013-03-12 20:35:04 -07:00
$posts = $sql -> update ( 'forum_post' , " post_forum= { $newForumId } WHERE post_thread= { $threadId } " );
2010-03-13 20:38:40 +00:00
$replies = $posts - 1 ;
if ( $replies < 0 ) { $replies = 0 ; }
//change thread counts accordingly
2013-03-12 20:35:04 -07:00
$sql -> update ( 'forum' , " forum_threads=forum_threads-1, forum_replies=forum_replies- $replies WHERE forum_id= { $oldForumId } " );
$sql -> update ( 'forum' , " forum_threads=forum_threads+1, forum_replies=forum_replies+ $replies WHERE forum_id= { $newForumId } " );
2010-03-13 20:38:40 +00:00
// update lastpost information for old and new forums
$this -> forumUpdateLastpost ( 'forum' , $oldForumId , false );
$this -> forumUpdateLastpost ( 'forum' , $newForumId , false );
}
2013-03-12 20:35:04 -07:00
2008-12-13 21:52:19 +00:00
function threadUpdate ( $threadId , $threadInfo )
2008-11-27 03:02:26 +00:00
{
2009-01-09 16:22:08 +00:00
$info = array ();
$info [ 'data' ] = $threadInfo ;
2010-03-09 22:40:21 +00:00
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
2009-01-09 16:22:08 +00:00
$info [ 'WHERE' ] = 'thread_id = ' . ( int ) $threadId ;
2013-03-24 18:59:18 +01:00
e107 :: getDb () -> update ( 'forum_thread' , $info );
2008-11-27 03:02:26 +00:00
}
2008-12-01 21:11:01 +00:00
2013-03-12 20:35:04 -07:00
2008-12-13 21:52:19 +00:00
function postUpdate ( $postId , $postInfo )
{
2009-01-09 16:22:08 +00:00
$info = array ();
$info [ 'data' ] = $postInfo ;
2010-03-09 22:40:21 +00:00
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
2009-01-09 16:22:08 +00:00
$info [ 'WHERE' ] = 'post_id = ' . ( int ) $postId ;
2013-03-24 18:59:18 +01:00
e107 :: getDb () -> update ( 'forum_post' , $info );
2008-12-13 21:52:19 +00:00
}
2013-03-12 20:35:04 -07:00
2008-12-01 01:10:50 +00:00
function threadGet ( $id , $joinForum = true , $uid = USERID )
{
$id = ( int ) $id ;
$uid = ( int ) $uid ;
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2006-12-02 04:36:16 +00:00
2008-12-01 01:10:50 +00:00
if ( $joinForum )
{
2009-09-08 02:00:48 +00:00
//TODO: Fix query to get only forum and parent info needed, with correct naming
2008-12-01 01:10:50 +00:00
$qry = '
2008-12-15 00:29:20 +00:00
SELECT t .* , f .* ,
2008-12-14 03:18:45 +00:00
fp . forum_id as parent_id , fp . forum_name as parent_name ,
2008-12-15 00:29:20 +00:00
sp . forum_id as forum_sub , sp . forum_name as sub_parent ,
2008-12-14 03:18:45 +00:00
tr . track_userid
2008-12-01 01:10:50 +00:00
FROM `#forum_thread` AS t
LEFT JOIN `#forum` AS f ON t . thread_forum_id = f . forum_id
2008-12-14 03:18:45 +00:00
LEFT JOIN `#forum` AS fp ON fp . forum_id = f . forum_parent
LEFT JOIN `#forum` AS sp ON sp . forum_id = f . forum_sub
2008-12-01 21:11:01 +00:00
LEFT JOIN `#forum_track` AS tr ON tr . track_thread = t . thread_id AND tr . track_userid = '.$uid.'
2008-12-01 01:10:50 +00:00
WHERE thread_id = ' . $id ;
}
else
{
$qry = '
SELECT *
FROM `#forum_thread`
WHERE thread_id = ' . $id ;
}
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $qry ))
2008-12-01 01:10:50 +00:00
{
2013-03-24 18:59:18 +01:00
$tmp = $sql -> fetch ( MYSQL_ASSOC );
2008-12-01 01:10:50 +00:00
if ( $tmp )
{
if ( trim ( $tmp [ 'thread_options' ]) != '' )
{
2008-12-07 00:21:21 +00:00
$tmp [ 'thread_options' ] = unserialize ( $tmp [ 'thread_options' ]);
2008-12-01 01:10:50 +00:00
}
return $tmp ;
}
}
return false ;
}
2008-12-01 21:11:01 +00:00
2013-03-12 20:35:04 -07:00
2010-06-21 01:27:26 +00:00
function postGet ( $id , $start , $num = NULL )
2008-12-01 01:10:50 +00:00
{
2008-12-11 21:50:18 +00:00
$id = ( int ) $id ;
2008-12-01 21:11:01 +00:00
$ret = false ;
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-11 21:50:18 +00:00
if ( 'post' === $start )
{
$qry = '
2011-11-28 14:19:19 +00:00
SELECT u . user_name , t . thread_active , t . thread_datestamp , t . thread_name , t . thread_id , p .* FROM `#forum_post` AS p
2008-12-11 21:50:18 +00:00
LEFT JOIN `#forum_thread` AS t ON t . thread_id = p . post_thread
LEFT JOIN `#user` AS u ON u . user_id = p . post_user
WHERE p . post_id = ' . $id ;
}
else
{
$qry = "
SELECT p .* ,
u . user_name , u . user_customtitle , u . user_hideemail , u . user_email , u . user_signature ,
u . user_admin , u . user_image , u . user_join , ue . user_plugin_forum_posts ,
2011-11-28 14:19:19 +00:00
eu . user_name AS edit_name ,
t . thread_name
2008-12-11 21:50:18 +00:00
FROM `#forum_post` AS p
LEFT JOIN `#user` AS u ON p . post_user = u . user_id
LEFT JOIN `#user` AS eu ON p . post_edit_user IS NOT NULL AND p . post_edit_user = eu . user_id
LEFT JOIN `#user_extended` AS ue ON ue . user_extended_id = p . post_user
2011-11-28 14:19:19 +00:00
LEFT JOIN `#forum_thread` AS t ON t . thread_id = p . post_thread
2008-12-11 21:50:18 +00:00
WHERE p . post_thread = { $id }
ORDER BY p . post_datestamp ASC
LIMIT { $start }, { $num }
" ;
}
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $qry ))
2008-12-01 01:10:50 +00:00
{
2008-12-01 21:11:01 +00:00
$ret = array ();
2013-03-24 18:59:18 +01:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2008-12-01 21:11:01 +00:00
{
$ret [] = $row ;
}
2008-12-01 01:10:50 +00:00
}
2008-12-11 21:50:18 +00:00
if ( 'post' === $start ) { return $ret [ 0 ]; }
2008-12-01 21:11:01 +00:00
return $ret ;
2008-12-01 01:10:50 +00:00
}
2008-12-01 21:11:01 +00:00
2008-12-09 21:46:14 +00:00
function threadGetUserPostcount ( $threadId )
{
$threadId = ( int ) $threadId ;
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-09 21:46:14 +00:00
$ret = false ;
$qry = "
SELECT post_user , count ( post_user ) AS post_count FROM `#forum_post`
WHERE post_thread = { $threadId } AND post_user IS NOT NULL
GROUP BY post_user
" ;
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $qry ))
2008-12-09 21:46:14 +00:00
{
$ret = array ();
2013-03-24 18:59:18 +01:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2008-12-09 21:46:14 +00:00
{
$ret [ $row [ 'post_user' ]] = $row [ 'post_count' ];
}
}
return $ret ;
}
2013-03-12 20:35:04 -07:00
2008-12-10 21:00:48 +00:00
function threadGetUserViewed ( $uid = USERID )
{
2009-09-08 02:00:48 +00:00
$e107 = e107 :: getInstance ();
2008-12-10 21:00:48 +00:00
if ( $uid == USERID )
{
2009-09-08 02:00:48 +00:00
$viewed = $e107 -> currentUser [ 'user_plugin_forum_viewed' ];
2008-12-10 21:00:48 +00:00
}
else
{
2013-03-31 04:23:11 -07:00
$tmp = e107 :: user ( $uid );
2008-12-17 04:22:37 +00:00
$viewed = $tmp [ 'user_plugin_forum_viewed' ];
2008-12-10 21:00:48 +00:00
unset ( $tmp );
}
return explode ( ',' , $viewed );
2008-12-11 16:02:05 +00:00
}
2008-12-10 21:00:48 +00:00
2013-03-12 20:35:04 -07:00
2008-12-11 16:02:05 +00:00
function postDeleteAttachments ( $type = 'post' , $id = '' , $f = '' )
{
$e107 = e107 :: getInstance ();
2013-03-29 00:03:36 +01:00
$sql = e107 :: getDb ();
2013-03-24 18:59:18 +01:00
2008-12-11 16:02:05 +00:00
$id = ( int ) $id ;
if ( ! $id ) { return ; }
if ( $type == 'thread' )
{
2013-03-24 18:59:18 +01:00
if ( ! $sql -> select ( 'forum_post' , 'post_id' , 'post_attachments IS NOT NULL' ))
2008-12-11 16:02:05 +00:00
{
return true ;
}
$postList = array ();
2013-03-24 18:59:18 +01:00
while ( $row = $sql -> Fetch ( MYSQL_ASSOC ))
2008-12-11 16:02:05 +00:00
{
$postList [] = $row [ 'post_id' ];
}
foreach ( $postList as $postId )
{
$this -> postDeleteAttachment ( 'post' , $postId );
}
}
if ( $type == 'post' )
{
2013-03-24 18:59:18 +01:00
if ( ! $sql -> select ( 'forum_post' , 'post_attachments' , 'post_id = ' . $id ))
2008-12-11 16:02:05 +00:00
{
return true ;
}
2013-03-24 18:59:18 +01:00
$tmp = $sql -> fetch ( MYSQL_ASSOC );
2008-12-11 16:02:05 +00:00
$attachments = explode ( ',' , $tmp [ 'post_attachments' ]);
foreach ( $attachments as $k => $a )
{
$info = explode ( '*' , $a );
if ( '' == $f || $info [ 1 ] == $f )
{
$fname = e_PLUGIN . " forum/attachments/ { $info [ 1 ] } " ;
@ unlink ( $fname );
//If attachment is an image and there is a thumb, remove it
if ( 'img' == $info [ 0 ] && $info [ 2 ])
{
$fname = e_PLUGIN . " forum/attachments/thumb/ { $info [ 2 ] } " ;
@ unlink ( $fname );
}
}
unset ( $attachments [ $k ]);
}
$tmp = array ();
if ( count ( $attachments ))
{
$tmp [ 'post_attachments' ] = implode ( ',' , $attachments );
}
else
{
$tmp [ 'post_attachments' ] = '_NULL_' ;
}
2009-01-09 16:22:08 +00:00
$info = array ();
$info [ 'data' ] = $tmp ;
2013-03-31 00:43:18 -07:00
$info [ '_FILE_TYPES' ][ 'post_attachments' ] = 'array' ;
2009-01-09 16:22:08 +00:00
$info [ 'WHERE' ] = 'post_id = ' . $id ;
2013-03-24 18:59:18 +01:00
$sql -> update ( 'forum_post' , $info );
2008-12-11 16:02:05 +00:00
}
2008-12-10 21:00:48 +00:00
}
2008-12-09 21:46:14 +00:00
2013-03-12 20:35:04 -07:00
2008-12-13 21:52:19 +00:00
/**
* Given threadId and postId , determine which number of post in thread the postid is
2008-12-15 00:29:20 +00:00
*
2008-12-13 21:52:19 +00:00
*/
function postGetPostNum ( $threadId , $postId )
{
$threadId = ( int ) $threadId ;
$postId = ( int ) $postId ;
2013-03-24 18:59:18 +01:00
return e107 :: getDb () -> count ( 'forum_post' , '(*)' , " WHERE post_id <= { $postId } AND post_thread = { $threadId } ORDER BY post_id ASC " );
2008-12-13 21:52:19 +00:00
}
2013-03-12 20:35:04 -07:00
2008-12-24 04:51:27 +00:00
function forumUpdateLastpost ( $type , $id , $updateThreads = false )
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2006-12-02 04:36:16 +00:00
$sql2 = new db ;
if ( $type == 'thread' )
{
2008-12-11 16:02:05 +00:00
$id = ( int ) $id ;
$lpInfo = $this -> threadGetLastpost ( $id );
$tmp = array ();
if ( $lpInfo [ 'user_name' ])
2006-12-02 04:36:16 +00:00
{
2008-12-11 16:02:05 +00:00
$tmp [ 'thread_lastuser' ] = $lpInfo [ 'post_user' ];
$tmp [ 'thread_lastuser_anon' ] = '_NULL_' ;
2006-12-02 04:36:16 +00:00
}
2008-12-11 16:02:05 +00:00
else
{
$tmp [ 'thread_lastuser' ] = 0 ;
2008-12-24 04:51:27 +00:00
$tmp [ 'thread_lastuser_anon' ] = ( $lpInfo [ 'post_user_anon' ] ? $lpInfo [ 'post_user_anon' ] : 'Anonymous' );
2008-12-11 16:02:05 +00:00
}
$tmp [ 'thread_lastpost' ] = $lpInfo [ 'post_datestamp' ];
2009-01-09 16:22:08 +00:00
$info = array ();
$info [ 'data' ] = $tmp ;
2010-03-09 22:40:21 +00:00
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_thread'];
2009-01-09 16:22:08 +00:00
$info [ 'WHERE' ] = 'thread_id = ' . $id ;
2013-03-12 20:35:04 -07:00
$sql -> update ( 'forum_thread' , $info );
2008-12-11 16:02:05 +00:00
return $lpInfo ;
2006-12-02 04:36:16 +00:00
}
2008-12-24 04:51:27 +00:00
if ( $type == 'forum' )
{
2006-12-02 04:36:16 +00:00
if ( $id == 'all' )
{
2013-03-24 18:59:18 +01:00
if ( $sql -> select ( 'forum' , 'forum_id' , 'forum_parent != 0' ))
2006-12-02 04:36:16 +00:00
{
2013-03-12 20:35:04 -07:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2006-12-02 04:36:16 +00:00
{
$parentList [] = $row [ 'forum_id' ];
}
foreach ( $parentList as $id )
{
2008-12-24 04:51:27 +00:00
set_time_limit ( 60 );
$this -> forumUpdateLastpost ( 'forum' , $id , $updateThreads );
2006-12-02 04:36:16 +00:00
}
}
}
else
{
2008-12-09 21:46:14 +00:00
$id = ( int ) $id ;
$lp_info = '' ;
$lp_user = 'NULL' ;
2008-12-24 04:51:27 +00:00
if ( $updateThreads == true )
2006-12-02 04:36:16 +00:00
{
2013-04-18 20:26:37 +02:00
if ( $sql2 -> select ( 'forum_t' , 'thread_id' , " thread_forum_id = $id AND thread_parent = 0 " )) // forum_t used in forum_update
2006-12-02 04:36:16 +00:00
{
2013-03-12 20:35:04 -07:00
while ( $row = $sql2 -> fetch ( MYSQL_ASSOC ))
2006-12-02 04:36:16 +00:00
{
2008-12-24 04:51:27 +00:00
set_time_limit ( 60 );
$this -> forumUpdateLastpost ( 'thread' , $row [ 'thread_id' ]);
2006-12-02 04:36:16 +00:00
}
}
}
2013-03-24 18:59:18 +01:00
if ( $sql -> select ( 'forum_thread' , 'thread_id, thread_lastuser, thread_lastuser_anon, thread_datestamp' , 'thread_forum_id=' . $id . ' ORDER BY thread_datestamp DESC LIMIT 1' ))
2006-12-02 04:36:16 +00:00
{
2013-03-12 20:35:04 -07:00
$row = $sql -> fetch ( MYSQL_ASSOC );
2008-12-09 21:46:14 +00:00
$lp_info = $row [ 'thread_datestamp' ] . '.' . $row [ 'thread_id' ];
$lp_user = $row [ 'thread_lastuser' ];
}
if ( $row [ 'thread_lastuser_anon' ])
{
2013-03-28 00:43:00 -07:00
$sql -> update ( 'forum' , " forum_lastpost_user = 0, forum_lastpost_user_anon = ' { $row [ 'thread_lastuser_anon' ] } ', forum_lastpost_info = ' { $lp_info } ' WHERE forum_id= " . $id );
2008-12-09 21:46:14 +00:00
}
else
{
2013-03-12 20:35:04 -07:00
$sql -> update ( 'forum' , " forum_lastpost_user = { $lp_user } , forum_lastpost_user_anon = NULL, forum_lastpost_info = ' { $lp_info } ' WHERE forum_id= " . $id );
2006-12-02 04:36:16 +00:00
}
}
}
}
2013-03-12 20:35:04 -07:00
2008-12-17 04:22:37 +00:00
function forumMarkAsRead ( $forum_id )
2007-09-29 20:52:13 +00:00
{
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-17 04:22:37 +00:00
$extra = '' ;
$newIdList = array ();
if ( $forum_id !== 0 )
2007-09-29 20:52:13 +00:00
{
2008-12-17 04:22:37 +00:00
$forum_id = ( int ) $forum_id ;
$flist = array ();
$flist [] = $forum_id ;
if ( $subList = $this -> forumGetSubs ( $forum_id ))
{
foreach ( $subList as $sub )
{
$flist [] = $sub [ 'forum_id' ];
}
}
$forumList = implode ( ',' , $flist );
$extra = " AND thread_forum_id IN( $forumList ) " ;
}
$qry = 'thread_lastpost > ' . USERLV . $extra ;
2008-12-23 20:48:24 +00:00
2013-03-24 18:59:18 +01:00
if ( $sql -> select ( 'forum_thread' , 'thread_id' , $qry ))
2008-12-17 04:22:37 +00:00
{
2013-03-24 18:59:18 +01:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2008-12-17 04:22:37 +00:00
{
$newIdList [] = $row [ 'thread_id' ];
}
if ( count ( $newIdList ))
{
$this -> threadMarkAsRead ( $newIdList );
}
2006-12-02 04:36:16 +00:00
}
2008-12-17 04:22:37 +00:00
header ( 'location:' . e_SELF );
2007-09-29 20:52:13 +00:00
exit ;
2006-12-02 04:36:16 +00:00
}
2013-03-12 20:35:04 -07:00
2008-12-02 21:34:18 +00:00
function threadMarkAsRead ( $threadId )
2006-12-02 04:36:16 +00:00
{
2008-12-15 00:29:20 +00:00
global $currentUser ;
2013-03-24 18:59:18 +01:00
2008-12-15 00:29:20 +00:00
$_tmp = preg_split ( '#\,+#' , $currentUser [ 'user_plugin_forum_viewed' ]);
2008-12-17 04:22:37 +00:00
if ( ! is_array ( $threadId )) { $threadId = array ( $threadId ); }
foreach ( $threadId as $tid )
{
$_tmp [] = ( int ) $tid ;
}
2008-12-15 00:29:20 +00:00
$tmp = array_unique ( $tmp );
$viewed = trim ( implode ( ',' , $_tmp ), ',' );
2013-03-24 18:59:18 +01:00
return e107 :: getDb () -> update ( 'user_extended' , " user_plugin_forum_viewed = ' { $viewed } ' WHERE user_extended_id = " . USERID );
2006-12-02 04:36:16 +00:00
}
2013-03-12 20:35:04 -07:00
2006-12-02 04:36:16 +00:00
function forum_getparents ()
{
2013-03-24 18:59:18 +01:00
if ( e107 :: getDb () -> select ( 'forum' , '*' , 'forum_parent=0 ORDER BY forum_order ASC' ))
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
while ( $row = e107 :: getDb () -> fetch ( MYSQL_ASSOC )) {
2006-12-02 04:36:16 +00:00
$ret [] = $row ;
}
return $ret ;
}
return FALSE ;
}
2013-03-12 20:35:04 -07:00
2009-01-25 17:44:13 +00:00
function forumGetMods ( $uclass = e_UC_ADMIN , $force = false )
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2009-01-25 17:44:13 +00:00
if ( count ( $this -> modArray ) && ! $force )
{
return $this -> modArray ;
}
2006-12-02 04:36:16 +00:00
if ( $uclass == e_UC_ADMIN || trim ( $uclass ) == '' )
{
2013-03-24 18:59:18 +01:00
$sql -> select ( 'user' , 'user_id, user_name' , 'user_admin = 1 ORDER BY user_name ASC' );
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2008-12-04 21:36:09 +00:00
{
2009-01-25 17:44:13 +00:00
$this -> modArray [ $row [ 'user_id' ]] = $row [ 'user_name' ];
2008-12-04 21:36:09 +00:00
}
2006-12-02 04:36:16 +00:00
}
else
{
2009-01-25 17:44:13 +00:00
$this -> modArray = $this -> e107 -> user_class -> get_users_in_class ( $uclass , 'user_name' , true );
2006-12-02 04:36:16 +00:00
}
2009-01-25 17:44:13 +00:00
return $this -> modArray ;
}
2010-03-13 20:38:40 +00:00
2013-03-12 20:35:04 -07:00
2009-01-25 17:44:13 +00:00
function isModerator ( $uid )
{
2011-04-21 13:20:22 +00:00
return ( $uid && in_array ( $uid , array_keys ( $this -> forumGetMods ())));
2006-12-02 04:36:16 +00:00
}
2013-03-12 20:35:04 -07:00
2010-03-14 00:50:27 +00:00
function forumGetForumList ( $all = false )
2008-12-17 04:22:37 +00:00
{
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2010-03-14 00:50:27 +00:00
$where = ( $all ? '' : " WHERE forum_id IN ( { $this -> permList [ 'view_list' ] } ) " );
2008-12-17 04:22:37 +00:00
$qry = '
SELECT f .* , u . user_name FROM `#forum` AS f
LEFT JOIN `#user` AS u ON f . forum_lastpost_user IS NOT NULL AND u . user_id = f . forum_lastpost_user
2010-03-14 00:50:27 +00:00
' . $where .
'ORDER BY f.forum_order ASC' ;
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $qry ))
2008-12-17 04:22:37 +00:00
{
$ret = array ();
2013-03-24 18:59:18 +01:00
while ( $row = $sql -> fetch ())
2008-12-17 04:22:37 +00:00
{
if ( ! $row [ 'forum_parent' ])
{
$ret [ 'parents' ][] = $row ;
}
elseif ( $row [ 'forum_sub' ])
{
$ret [ 'subs' ][ $row [ 'forum_sub' ]][] = $row ;
}
else
{
$ret [ 'forums' ][ $row [ 'forum_parent' ]][] = $row ;
}
}
return $ret ;
}
return false ;
}
2013-03-12 20:35:04 -07:00
2006-12-02 04:36:16 +00:00
function forum_getforums ( $type = 'all' )
{
2013-03-29 00:03:36 +01:00
$sql = e107 :: getDb ();
2006-12-02 04:36:16 +00:00
$qry = "
SELECT f .* , u . user_name FROM #forum AS f
LEFT JOIN #user AS u ON SUBSTRING_INDEX(f.forum_lastpost_user,'.',1) = u.user_id
WHERE forum_parent != 0 AND forum_sub = 0
ORDER BY f . forum_order ASC
" ;
2013-03-12 20:35:04 -07:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2013-03-12 20:35:04 -07:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2006-12-02 04:36:16 +00:00
{
if ( $type == 'all' )
{
$ret [ $row [ 'forum_parent' ]][] = $row ;
}
else
{
$ret [] = $row ;
}
}
return $ret ;
}
return FALSE ;
}
2013-03-12 20:35:04 -07:00
2008-12-15 00:29:20 +00:00
function forumGetSubs ( $forum_id = '' )
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-15 00:29:20 +00:00
$where = ( $forum_id != '' && $forum_id != 'bysub' ? 'AND forum_sub = ' . ( int ) $forum_id : '' );
2006-12-02 04:36:16 +00:00
$qry = "
2008-12-15 00:29:20 +00:00
SELECT f .* , u . user_name FROM `#forum` AS f
LEFT JOIN `#user` AS u ON f . forum_lastpost_user = u . user_id
2006-12-02 04:36:16 +00:00
WHERE forum_sub != 0 { $where }
ORDER BY f . forum_order ASC
" ;
2013-03-12 20:35:04 -07:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2013-03-12 20:35:04 -07:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2006-12-02 04:36:16 +00:00
{
2008-12-15 00:29:20 +00:00
if ( $forum_id == '' )
2006-12-02 04:36:16 +00:00
{
$ret [ $row [ 'forum_parent' ]][ $row [ 'forum_sub' ]][] = $row ;
}
elseif ( $forum_id == 'bysub' )
{
$ret [ $row [ 'forum_sub' ]][] = $row ;
}
else
{
$ret [] = $row ;
}
}
return $ret ;
}
2008-11-26 03:24:51 +00:00
return false ;
2006-12-02 04:36:16 +00:00
}
2013-03-12 20:35:04 -07:00
2008-12-17 04:22:37 +00:00
/**
* List of forums with unread threads
*
* Get a list of forum IDs that have unread threads .
* If a forum is a subforum , also ensure the parent is in the list .
*
* @ return type description
* @ access public
*/
function forumGetUnreadForums ()
2006-12-02 04:36:16 +00:00
{
2008-12-17 04:22:37 +00:00
if ( ! USER ) { return false ; } // Can't determine new threads for non-logged in users
$e107 = e107 :: getInstance ();
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-17 04:22:37 +00:00
$viewed = '' ;
if ( $e107 -> currentUser [ 'user_plugin_forum_viewed' ])
2006-12-02 04:36:16 +00:00
{
2008-12-17 04:22:37 +00:00
$viewed = " AND thread_id NOT IN ( " . $e107 -> currentUser [ 'user_plugin_forum_viewed' ] . " ) " ;
2006-12-02 04:36:16 +00:00
}
2008-12-17 04:22:37 +00:00
$_newqry = '
SELECT DISTINCT f . forum_sub , ft . thread_forum_id FROM `#forum_thread` AS ft
LEFT JOIN `#forum` AS f ON f . forum_id = ft . thread_forum_id
WHERE ft . thread_lastpost > '.USERLV.' ' . $viewed ;
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $_newqry ))
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2006-12-02 04:36:16 +00:00
{
$ret [] = $row [ 'thread_forum_id' ];
if ( $row [ 'forum_sub' ])
{
$ret [] = $row [ 'forum_sub' ];
}
}
return $ret ;
}
else
{
2008-12-17 04:22:37 +00:00
return false ;
2006-12-02 04:36:16 +00:00
}
}
2008-12-23 20:48:24 +00:00
2013-03-12 20:35:04 -07:00
2006-12-02 04:36:16 +00:00
function thread_user ( $post_info )
{
if ( $post_info [ 'user_name' ])
{
return $post_info [ 'user_name' ];
}
else
{
$tmp = explode ( " . " , $post_info [ 'thread_user' ], 2 );
return $tmp [ 1 ];
}
}
2013-03-12 20:35:04 -07:00
2008-12-23 20:48:24 +00:00
function track ( $which , $uid , $threadId , $force = false )
2006-12-02 04:36:16 +00:00
{
2008-12-01 01:10:50 +00:00
$e107 = e107 :: getInstance ();
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-04 21:36:09 +00:00
2010-03-09 22:40:21 +00:00
if ( $this -> prefs -> get ( 'track' ) != 1 && ! $force ) { return false ; }
2008-12-04 21:36:09 +00:00
2008-11-26 04:00:36 +00:00
$threadId = ( int ) $threadId ;
$uid = ( int ) $uid ;
$result = false ;
switch ( $which )
{
case 'add' :
$tmp = array ();
2009-01-09 16:22:08 +00:00
$tmp [ 'data' ][ 'track_userid' ] = $uid ;
$tmp [ 'data' ][ 'track_thread' ] = $threadId ;
2013-03-24 18:59:18 +01:00
$result = $sql -> insert ( 'forum_track' , $tmp );
2008-11-26 04:00:36 +00:00
unset ( $tmp );
break ;
2008-11-26 19:59:06 +00:00
2008-11-26 04:00:36 +00:00
case 'delete' :
case 'del' :
2013-03-24 18:59:18 +01:00
$result = $sql -> delete ( 'forum_track' , " `track_userid` = { $uid } AND `track_thread` = { $threadId } " );
2008-11-26 04:00:36 +00:00
break ;
2008-12-01 01:10:50 +00:00
case 'check' :
2013-03-24 18:59:18 +01:00
$result = $sql -> count ( 'forum_track' , '(*)' , " WHERE `track_userid` = { $uid } AND `track_thread` = { $threadId } " );
2008-12-01 01:10:50 +00:00
break ;
2008-11-26 04:00:36 +00:00
}
return $result ;
2006-12-02 04:36:16 +00:00
}
2013-03-12 20:35:04 -07:00
2010-03-14 00:50:27 +00:00
function forumGet ( $forum_id )
2006-12-02 04:36:16 +00:00
{
2010-03-14 00:50:27 +00:00
$sql = e107 :: getDb ();
2008-11-27 03:02:26 +00:00
$forum_id = ( int ) $forum_id ;
2006-12-02 04:36:16 +00:00
$qry = "
SELECT f .* , fp . forum_class as parent_class , fp . forum_name as parent_name , fp . forum_id as parent_id , fp . forum_postclass as parent_postclass , sp . forum_name AS sub_parent FROM #forum AS f
LEFT JOIN #forum AS fp ON fp.forum_id = f.forum_parent
LEFT JOIN #forum AS sp ON f.forum_sub = sp.forum_id AND f.forum_sub > 0
WHERE f . forum_id = { $forum_id }
" ;
2013-03-12 20:35:04 -07:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2013-03-12 20:35:04 -07:00
return $sql -> fetch ( MYSQL_ASSOC );
2006-12-02 04:36:16 +00:00
}
return FALSE ;
}
2013-03-12 20:35:04 -07:00
2008-12-18 14:08:33 +00:00
function forumGetAllowed ( $type = 'view' )
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-18 14:08:33 +00:00
$forumList = implode ( ',' , $this -> permList [ $type ]);
2006-12-02 04:36:16 +00:00
$qry = "
2008-12-18 14:08:33 +00:00
SELECT forum_id , forum_name FROM `#forum`
WHERE forum_id IN ({ $forumList })
2006-12-02 04:36:16 +00:00
" ;
2013-03-12 20:35:04 -07:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2013-03-12 20:35:04 -07:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2006-12-02 04:36:16 +00:00
{
$ret [ $row [ 'forum_id' ]] = $row [ 'forum_name' ];
}
}
return $ret ;
}
2013-03-12 20:35:04 -07:00
2008-12-02 21:34:18 +00:00
function forumGetThreads ( $forumId , $from , $view )
2006-12-02 04:36:16 +00:00
{
2009-09-08 02:00:48 +00:00
$e107 = e107 :: getInstance ();
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-02 21:34:18 +00:00
$forumId = ( int ) $forumId ;
2006-12-02 04:36:16 +00:00
$qry = "
2008-11-27 03:02:26 +00:00
SELECT t .* , u . user_name , lpu . user_name AS lastpost_username from `#forum_thread` as t
LEFT JOIN `#user` AS u ON t . thread_user = u . user_id
LEFT JOIN `#user` AS lpu ON t . thread_lastuser = lpu . user_id
2008-12-02 21:34:18 +00:00
WHERE t . thread_forum_id = { $forumId }
2006-12-02 04:36:16 +00:00
ORDER BY
2008-12-15 00:29:20 +00:00
t . thread_sticky DESC ,
2008-11-27 03:02:26 +00:00
t . thread_lastpost DESC
2009-09-08 02:00:48 +00:00
LIMIT " .(int) $from .','.(int) $view ;
2008-11-29 01:24:27 +00:00
2009-09-08 02:00:48 +00:00
$ret = array ();
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2006-12-02 04:36:16 +00:00
{
2009-09-08 02:00:48 +00:00
$ret [] = $row ;
2006-12-02 04:36:16 +00:00
}
}
2009-09-08 02:00:48 +00:00
return $ret ;
2006-12-02 04:36:16 +00:00
}
2013-03-12 20:35:04 -07:00
2008-12-11 16:02:05 +00:00
function threadGetLastpost ( $id )
2006-12-02 04:36:16 +00:00
{
2008-12-11 16:02:05 +00:00
$e107 = e107 :: getInstance ();
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-11 16:02:05 +00:00
$id = ( int ) $id ;
2006-12-02 04:36:16 +00:00
$qry = "
2008-12-11 16:02:05 +00:00
SELECT p . post_user , p . post_user_anon , p . post_datestamp , p . post_thread , u . user_name FROM `#forum_post` AS p
LEFT JOIN `#user` AS u ON u . user_id = p . post_user
WHERE p . post_thread = { $id }
ORDER BY p . post_datestamp DESC LIMIT 0 , 1
2006-12-02 04:36:16 +00:00
" ;
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
return $sql -> fetch ( MYSQL_ASSOC );
2006-12-02 04:36:16 +00:00
}
2008-12-11 16:02:05 +00:00
return false ;
2006-12-02 04:36:16 +00:00
}
2008-12-02 21:34:18 +00:00
// function forum_get_topic_count($forum_id)
// {
// $e107 = e107::getInstance();
2013-03-24 18:59:18 +01:00
// return $sql->count('forum_thread', '(*)', 'WHERE thread_forum_id='.(int)$forum_id);
2008-12-02 21:34:18 +00:00
// }
2006-12-02 04:36:16 +00:00
2013-03-12 20:35:04 -07:00
2008-12-04 21:36:09 +00:00
function threadGetNextPrev ( $which , $threadId , $forumId , $lastpost )
2006-12-02 04:36:16 +00:00
{
2008-12-04 21:36:09 +00:00
// echo "threadid = $threadId <br />forum id = $forumId <br />";
// return;
$e107 = e107 :: getInstance ();
2013-03-28 00:43:00 -07:00
$sql = e107 :: getDb ();
2008-12-04 21:36:09 +00:00
$threadId = ( int ) $threadId ;
$forumId = ( int ) $forumId ;
$lastpost = ( int ) $lastpost ;
if ( $which == 'next' )
2006-12-02 04:36:16 +00:00
{
2008-12-04 21:36:09 +00:00
$dir = '<' ;
$sort = 'ASC' ;
}
else
{
$dir = '>' ;
$sort = 'DESC' ;
}
$qry = "
SELECT thread_id from `#forum_thread`
WHERE thread_forum_id = $forumId
AND thread_lastpost { $dir } $lastpost
2006-12-02 04:36:16 +00:00
ORDER BY
2008-12-15 00:29:20 +00:00
thread_sticky DESC ,
2008-12-04 21:36:09 +00:00
thread_lastpost { $sort }
LIMIT 1 " ;
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$row = $sql -> fetch ();
2008-12-04 21:36:09 +00:00
return $row [ 'thread_id' ];
2006-12-02 04:36:16 +00:00
}
2008-12-04 21:36:09 +00:00
return false ;
2006-12-02 04:36:16 +00:00
}
2013-03-12 20:35:04 -07:00
2008-12-01 01:10:50 +00:00
function threadIncView ( $id )
2006-12-02 04:36:16 +00:00
{
2008-12-17 04:22:37 +00:00
$id = ( int ) $id ;
2013-03-12 20:35:04 -07:00
return e107 :: getDb () -> update ( 'forum_thread' , 'thread_views=thread_views+1 WHERE thread_id=' . $id );
2006-12-02 04:36:16 +00:00
}
2013-03-12 20:35:04 -07:00
2006-12-02 04:36:16 +00:00
function _forum_lp_update ( $lp_type , $lp_user , $lp_info , $lp_forum_id , $lp_forum_sub )
{
2011-04-26 11:27:36 +00:00
$sql = e107 :: getDb ();
2013-03-12 20:35:04 -07:00
$sql -> update ( 'forum' , " { $lp_type } = { $lp_type } +1, forum_lastpost_user=' { $lp_user } ', forum_lastpost_info = ' { $lp_info } ' WHERE forum_id=' " . intval ( $lp_forum_id ) . " ' " );
2006-12-02 04:36:16 +00:00
if ( $lp_forum_sub )
{
2013-03-12 20:35:04 -07:00
$sql -> update ( 'forum' , " forum_lastpost_user = ' { $lp_user } ', forum_lastpost_info = ' { $lp_info } ' WHERE forum_id=' " . intval ( $lp_forum_sub ) . " ' " );
2006-12-02 04:36:16 +00:00
}
}
2013-03-12 20:35:04 -07:00
2008-12-18 14:08:33 +00:00
function threadGetNew ( $count = 50 , $unread = true , $uid = USERID )
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-18 14:08:33 +00:00
$viewed = '' ;
if ( $unread )
2006-12-02 04:36:16 +00:00
{
2008-12-18 14:08:33 +00:00
$viewed = implode ( ',' , $this -> threadGetUserViewed ( $uid ));
if ( $viewed != '' )
{
$viewed = ' AND p.post_forum NOT IN (' . $viewed . ')' ;
}
2006-12-02 04:36:16 +00:00
}
$qry = "
SELECT ft .* , fp . thread_name as post_subject , fp . thread_total_replies as replies , u . user_id , u . user_name , f . forum_class
2013-04-18 20:26:37 +02:00
FROM #forum_t AS ft
2013-04-15 12:44:56 +02:00
LEFT JOIN #forum_thread as fp ON fp.thread_id = ft.thread_parent
2006-12-02 04:36:16 +00:00
LEFT JOIN #user as u ON u.user_id = SUBSTRING_INDEX(ft.thread_user,'.',1)
LEFT JOIN #forum as f ON f.forum_id = ft.thread_forum_id
WHERE ft . thread_datestamp > " .USERLV. "
AND f . forum_class IN ( " .USERCLASS_LIST. " )
{ $viewed }
ORDER BY ft . thread_datestamp DESC LIMIT 0 , " .intval( $count );
2008-12-23 20:48:24 +00:00
2008-12-18 14:08:33 +00:00
$qry = "
SELECT t .* , u . user_name FROM `#forum_thread` AS t
LEFT JOIN `#user` AS u ON u . user_id = t . thread_lastuser
WHERE t . thread_lastpost > " .USERLV. "
{ $viewed }
ORDER BY t . thread_lastpost DESC LIMIT 0 , " .(int) $count ;
2008-12-23 20:48:24 +00:00
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$ret = $sql -> db_getList ();
2006-12-02 04:36:16 +00:00
}
return $ret ;
}
2013-03-12 20:35:04 -07:00
2008-12-18 18:32:54 +00:00
function forumPrune ( $type , $days , $forumArray )
2006-12-02 04:36:16 +00:00
{
2008-12-18 18:32:54 +00:00
$e107 = e107 :: getInstance ();
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-18 18:32:54 +00:00
$prunedate = time () - ( int ) $days * 86400 ;
$forumList = implode ( ',' , $forumArray );
2006-12-02 04:36:16 +00:00
if ( $type == 'delete' )
{
//Get list of threads to prune
2013-03-24 18:59:18 +01:00
if ( $sql -> select ( 'forum_thread' , 'thread_id' , " thread_lastpost < { $prunedate } AND thread_sticky != 1 AND thread_forum_id IN ( { $forumList } ) " ))
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$threadList = $sql -> db_getList ();
2006-12-02 04:36:16 +00:00
foreach ( $threadList as $thread )
{
2008-12-18 18:32:54 +00:00
$this -> threadDelete ( $thread [ 'thread_id' ], false );
2006-12-02 04:36:16 +00:00
}
foreach ( $forumArray as $fid )
{
2008-12-18 18:32:54 +00:00
$this -> forumUpdateLastpost ( 'forum' , $fid );
$this -> forumUpdateCounts ( $fid );
2006-12-02 04:36:16 +00:00
}
return FORLAN_8 . " ( " . $thread_count . " " . FORLAN_92 . " , " . $reply_count . " " . FORLAN_93 . " ) " ;
}
else
{
return FORLAN_9 ;
}
}
2007-05-16 20:24:44 +00:00
if ( $type == 'make_inactive' )
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$pruned = $sql -> update ( 'forum_thread' , " thread_active=0 WHERE thread_lastpost < { $prunedate } thread_forum_id IN ( { $forumList } ) " );
2008-12-18 18:32:54 +00:00
return FORLAN_8 . ' ' . $pruned . ' ' . FORLAN_91 ;
2006-12-02 04:36:16 +00:00
}
}
2013-03-12 20:35:04 -07:00
2008-12-18 18:32:54 +00:00
function forumUpdateCounts ( $forumId , $recalcThreads = false )
2006-12-02 04:36:16 +00:00
{
2008-12-18 18:32:54 +00:00
$e107 = e107 :: getInstance ();
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2008-12-18 18:32:54 +00:00
if ( $forumId == 'all' )
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$sql -> select ( 'forum' , 'forum_id' , 'forum_parent != 0' );
$flist = $sql -> db_getList ();
2006-12-02 04:36:16 +00:00
foreach ( $flist as $f )
{
2008-12-24 04:51:27 +00:00
set_time_limit ( 60 );
$this -> forumUpdateCounts ( $f [ 'forum_id' ], $recalcThreads );
2006-12-02 04:36:16 +00:00
}
return ;
}
2008-12-18 18:32:54 +00:00
$forumId = ( int ) $forumId ;
2013-03-24 18:59:18 +01:00
$threads = $sql -> count ( 'forum_thread' , '(*)' , 'WHERE thread_forum_id=' . $forumId );
$replies = $sql -> count ( 'forum_post' , '(*)' , 'WHERE post_forum=' . $forumId );
$sql -> update ( 'forum' , " forum_threads= { $threads } , forum_replies= { $replies } WHERE forum_id= { $forumId } " );
2008-12-24 04:51:27 +00:00
if ( $recalcThreads == true )
2006-12-02 04:36:16 +00:00
{
2008-12-24 04:51:27 +00:00
set_time_limit ( 60 );
2013-03-24 18:59:18 +01:00
$sql -> select ( 'forum_post' , 'post_thread, count(post_thread) AS replies' , " post_forum= { $forumId } GROUP BY post_thread " );
$tlist = $sql -> db_getList ();
2006-12-02 04:36:16 +00:00
foreach ( $tlist as $t )
{
2008-12-18 18:32:54 +00:00
$tid = $t [ 'post_thread' ];
$replies = ( int ) $t [ 'replies' ];
2013-03-24 18:59:18 +01:00
$sql -> update ( 'forum_thread' , " thread_total_replies= { $replies } WHERE thread_id= { $tid } " );
2006-12-02 04:36:16 +00:00
}
}
}
2008-12-23 20:48:24 +00:00
2013-03-12 20:35:04 -07:00
2008-12-18 15:28:59 +00:00
function getUserCounts ()
2006-12-02 04:36:16 +00:00
{
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2006-12-02 04:36:16 +00:00
$qry = "
2008-12-18 15:28:59 +00:00
SELECT post_user , count ( post_user ) AS cnt FROM `#forum_post`
WHERE post_user > 0
GROUP BY post_user
2006-12-02 04:36:16 +00:00
" ;
2013-03-12 20:35:04 -07:00
if ( $sql -> gen ( $qry ))
2006-12-02 04:36:16 +00:00
{
$ret = array ();
2013-03-12 20:35:04 -07:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2006-12-02 04:36:16 +00:00
{
2008-12-18 15:28:59 +00:00
$ret [ $row [ 'post_user' ]] = $row [ 'cnt' ];
2006-12-02 04:36:16 +00:00
}
return $ret ;
}
return FALSE ;
}
2008-11-26 19:59:06 +00:00
2013-03-12 20:35:04 -07:00
2006-12-02 04:36:16 +00:00
/*
* set bread crumb
* $forum_href override ONLY applies when template is missing FORUM_CRUMB
* $thread_title is needed for post - related breadcrumbs
*/
2010-02-01 03:41:59 +00:00
function set_crumb ( $forum_href = false , $thread_title = '' , & $templateVar )
2006-12-02 04:36:16 +00:00
{
2008-12-14 03:18:45 +00:00
$e107 = e107 :: getInstance ();
2013-03-26 12:33:03 +01:00
$tp = e107 :: getParser ();
2011-04-25 11:29:21 +00:00
global $FORUM_CRUMB , $forumInfo , $threadInfo , $thread ;
2006-12-02 04:36:16 +00:00
global $BREADCRUMB , $BACKLINK ; // Eventually we should deprecate BACKLINK
2008-11-26 19:59:06 +00:00
2011-04-25 11:29:21 +00:00
if ( ! $forumInfo && $thread ) { $forumInfo = $thread -> threadInfo ; }
2008-12-14 03:18:45 +00:00
2006-12-02 04:36:16 +00:00
if ( is_array ( $FORUM_CRUMB ))
{
2008-12-14 03:18:45 +00:00
$search = array ( '{SITENAME}' , '{SITENAME_HREF}' );
2013-03-26 12:33:03 +01:00
$replace = array ( SITENAME , e107 :: getUrl () -> create ( '/' ));
2006-12-02 04:36:16 +00:00
$FORUM_CRUMB [ 'sitename' ][ 'value' ] = str_replace ( $search , $replace , $FORUM_CRUMB [ 'sitename' ][ 'value' ]);
2008-11-26 19:59:06 +00:00
2008-12-14 03:18:45 +00:00
$search = array ( '{FORUMS_TITLE}' , '{FORUMS_HREF}' );
2013-03-26 12:33:03 +01:00
$replace = array ( LAN_01 , e107 :: getUrl () -> create ( 'forum/forum/main' ));
2006-12-02 04:36:16 +00:00
$FORUM_CRUMB [ 'forums' ][ 'value' ] = str_replace ( $search , $replace , $FORUM_CRUMB [ 'forums' ][ 'value' ]);
2008-11-26 19:59:06 +00:00
2008-12-14 03:18:45 +00:00
$search = '{PARENT_TITLE}' ;
2013-03-26 12:33:03 +01:00
$replace = $tp -> toHTML ( $forumInfo [ 'parent_name' ]);
2006-12-02 04:36:16 +00:00
$FORUM_CRUMB [ 'parent' ][ 'value' ] = str_replace ( $search , $replace , $FORUM_CRUMB [ 'parent' ][ 'value' ]);
2011-04-25 11:29:21 +00:00
if ( $forumInfo [ 'forum_sub' ])
2006-12-02 04:36:16 +00:00
{
2008-12-14 03:18:45 +00:00
$search = array ( '{SUBPARENT_TITLE}' , '{SUBPARENT_HREF}' );
2013-03-26 12:33:03 +01:00
$replace = array ( ltrim ( $forumInfo [ 'sub_parent' ], '*' ), e107 :: getUrl () -> create ( 'forum/forum/view' , " id= { $forumInfo [ 'forum_sub' ] } " )); // XXX forum sub name
2006-12-02 04:36:16 +00:00
$FORUM_CRUMB [ 'subparent' ][ 'value' ] = str_replace ( $search , $replace , $FORUM_CRUMB [ 'subparent' ][ 'value' ]);
}
else
{
2008-12-14 03:18:45 +00:00
$FORUM_CRUMB [ 'subparent' ][ 'value' ] = '' ;
2006-12-02 04:36:16 +00:00
}
2008-12-14 03:18:45 +00:00
$search = array ( '{FORUM_TITLE}' , '{FORUM_HREF}' );
2011-04-25 11:29:21 +00:00
// TODO - remove 'href=' from the return value
2013-03-26 12:33:03 +01:00
$replace = array ( ltrim ( $forumInfo [ 'forum_name' ], '*' ), e107 :: getUrl () -> create ( 'forum/forum/view' , $forumInfo ));
2006-12-02 04:36:16 +00:00
$FORUM_CRUMB [ 'forum' ][ 'value' ] = str_replace ( $search , $replace , $FORUM_CRUMB [ 'forum' ][ 'value' ]);
2011-04-25 11:29:21 +00:00
$threadInfo [ 'thread_id' ] = intval ( $threadInfo [ 'thread_id' ]);
$search = array ( '{THREAD_TITLE}' , '{THREAD_HREF}' );
2013-03-26 12:33:03 +01:00
$replace = array ( vartrue ( $threadInfo [ 'thread_name' ]), e107 :: getUrl () -> create ( 'forum/thread/view' , $threadInfo )); // $thread->threadInfo - no reference found
2008-12-14 03:18:45 +00:00
$FORUM_CRUMB [ 'thread' ][ 'value' ] = str_replace ( $search , $replace , $FORUM_CRUMB [ 'thread' ][ 'value' ]);
2006-12-02 04:36:16 +00:00
2008-12-14 03:18:45 +00:00
$FORUM_CRUMB [ 'fieldlist' ] = 'sitename,forums,parent,subparent,forum,thread' ;
2013-03-12 04:22:09 -07:00
// $FORUM_CRUMB['style'] = 'bootstrap';
2013-03-26 12:33:03 +01:00
$BREADCRUMB = $tp -> parseTemplate ( '{BREADCRUMB=FORUM_CRUMB}' , true );
2006-12-02 04:36:16 +00:00
}
else
{
2008-12-14 03:18:45 +00:00
$dfltsep = ' :: ' ;
2006-12-02 04:36:16 +00:00
$BREADCRUMB = " <a class='forumlink' href=' " . e_BASE . " index.php'> " . SITENAME . " </a> " . $dfltsep . " <a class='forumlink' href=' " . e_PLUGIN . " forum/forum.php'> " . LAN_01 . " </a> " . $dfltsep ;
2011-04-25 11:29:21 +00:00
if ( $forumInfo [ 'sub_parent' ])
2006-12-02 04:36:16 +00:00
{
2011-04-25 11:29:21 +00:00
$forum_sub_parent = ( substr ( $forumInfo [ 'sub_parent' ], 0 , 1 ) == '*' ? substr ( $forumInfo [ 'sub_parent' ], 1 ) : $forumInfo [ 'sub_parent' ]);
$BREADCRUMB .= " <a class='forumlink' href=' " . e_PLUGIN . " forum/forum_viewforum.php? { $forumInfo [ 'forum_sub' ] } '> { $forum_sub_parent } </a> " . $dfltsep ;
2006-12-02 04:36:16 +00:00
}
2008-11-26 19:59:06 +00:00
2011-04-25 11:29:21 +00:00
$tmpFname = $forumInfo [ 'forum_name' ];
2006-12-02 04:36:16 +00:00
if ( substr ( $tmpFname , 0 , 1 ) == " * " ) { $tmpFname = substr ( $tmpFname , 1 ); }
if ( $forum_href )
{
2013-03-26 12:33:03 +01:00
$BREADCRUMB .= " <a class='forumlink' href=' " . e_PLUGIN . " forum/forum_viewforum.php? { $forumInfo [ 'forum_id' ] } '> " . $tp -> toHTML ( $tmpFname , TRUE , 'no_hook,emotes_off' ) . " </a> " ;
2006-12-02 04:36:16 +00:00
} else
{
$BREADCRUMB .= $tmpFname ;
}
if ( strlen ( $thread_title ))
{
$BREADCRUMB .= $dfltsep . $thread_title ;
}
}
$BACKLINK = $BREADCRUMB ;
2010-02-01 03:41:59 +00:00
$templateVar -> BREADCRUMB = $BREADCRUMB ;
$templateVar -> BACKLINK = $BACKLINK ;
$templateVar -> FORUM_CRUMB = $FORUM_CRUMB ;
2006-12-02 04:36:16 +00:00
}
2008-12-23 20:48:24 +00:00
2013-03-12 20:35:04 -07:00
/**
* Delete a Thread
* @ param $threadId integer
* @ param $updateForumLastPost boolean
* @ return true on success or false on error .
*/
2008-12-18 18:32:54 +00:00
function threadDelete ( $threadId , $updateForumLastpost = true )
{
2013-03-24 18:59:18 +01:00
$e107 = e107 :: getInstance ();
2013-03-12 20:35:04 -07:00
$sql = e107 :: getDb ();
$status = false ;
2008-12-18 18:32:54 +00:00
if ( $threadInfo = $this -> threadGet ( $threadId ))
{
// delete poll if there is one
2013-03-12 20:35:04 -07:00
$sql -> delete ( 'poll' , 'poll_datestamp=' . $threadId );
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
//decrement user post counts
if ( $postCount = $this -> threadGetUserPostcount ( $threadId ))
{
foreach ( $postCount as $k => $v )
{
2013-03-12 20:35:04 -07:00
$sql -> update ( 'user_extended' , 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-' . $v . ',0) WHERE user_extended_id=' . $k );
2008-12-18 18:32:54 +00:00
}
}
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
// delete all posts
$qry = 'SELECT post_id FROM `#forum_post` WHERE post_thread = ' . $threadId ;
2013-03-12 20:35:04 -07:00
if ( $sql -> gen ( $qry ))
2008-12-18 18:32:54 +00:00
{
$postList = array ();
2013-03-12 20:35:04 -07:00
while ( $row = $sql -> fetch ( MYSQL_ASSOC ))
2008-12-18 18:32:54 +00:00
{
$postList [] = $row [ 'post_id' ];
}
foreach ( $postList as $postId )
{
$this -> postDelete ( $postId , false );
}
}
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
// delete the thread itself
2013-03-12 20:35:04 -07:00
if ( $sql -> delete ( 'forum_thread' , 'thread_id=' . $threadId ))
{
$status = true ;
}
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
//Delete any thread tracking
2013-03-12 20:35:04 -07:00
$sql -> delete ( 'forum_track' , 'track_thread=' . $threadId );
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
// update forum with correct thread/reply counts
2013-03-12 20:35:04 -07:00
$sql -> update ( 'forum' , " forum_threads=GREATEST(forum_threads-1,0), forum_replies=GREATEST(forum_replies- { $threadInfo [ 'thread_total_replies' ] } ,0) WHERE forum_id= " . $threadInfo [ 'thread_forum_id' ]);
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
if ( $updateForumLastpost )
{
// update lastpost info
$this -> forumUpdateLastpost ( 'forum' , $threadInfo [ 'thread_forum_id' ]);
}
2013-03-12 20:35:04 -07:00
return $status ; // - XXX should return true/false $threadInfo['thread_total_replies'];
2008-12-18 18:32:54 +00:00
}
}
2008-12-23 20:48:24 +00:00
2013-03-12 20:35:04 -07:00
/**
* Delete a Post
* @ param $postId integer
* @ param $updateCounts boolean
*
*/
2008-12-18 18:32:54 +00:00
function postDelete ( $postId , $updateCounts = true )
{
2013-03-14 16:25:24 -07:00
$postId = ( int ) $postId ;
2013-03-24 18:59:18 +01:00
$e107 = e107 :: getInstance ();
2013-03-14 16:25:24 -07:00
$sql = e107 :: getDb ();
$deleted = false ;
2013-03-24 18:59:18 +01:00
if ( ! $sql -> select ( 'forum_post' , '*' , 'post_id = ' . $postId ))
2008-12-18 18:32:54 +00:00
{
echo 'NOT FOUND!' ; return ;
}
2013-03-14 16:25:24 -07:00
$row = $sql -> fetch ( MYSQL_ASSOC );
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
//delete attachments if they exist
if ( $row [ 'post_attachments' ])
{
$this -> postDeleteAttachments ( 'post' , $postId );
}
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
// delete post
2013-03-14 16:25:24 -07:00
if ( $sql -> delete ( 'forum_post' , 'post_id=' . $postId ))
{
$deleted = true ;
}
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
if ( $updateCounts )
{
//decrement user post counts
if ( $row [ 'post_user' ])
{
2013-03-24 18:59:18 +01:00
$sql -> update ( 'user_extended' , 'user_plugin_forum_posts=GREATEST(user_plugin_forum_posts-1,0) WHERE user_extended_id=' . $row [ 'post_user' ]);
2008-12-18 18:32:54 +00:00
}
// update thread with correct reply counts
2013-03-24 18:59:18 +01:00
$sql -> update ( 'forum_thread' , " thread_total_replies=GREATEST(thread_total_replies-1,0) WHERE thread_id= " . $row [ 'post_thread' ]);
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
// update forum with correct thread/reply counts
2013-03-24 18:59:18 +01:00
$sql -> update ( 'forum' , " forum_replies=GREATEST(forum_replies-1,0) WHERE forum_id= " . $row [ 'post_forum' ]);
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
// update thread lastpost info
$this -> forumUpdateLastpost ( 'thread' , $row [ 'post_thread' ]);
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
// update forum lastpost info
$this -> forumUpdateLastpost ( 'forum' , $row [ 'post_forum' ]);
}
2013-03-14 16:25:24 -07:00
return $deleted ; // return boolean. $threadInfo['thread_total_replies'];
2008-12-18 18:32:54 +00:00
}
2008-12-23 20:48:24 +00:00
2006-12-02 04:36:16 +00:00
}
/**
* @ return string path to and filename of forum icon image
*
* @ param string $filename filename of forum image
* @ param string $eMLANG_folder if specified , indicates its a multilanguage image being processed and
* gives the subfolder of the image path to the eMLANG_path () function ,
* default = FALSE
* @ param string $eMLANG_pref if specified , indicates that $filename may be overridden by the
* $pref with $eMLANG_pref as its key if that pref is TRUE , default = FALSE
*
* @ desc checks for the existence of a forum icon image in the themes forum folder and if it is found
* returns the path and filename of that file , otherwise it returns the path and filename of the
* default forum icon image in e_IMAGES . The additional $eMLANG args if specfied switch the process
* to the sister multi - language function eMLANG_path () .
*
* @ access public
*/
function img_path ( $filename )
{
2008-12-14 03:18:45 +00:00
$multilang = array ( 'reply.png' , 'newthread.png' , 'moderator.png' , 'main_admin.png' , 'admin.png' );
2006-12-02 04:36:16 +00:00
$ML = ( in_array ( $filename , $multilang )) ? TRUE : FALSE ;
2008-12-14 03:18:45 +00:00
if ( file_exists ( THEME . 'forum/' . $filename ) || is_readable ( THEME . 'forum/' . e_LANGUAGE . '_' . $filename ))
2006-12-02 04:36:16 +00:00
{
2008-12-14 03:18:45 +00:00
$image = ( $ML && is_readable ( THEME . 'forum/' . e_LANGUAGE . '_' . $filename )) ? THEME . 'forum/' . e_LANGUAGE . " _ " . $filename : THEME . 'forum/' . $filename ;
2006-12-02 04:36:16 +00:00
}
else
{
2008-12-14 03:18:45 +00:00
if ( defined ( 'IMODE' ))
2006-12-02 04:36:16 +00:00
{
if ( $ML )
{
2008-12-14 03:18:45 +00:00
$image = ( is_readable ( e_PLUGIN . 'forum/images/' . IMODE . '/' . e_LANGUAGE . '_' . $filename )) ? e_PLUGIN . 'forum/images/' . IMODE . '/' . e_LANGUAGE . '_' . $filename : e_PLUGIN . 'forum/images/' . IMODE . '/English_' . $filename ;
2006-12-02 04:36:16 +00:00
}
else
{
2008-12-14 03:18:45 +00:00
$image = e_PLUGIN . 'forum/images/' . IMODE . '/' . $filename ;
2006-12-02 04:36:16 +00:00
}
}
else
{
if ( $ML )
{
2008-12-14 03:18:45 +00:00
$image = ( is_readable ( e_PLUGIN . " forum/images/lite/ " . e_LANGUAGE . '_' . $filename )) ? e_PLUGIN . 'forum/images/lite/' . e_LANGUAGE . '_' . $filename : e_PLUGIN . 'forum/images/lite/English_' . $filename ;
2006-12-02 04:36:16 +00:00
}
else
{
2008-12-14 03:18:45 +00:00
$image = e_PLUGIN . 'forum/images/lite/' . $filename ;
2006-12-02 04:36:16 +00:00
}
}
}
return $image ;
}
if ( file_exists ( THEME . 'forum/forum_icons_template.php' ))
{
require_once ( THEME . 'forum/forum_icons_template.php' );
}
2008-12-14 03:18:45 +00:00
elseif ( file_exists ( THEME . 'forum_icons_template.php' ))
2006-12-02 04:36:16 +00:00
{
require_once ( THEME . 'forum_icons_template.php' );
}
else
{
require_once ( e_PLUGIN . 'forum/templates/forum_icons_template.php' );
}
?>