2006-12-02 04:36:16 +00:00
< ? php
/*
2010-03-09 22:40:21 +00:00
* e107 website system
*
2014-08-04 15:42:06 +02:00
* Copyright ( c ) 2008 - 2014 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-06-12 21:37:54 +02:00
// TODO LAN
2013-03-12 20:35:04 -07:00
/* Forum Header File */
if ( ! defined ( 'e107_INIT' )) { exit ; }
2016-02-01 11:43:03 +01:00
e107 :: js ( 'forum' , 'js/forum.js' , 'jquery' , 5 );
2015-03-28 14:10:28 -07:00
e107 :: css ( 'forum' , 'forum.css' );
2013-03-12 20:35:04 -07:00
2013-03-21 19:46:27 -07:00
e107 :: lan ( 'forum' , 'English_front' );
2016-01-13 18:07:05 -08:00
2013-03-14 04:05:33 -07:00
// include_lan(e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/lan_forum.php');
2015-03-28 14:10:28 -07:00
if ( ! defined ( 'IMAGE_new' ) && ! defined ( 'IMAGE_e' ))
2013-07-08 11:42:22 -07:00
{
2015-03-28 14:10:28 -07:00
if ( file_exists ( THEME . 'templates/forum/forum_icons_template.php' )) // Preferred v2.x location.
{
require_once ( THEME . 'templates/forum/forum_icons_template.php' );
}
elseif ( file_exists ( THEME . 'forum/forum_icons_template.php' ))
{
require_once ( THEME . 'forum/forum_icons_template.php' );
}
elseif ( file_exists ( THEME . 'forum_icons_template.php' ))
{
require_once ( THEME . 'forum_icons_template.php' );
}
else
{
require_once ( e_PLUGIN . 'forum/templates/forum_icons_template.php' );
}
2013-07-08 11:42:22 -07:00
}
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 ;
2016-03-26 12:29:32 -07:00
private $forumData = array ();
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
{
2016-01-13 18:07:05 -08:00
if ( ! empty ( $_POST [ 'fjsubmit' ]) && ! empty ( $_POST [ 'forumjump' ]))
{
$url = e107 :: getParser () -> filter ( $_POST [ 'forumjump' ], 'url' );
e107 :: getRedirect () -> go ( $_POST [ 'forumjump' ]);
exit ;
}
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
2016-03-26 12:29:32 -07:00
$this -> getForumData ();
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' ;
*/
}
2016-03-26 15:17:11 -07:00
/**
* Grab the forum data up front to reduce LEFT JOIN usage . Currently only forum_id and forum_sef but may be expanded as needed .
*/
private function getForumData ()
2016-03-26 12:29:32 -07:00
{
2016-03-26 15:17:11 -07:00
$data = e107 :: getDb () -> retrieve ( " SELECT forum_id, forum_sef, forum_class FROM `#forum` " , true ); // no ordering for better performance.
2016-03-26 12:29:32 -07:00
$newData = array ();
foreach ( $data as $row )
{
$id = $row [ 'forum_id' ];
$newData [ $id ] = $row ;
}
$this -> forumData = $newData ;
}
function getForumSef ( $threadInfo )
{
$forumId = ! empty ( $threadInfo [ 'post_forum' ]) ? $threadInfo [ 'post_forum' ] : $threadInfo [ 'thread_forum_id' ];
if ( ! empty ( $this -> forumData [ $forumId ][ 'forum_sef' ]))
{
$ret = $this -> forumData [ $forumId ][ 'forum_sef' ];
}
else
{
$ret = null ;
}
return $ret ;
}
2016-03-26 15:17:11 -07:00
function getForumClassMembers ( $forumId , $type = 'view' )
{
$fieldTypes = array ( 'view' => 'forum_class' );
$field = $fieldTypes [ $type ];
if ( isset ( $this -> forumData [ $forumId ][ $field ]))
{
$class = $this -> forumData [ $forumId ][ 'forum_class' ];
if ( $class == 0 || ( $class > 250 && $class < 256 ))
{
return $class ;
}
$qry = " SELECT user_id, user_name, user_class FROM `#user` WHERE FIND_IN_SET( " . $class . " , user_class) OR user_class = " . $class . " ORDER by user_name LIMIT 50 " ; // FIND_IN_SET(user_class, ".$class.")
$users = e107 :: getDb () -> retrieve ( $qry , true );
return $users ;
}
return false ;
}
2016-03-26 12:29:32 -07:00
2014-07-26 20:55:24 +02:00
/**
* @ param $user integer userid ( if empty " anon " will be used )
* @ param $create boolean creates the attachment folder if set to true
* @ return forum attachment path for specific user
*/
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
2014-07-26 20:55:24 +02:00
if ( $create == TRUE && ! is_dir ( $baseDir ))
2013-04-18 18:25:20 -07:00
{
2014-07-26 20:55:24 +02:00
mkdir ( $baseDir , 0755 , TRUE ); // recursively
2013-04-18 18:25:20 -07:00
}
2013-03-31 00:06:21 -07:00
$baseDir .= " / " ;
return $baseDir ;
}
2014-08-04 10:27:42 +02:00
function sendFile ( $data )
{
2014-08-04 12:24:24 +02:00
$sql = e107 :: getDb ();
$post_id = intval ( $data [ 'id' ]); // forum (post) id
$file_id = intval ( $data [ 'dl' ]); // file id
$forum_id = $sql -> retrieve ( 'forum_post' , 'post_forum' , 'post_id=' . $post_id );
2014-08-04 10:27:42 +02:00
2014-08-04 12:24:24 +02:00
// Check if user is allowed to download this file (has 'view' permissions to forum)
if ( ! $this -> checkPerm ( $forum_id , 'view' ))
{
2015-05-07 11:49:36 -07:00
if ( E107_DEBUG_LEVEL > 0 )
{
echo " You don't have 'view' access to forum-id: : " . $forum_id ;
print_a ( $this -> permList );
return ;
}
2015-05-22 15:37:46 -07:00
$url = e107 :: url ( 'forum' , 'index' , 'full' );
e107 :: getRedirect () -> go ( $url );
// header('Location:'.e107::getUrl()->create('forum/forum/main')); // FIXME needs proper redirect and 403 header
2014-08-04 12:24:24 +02:00
exit ;
}
$array = $sql -> retrieve ( 'forum_post' , 'post_user,post_attachments' , 'post_id=' . $post_id );
2014-08-04 10:27:42 +02:00
$attach = e107 :: unserialize ( $array [ 'post_attachments' ]);
2016-03-21 14:32:02 -07:00
$filename = is_array ( $attach [ 'file' ][ $file_id ]) ? $attach [ 'file' ][ $file_id ][ 'file' ] : $attach [ 'file' ][ $file_id ];
$file = $this -> getAttachmentPath ( $array [ 'post_user' ]) . varset ( $filename );
2014-08-04 12:24:24 +02:00
// Check if file exists. Send file for download if it does, return 404 error code when file does not exist.
if ( file_exists ( $file ))
{
e107 :: getFile () -> send ( $file );
}
else
{
2015-05-07 11:49:36 -07:00
if ( E107_DEBUG_LEVEL > 0 )
{
echo " Couldn't find file: " . $file ;
2016-03-21 14:32:02 -07:00
print_a ( $attach );
2015-05-07 11:49:36 -07:00
return ;
}
2015-05-22 15:37:46 -07:00
$url = e107 :: url ( 'forum' , 'index' , 'full' );
e107 :: getRedirect () -> go ( $url );
// header('Location:'.e107::getUrl()->create('forum/forum/main', TRUE, 404)); // FIXME needs proper redirect and 404 header
2014-08-04 12:24:24 +02:00
exit ;
}
2014-08-04 10:27:42 +02:00
}
2013-03-31 00:06:21 -07:00
2013-03-14 02:26:47 -07:00
2013-03-14 04:05:33 -07:00
/**
2016-02-01 11:43:03 +01:00
* Handle the Ajax quick - reply .
2013-03-14 04:05:33 -07:00
*/
2013-03-14 02:26:47 -07:00
function ajaxQuickReply ()
{
2013-03-13 02:39:00 -07:00
$tp = e107 :: getParser ();
2016-02-01 11:43:03 +01:00
if ( ! isset ( $_POST [ 'e_token' ])) // Set the token if not included
2013-07-08 10:36:13 -07:00
{
2016-02-01 11:43:03 +01:00
$_POST [ 'e_token' ] = '' ;
2013-07-08 10:36:13 -07:00
}
2016-02-01 11:43:03 +01:00
2013-06-26 02:28:24 -07:00
if ( ! e107 :: getSession () -> check ( false ) || ! $this -> checkPerm ( $_POST [ 'post' ], 'post' ))
2013-06-19 19:54:29 -07:00
{
2016-02-01 11:43:03 +01:00
// Invalid token.
2013-06-19 19:54:29 -07:00
exit ;
}
2013-03-13 02:39:00 -07:00
2013-03-14 02:26:47 -07:00
if ( varset ( $_POST [ 'action' ]) == 'quickreply' && vartrue ( $_POST [ 'text' ]))
2016-02-01 11:43:03 +01:00
{
$postInfo = array ();
$postInfo [ 'post_ip' ] = e107 :: getIPHandler () -> getIP ( false );
if ( USER )
{
$postInfo [ 'post_user' ] = USERID ;
}
else
{
$postInfo [ 'post_user_anon' ] = $_POST [ 'anonname' ];
}
$postInfo [ 'post_entry' ] = $_POST [ 'text' ];
$postInfo [ 'post_forum' ] = intval ( $_POST [ 'post' ]);
$postInfo [ 'post_datestamp' ] = time ();
$postInfo [ 'post_thread' ] = intval ( $_POST [ 'thread' ]);
$postInfo [ 'post_id' ] = $this -> postAdd ( $postInfo ); // save it.
$postInfo [ 'user_name' ] = USERNAME ;
$postInfo [ 'user_email' ] = USEREMAIL ;
$postInfo [ 'user_image' ] = USERIMAGE ;
$postInfo [ 'user_signature' ] = USERSIGNATURE ;
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 , $sc ) . " \n " ;
}
else
{
$ret [ 'html' ] = false ;
}
$ret [ 'status' ] = 'ok' ;
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_3047 ;
2016-02-01 11:43:03 +01:00
}
2013-03-13 02:39:00 -07:00
2013-06-19 19:54:29 -07:00
e107 :: getSession () -> reset ();
2013-03-14 02:26:47 -07:00
2016-02-01 11:43:03 +01:00
if ( varset ( $ret , false ))
{
$ret [ 'e_token' ] = e107 :: getSession () -> getFormToken ();
}
echo $tp -> toJSON ( $ret );
exit ;
2013-03-14 02:26:47 -07:00
}
2016-01-31 14:39:41 -08:00
/**
* Process Tracking Enable / disable
*/
public function ajaxTrack ()
{
$ret = array ();
$ret [ 'status' ] = 'error' ;
$threadID = intval ( $_POST [ 'thread' ]);
if ( ! USER || empty ( $threadID ))
{
exit ;
}
2016-04-05 11:21:53 -07:00
$trackByEmail = ( $this -> prefs -> get ( 'trackemail' , true )) ? true : false ;
2016-01-31 14:39:41 -08:00
$sql = e107 :: getDb ();
if ( $sql -> select ( 'forum_track' , '*' , " track_userid= " . USERID . " AND track_thread= " . $threadID ))
{
if ( $this -> track ( 'del' , USERID , $threadID ))
{
$ret [ 'html' ] = IMAGE_untrack ;
2016-04-05 11:21:53 -07:00
$ret [ 'msg' ] = ( $trackByEmail ) ? LAN_FORUM_8004 : LAN_FORUM_8006 ; // "Email notifications for this topic are now turned off. ";
2016-01-31 19:26:08 -08:00
$ret [ 'status' ] = 'info' ;
2016-01-31 14:39:41 -08:00
}
else
{
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_8017 ;
2016-01-31 14:39:41 -08:00
$ret [ 'status' ] = 'error' ;
}
}
else
{
if ( $this -> track ( 'add' , USERID , $threadID ))
{
2016-04-05 11:21:53 -07:00
$ret [ 'msg' ] = ( $trackByEmail ) ? LAN_FORUM_8003 : LAN_FORUM_8005 ; // "Email notifications for this topic are now turned on. ";
2016-01-31 14:39:41 -08:00
$ret [ 'html' ] = IMAGE_track ;
$ret [ 'status' ] = 'ok' ;
}
else
{
$ret [ 'html' ] = IMAGE_untrack ;
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_8018 ;
2016-01-31 14:39:41 -08:00
$ret [ 'status' ] = 'error' ;
}
}
echo json_encode ( $ret );
exit ;
}
2013-03-14 02:26:47 -07:00
2013-06-21 01:26:30 -07:00
public function ajaxModerate ()
2013-03-14 02:26:47 -07:00
{
2013-06-19 19:54:29 -07:00
2013-06-21 01:26:30 -07:00
if ( ! $this -> isModerator ( USERID )) //FIXME check permissions per forum.
2013-06-19 19:54:29 -07:00
{
exit ;
}
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);
2014-08-04 15:42:06 +02:00
$ret = array ( 'hide' => false , 'msg' => '' , 'status' => null );
2013-03-12 20:35:04 -07:00
switch ( $_POST [ 'action' ])
{
case 'delete' :
if ( $this -> threadDelete ( $id ))
{
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = '' . LAN_FORUM_8020 . ' #' . $id ;
2013-03-12 20:35:04 -07:00
$ret [ 'hide' ] = true ;
$ret [ 'status' ] = 'ok' ;
}
else
{
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_8019 ;
2013-03-12 20:35:04 -07:00
$ret [ 'status' ] = 'error' ;
}
break ;
2013-03-13 02:39:00 -07:00
case 'deletepost' :
if ( ! $postId = vartrue ( $_POST [ 'post' ]))
{
2014-08-04 15:42:06 +02:00
// echo "No Post";
// exit;
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_7008 ;
2014-08-04 15:42:06 +02:00
$ret [ 'status' ] = 'error' ;
2013-03-13 02:39:00 -07:00
}
if ( $this -> postDelete ( $postId ))
{
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = '' . LAN_FORUM_8021 . ' #' . $postId ;
2013-03-13 02:39:00 -07:00
$ret [ 'hide' ] = true ;
$ret [ 'status' ] = 'ok' ;
}
else
{
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = " " . LAN_FORUM_8021 . " # " . $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
{
2015-01-30 18:14:06 -08:00
$ret [ 'msg' ] = LAN_FORUM_CLOSE ;
2013-03-12 20:35:04 -07:00
$ret [ 'status' ] = 'ok' ;
}
else
{
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_8023 ;
2013-03-12 20:35:04 -07:00
$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
{
2015-01-30 18:14:06 -08:00
$ret [ 'msg' ] = LAN_FORUM_OPEN ;
2013-03-12 20:35:04 -07:00
$ret [ 'status' ] = 'ok' ;
}
else
{
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_8024 ;
2013-03-12 20:35:04 -07:00
$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
{
2015-01-30 18:14:06 -08:00
$ret [ 'msg' ] = LAN_FORUM_STICK ;
2013-03-12 20:35:04 -07:00
$ret [ 'status' ] = 'ok' ;
}
else
{
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_8025 ;
2013-03-12 20:35:04 -07:00
$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
{
2015-01-30 18:14:06 -08:00
$ret [ 'msg' ] = LAN_FORUM_UNSTICK ;
2013-03-12 20:35:04 -07:00
$ret [ 'status' ] = 'ok' ;
}
else
{
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_8026 ;
2013-03-12 20:35:04 -07:00
$ret [ 'status' ] = 'error' ;
}
2013-03-13 02:39:00 -07:00
break ;
2013-03-12 20:35:04 -07:00
default :
$ret [ 'status' ] = 'error' ;
2016-09-15 10:55:12 +02:00
$ret [ 'msg' ] = LAN_FORUM_8027 ;
2013-03-12 20:35:04 -07:00
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
{
2015-06-25 18:17:08 -07:00
if ( $tmp = e107 :: getCache () -> setMD5 ( e_LANGUAGE . USERCLASS_LIST ) -> retrieve ( 'forum_perms' ))
2008-11-26 19:59:06 +00:00
{
2016-05-04 09:25:44 -07:00
e107 :: getDebug () -> log ( " Using Permlist cache: True " );
2015-06-25 18:17:08 -07:00
2015-02-14 23:34:15 -08:00
$this -> permList = e107 :: unserialize ( $tmp );
2015-06-25 18:17:08 -07:00
// print_a($this->permList);
2008-11-26 19:59:06 +00:00
}
else
{
2016-05-04 09:25:44 -07:00
e107 :: getDebug () -> log ( " Using Permlist cache: False " );
2011-04-26 11:27:36 +00:00
$this -> _getForumPermList ();
2015-02-14 23:34:15 -08:00
$tmp = e107 :: serialize ( $this -> permList , false );
2015-06-25 18:17:08 -07:00
e107 :: getCache () -> setMD5 ( e_LANGUAGE . USERCLASS_LIST ) -> set ( '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
{
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 );
2015-04-23 20:19:14 -07:00
if ( $key == 'post' )
{
//echo "<h3>Raw Perms</h3>";
// echo "Qry: ".$qryList['post'];
// print_a($tmp);
}
2010-03-14 00:50:27 +00:00
$this -> permList [ $key ] = array_keys ( $tmp );
$this -> permList [ $key . '_list' ] = implode ( ',' , array_keys ( $tmp ));
2008-11-26 19:59:06 +00:00
}
}
2016-03-24 20:14:56 -07:00
// print_a($this->permList);
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' )
{
2015-04-23 20:19:14 -07:00
// print_a( $this->permList[$type]);
2015-06-25 18:17:08 -07:00
if ( empty ( $this -> permList [ $type ]))
{
2015-06-25 18:20:49 -07:00
return false ;
2015-06-25 18:17:08 -07:00
}
2008-11-27 03:02:26 +00:00
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
{
2015-02-15 16:07:27 -08:00
$ret = array ();
2016-01-31 21:44:11 -08:00
while ( $row = $sql -> fetch ())
2008-12-05 01:30:56 +00:00
{
$ret [] = $row [ 'track_thread' ];
}
2015-02-15 16:07:27 -08:00
2008-12-05 01:30:56 +00:00
return ( $retType == 'array' ? $ret : implode ( ',' , $ret ));
}
return false ;
}
2015-04-18 15:09:10 -07:00
function isDuplicatePost ( $postInfo )
{
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
$post = $tp -> toDB ( $postInfo [ 'post_entry' ]);
if ( $sql -> select ( 'forum_post' , 'post_id' , " post_forum = " . intval ( $postInfo [ 'post_forum' ]) . " AND post_entry=' " . $post . " ' AND post_user = " . USERID . " LIMIT 1 " ))
{
return true ;
}
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);
2015-04-18 15:09:10 -07:00
if ( $this -> isDuplicatePost ( $postInfo ) == true )
{
return - 1 ;
}
2016-01-31 19:26:08 -08:00
2008-12-01 21:11:01 +00:00
$addUserPostCount = true ;
2008-12-07 04:16:39 +00:00
$result = false ;
2008-12-01 21:11:01 +00:00
2013-03-24 18:59:18 +01:00
$sql = e107 :: getDb ();
2009-01-10 04:39:54 +00:00
$info = array ();
2015-04-18 15:09:10 -07:00
$tp = e107 :: getParser ();
2010-03-09 22:40:21 +00:00
// $info['_FIELD_TYPES'] = $this->fieldTypes['forum_post'];
2015-04-18 15:09:10 -07:00
$postInfo [ 'post_entry' ] = $tp -> toDB ( $postInfo [ 'post_entry' ]);
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 );
2016-01-31 19:26:08 -08:00
$info [ 'data' ][ 'post_id' ] = $postId ; // Append last inserted ID to data array for passing it to event callbacks.
2016-04-22 08:45:11 -07:00
$triggerData = $info [ 'data' ];
e107 :: getEvent () -> trigger ( 'user_forum_post_created' , $triggerData );
2016-01-31 19:26:08 -08:00
ob_start (); // precaution so json doesn't break.
$this -> trackEmail ( $info [ 'data' ]);
ob_end_clean ();
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
}
2016-03-21 14:32:02 -07:00
$threadInfo [ 'thread_lastpost' ] = ! empty ( $postInfo [ 'post_edit_datestamp' ]) ? $postInfo [ 'post_edit_datestamp' ] : $postInfo [ 'post_datestamp' ];
if ( ! empty ( $postInfo [ 'post_edit_user' ]))
{
$threadInfo [ 'thread_lastuser' ] = $postInfo [ 'post_edit_user' ];
}
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 );
2016-03-21 14:32:02 -07:00
e107 :: getMessage () -> addDebug ( " Updating Thread with: " . print_a ( $info , true ));
2016-04-22 08:45:11 -07:00
$triggerData = $info [ 'data' ];
2016-04-22 09:01:18 -07:00
$triggerData [ 'thread_id' ] = $postInfo [ 'post_thread' ];
2016-04-22 08:45:11 -07:00
e107 :: getEvent () -> trigger ( 'user_forum_topic_updated' , $triggerData );
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
}
2016-01-31 19:26:08 -08:00
2016-11-17 16:13:31 -08:00
$this -> clearReadThreads ( $postInfo [ 'post_thread' ]);
2016-01-31 19:26:08 -08: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
2016-11-17 16:13:31 -08:00
/**
* Remove threadID from the 'viewed list' list of other users .
* @ param $threadId
*/
private function clearReadThreads ( $threadId )
{
if ( empty ( $threadId ))
{
return false ;
}
$sql = e107 :: getDb ();
$threadId = intval ( $threadId );
$query = " UPDATE `#user_extended`
SET
user_plugin_forum_viewed = TRIM ( BOTH ',' FROM REPLACE ( CONCAT ( ',' , user_plugin_forum_viewed , ',' ), ',".$threadId.",' , ',' ))
WHERE
FIND_IN_SET ( " . $threadId . " , user_plugin_forum_viewed )
" ;
$sql -> gen ( $query );
}
2013-03-12 20:35:04 -07:00
2008-11-27 03:02:26 +00:00
function threadAdd ( $threadInfo , $postInfo )
{
2016-05-04 09:13:46 -07:00
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'];
2015-04-25 12:57:00 -07:00
2015-06-17 20:09:26 -07:00
// $threadInfo['thread_sef'] = eHelper::title2sef($threadInfo['thread_name'],'dashl');
2015-04-25 12:57:00 -07:00
2009-01-09 16:22:08 +00:00
$info [ 'data' ] = $threadInfo ;
2015-04-25 12:57:00 -07:00
2013-03-24 18:59:18 +01:00
if ( $newThreadId = e107 :: getDb () -> insert ( 'forum_thread' , $info ))
2009-01-09 16:22:08 +00:00
{
2016-05-03 20:52:46 -07:00
if ( $postInfo !== false )
{
$postInfo [ 'post_thread' ] = $newThreadId ;
2016-04-22 08:45:11 -07:00
2016-05-03 20:52:46 -07:00
if ( ! $newPostId = $this -> postAdd ( $postInfo , false ))
{
e107 :: getMessage () -> addDebug ( " There was a problem: " . print_a ( $postInfo , true ));
}
}
else
2016-03-20 18:32:35 -07:00
{
2016-05-03 20:52:46 -07:00
$newPostId = 0 ;
2016-03-20 18:32:35 -07:00
}
2008-12-18 17:10:48 +00:00
$this -> threadMarkAsRead ( $newThreadId );
2016-02-10 19:51:32 -08:00
$threadInfo [ 'thread_sef' ] = $this -> getThreadsef ( $threadInfo );
2015-06-17 20:09:26 -07:00
2016-04-22 08:45:11 -07:00
$triggerData = $info [ 'data' ];
$triggerData [ 'thread_id' ] = $newThreadId ;
$triggerData [ 'thread_sef' ] = $threadInfo [ 'thread_sef' ];
$triggerData [ 'post_id' ] = $newPostId ;
e107 :: getEvent () -> trigger ( 'user_forum_topic_created' , $triggerData );
2015-05-22 15:37:46 -07:00
return array ( 'postid' => $newPostId , 'threadid' => $newThreadId , 'threadsef' => $threadInfo [ 'thread_sef' ]);
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
2016-02-10 19:51:32 -08:00
function getThreadSef ( $threadInfo )
{
return eHelper :: title2sef ( $threadInfo [ 'thread_name' ], 'dashl' );
}
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
2015-05-09 13:22:27 -07:00
if ( ! empty ( $threadTitle ))
2010-03-13 20:38:40 +00:00
{
if ( $titleType == 0 )
{
//prepend to existing title
$threadTitle = " , thread_name = CONCAT(' { $threadTitle } ', thread_name) " ;
}
else
{
//Replace title
2015-06-17 20:09:26 -07:00
$threadTitle = " , thread_name = ' { $threadTitle } ' " ; // , thread_sef='".eHelper::title2sef($threadTitle,'dashl')."' ";
2010-03-13 20:38:40 +00:00
}
}
2015-05-09 13:22:27 -07:00
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 ();
2015-06-17 20:09:26 -07:00
// $threadInfo['thread_sef'] = eHelper::title2sef($threadInfo['thread_name'],'dashl');
2015-04-25 12:57:00 -07:00
2009-01-09 16:22:08 +00:00
$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 ;
2015-04-18 15:09:10 -07:00
if ( e107 :: getDb () -> update ( 'forum_thread' , $info ) === false )
{
e107 :: getMessage () -> addDebug ( " Thread Update Failed: " . print_a ( $info , true ));
}
2016-04-22 08:45:11 -07:00
$triggerData = $threadInfo ;
$triggerData [ 'thread_id' ] = intval ( $threadId );
e107 :: getEvent () -> trigger ( 'user_forum_topic_updated' , $triggerData );
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 ;
2015-04-18 15:09:10 -07:00
if ( e107 :: getDb () -> update ( 'forum_post' , $info ) === false )
{
e107 :: getMessage () -> addDebug ( " Post Update Failed: " . print_a ( $info , true ));
}
2016-04-22 08:45:11 -07:00
$triggerData = $postInfo ;
$triggerData [ 'post_id' ] = intval ( $postId );
2015-02-12 16:52:30 -08:00
e107 :: getEvent () -> trigger ( 'user_forum_post_updated' , $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 .* ,
2015-06-27 12:07:41 -07:00
fp . forum_id AS parent_id , fp . forum_name AS parent_name ,
sp . forum_id AS forum_sub , sp . forum_name AS sub_parent ,
sp . forum_sef AS parent_sef ,
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 ;
}
2016-03-03 15:24:59 -08:00
if ( $sql -> gen ( $qry ) !== false )
2008-12-01 01:10:50 +00:00
{
2016-02-14 12:15:55 -08:00
$tmp = $sql -> fetch ();
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
}
2015-06-17 20:09:26 -07:00
$tmp [ 'thread_sef' ] = eHelper :: title2sef ( $tmp [ 'thread_name' ], 'dashl' );
2016-11-21 17:21:07 -08:00
if ( empty ( $tmp [ 'forum_sef' ]))
{
e107 :: getDebug () -> log ( " Forum " . $tmp [ 'forum_name' ] . " is missing a SEF URL. Please add one via the admin area. " );
}
2008-12-01 01:10:50 +00:00
return $tmp ;
}
}
2015-04-18 15:09:10 -07:00
else
{
2015-06-27 12:07:41 -07:00
e107 :: getMessage () -> addDebug ( 'Query failed (' . __METHOD__ . ' ): ' . str_replace ( '#' , MPREFIX , $qry ));
2015-04-18 15:09:10 -07:00
}
2008-12-01 01:10:50 +00:00
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 = '
2015-06-22 19:29:20 +02:00
SELECT u . user_name , t . thread_active , t . thread_datestamp , t . thread_name , t . thread_user , t . thread_id , t . thread_sticky , 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 }
" ;
}
2016-05-03 20:52:46 -07:00
if ( $sql -> gen ( $qry ) !== false )
2008-12-01 01:10:50 +00:00
{
2008-12-01 21:11:01 +00:00
$ret = array ();
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
2008-12-01 21:11:01 +00:00
{
2016-03-26 12:29:32 -07:00
$row [ 'thread_sef' ] = $this -> getThreadSef ( $row ); // eHelper::title2sef($row['thread_name'],'dashl');
2008-12-01 21:11:01 +00:00
$ret [] = $row ;
}
2008-12-01 01:10:50 +00:00
}
2015-04-18 15:09:10 -07:00
else
{
2016-03-20 18:32:35 -07:00
e107 :: getMessage () -> addDebug ( 'Query failed (' . __METHOD__ . ' ): ' . str_replace ( '#' , MPREFIX , $qry ));
2015-04-18 15:09:10 -07:00
}
2016-03-26 12:29:32 -07:00
// print_a($ret);
2016-03-26 12:54:08 -07:00
if ( $start === 'post' )
2016-03-26 12:29:32 -07:00
{
$ret [ 0 ][ 'forum_sef' ] = $this -> getForumSef ( $ret [ 0 ]);
$ret [ 0 ][ 'thread_sef' ] = $this -> getThreadSef ( $ret [ 0 ]);
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
2014-08-04 16:55:34 +02:00
/**
2016-05-04 09:13:46 -07:00
* Checks if post is the initial post which started the topic .
* Retrieves list of post_id ' s belonging to one post_thread . When lowest value is equal to input param , return true .
* Used to prevent deleting of the initial post ( so topic shows empty does not get hidden accidently while posts remain in database )
*
* @ param $postId
* @ return bool true if post is the initial post of the topic ( false , if not )
*
* @ internal param int $postid
*/
2014-08-04 16:55:34 +02:00
function threadDetermineInitialPost ( $postId )
{
$sql = e107 :: getDb ();
$postId = ( int ) $postId ;
$threadId = $sql -> retrieve ( 'forum_post' , 'post_thread' , 'post_id = ' . $postId );
if ( $rows = $sql -> retrieve ( 'forum_post' , 'post_id' , 'post_thread = ' . $threadId , TRUE ))
{
$postids = array ();
foreach ( $rows as $row )
{
$postids [] = $row [ 'post_id' ];
}
if ( $postId == min ( $postids ))
{
return true ;
}
}
return false ;
}
2008-12-09 21:46:14 +00:00
2016-05-04 09:13:46 -07: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 ();
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
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
2014-08-04 15:42:06 +02:00
function postDeleteAttachments ( $type = 'post' , $id = '' ) // postDeleteAttachments($type = 'post', $id='', $f='')
2008-12-11 16:02:05 +00:00
{
$e107 = e107 :: getInstance ();
2014-08-04 15:42:06 +02:00
$sql = e107 :: getDb ();
$log = e107 :: getAdminLog ();
2013-03-24 18:59:18 +01:00
2008-12-11 16:02:05 +00:00
$id = ( int ) $id ;
if ( ! $id ) { return ; }
2014-08-04 15:42:06 +02:00
// Moc: Is the code below used at all? When deleting a thread, threadDelete() loops through each post separately to delete attachments (type=post)
/*
2008-12-11 16:02:05 +00:00
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 ;
}
2014-08-04 15:42:06 +02:00
2008-12-11 16:02:05 +00:00
$postList = array ();
2014-08-04 15:42:06 +02:00
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> Fetch ())
2008-12-11 16:02:05 +00:00
{
$postList [] = $row [ 'post_id' ];
}
2014-08-04 15:42:06 +02:00
2008-12-11 16:02:05 +00:00
foreach ( $postList as $postId )
{
$this -> postDeleteAttachment ( 'post' , $postId );
}
}
2014-08-04 15:42:06 +02:00
*/
// if we are deleting just a single post
2008-12-11 16:02:05 +00:00
if ( $type == 'post' )
{
2014-08-04 15:42:06 +02:00
if ( ! $sql -> select ( 'forum_post' , 'post_user, post_attachments' , 'post_id = ' . $id ))
2008-12-11 16:02:05 +00:00
{
return true ;
}
2014-08-04 15:42:06 +02:00
2016-02-14 12:15:55 -08:00
$tmp = $sql -> fetch ();
2014-08-04 15:42:06 +02:00
$attachment_array = e107 :: unserialize ( $tmp [ 'post_attachments' ]);
$files = $attachment_array [ 'file' ];
$imgs = $attachment_array [ 'img' ];
// TODO see if files/images check can be written more efficiently
// check if there are files to be deleted
if ( is_array ( $files ))
{
// loop through each file and delete it
foreach ( $files as $file )
{
$file = $this -> getAttachmentPath ( $tmp [ 'post_user' ]) . $file ;
@ unlink ( $file );
// Confirm that file has been deleted. Add warning to log file when file could not be deleted.
if ( file_exists ( $file ))
{
$log -> addWarning ( " Could not delete file: " . $file . " . Please delete manually as this file is now no longer in use (orphaned). " );
}
}
}
2014-08-04 17:54:34 +02:00
2014-08-04 15:42:06 +02:00
// check if there are images to be deleted
2014-08-04 17:54:34 +02:00
if ( is_array ( $imgs ))
2014-08-04 15:42:06 +02:00
{
// loop through each image and delete it
foreach ( $imgs as $img )
{
$img = $this -> getAttachmentPath ( $tmp [ 'post_user' ]) . $img ;
@ unlink ( $img );
// Confirm that file has been deleted. Add warning to log file when file could not be deleted.
if ( file_exists ( $img ))
{
$log -> addWarning ( " Could not delete image: " . $img . " . Please delete manually as this file is now no longer in use (orphaned). " );
}
}
}
2014-08-04 17:54:34 +02:00
2014-08-04 15:42:06 +02:00
// At this point we assume that all attachments have been deleted from the post. The log file may prove otherwise (see above).
$log -> toFile ( 'forum_delete_attachments' , 'Forum plugin - Delete attachments' , TRUE );
// Empty the post_attachments field for this post in the database (prevents loop when deleting entire thread)
$sql -> update ( " forum_post " , " post_attachments = NULL WHERE post_id = " . $id );
/* Old code when attachments were still stored in plugin folder .
Left for review but may be deleted in future .
2008-12-11 16:02:05 +00:00
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 ]);
}
2014-08-04 15:42:06 +02:00
2008-12-11 16:02:05 +00:00
$tmp = array ();
if ( count ( $attachments ))
{
$tmp [ 'post_attachments' ] = implode ( ',' , $attachments );
}
else
{
$tmp [ 'post_attachments' ] = '_NULL_' ;
}
2014-08-04 15:42:06 +02:00
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 );
2014-08-04 15:42:06 +02:00
*/
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 ();
2016-05-03 20:52:46 -07:00
$sql2 = e107 :: getDb ( 'sql2' );
2006-12-02 04:36:16 +00:00
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
}
2016-05-03 20:52:46 -07:00
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 ;
2016-05-03 20:52:46 -07:00
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
}
2016-05-03 20:52:46 -07: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
{
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
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
{
2016-02-14 12:15:55 -08:00
while ( $row = $sql2 -> fetch ())
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
{
2016-02-14 12:15:55 -08:00
$row = $sql -> fetch ();
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
{
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
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 ;
}
2015-04-22 00:16:52 -07:00
$tmp = array_unique ( $_tmp );
2008-12-15 00:29:20 +00:00
$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
{
2016-02-14 12:15:55 -08:00
while ( $row = e107 :: getDb () -> fetch ()) {
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' );
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
2008-12-04 21:36:09 +00:00
{
2016-03-23 20:13:26 -07:00
$this -> modArray [ $row [ 'user_id' ]] = $row ;
2008-12-04 21:36:09 +00:00
}
2006-12-02 04:36:16 +00:00
}
else
{
2016-03-23 20:13:26 -07:00
$this -> modArray = e107 :: getUserClass () -> get_users_in_class ( $uclass , 'user_name' , true );
2006-12-02 04:36:16 +00:00
}
2016-03-23 20:13:26 -07: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
2015-05-22 15:37:46 -07:00
if ( ! empty ( $this -> permList [ 'view_list' ]))
{
$where = ( $all ? '' : " WHERE forum_id IN ( { $this -> permList [ 'view_list' ] } ) " );
}
$qry = ' SELECT f .* , u . user_name FROM `#forum` AS f
2008-12-17 04:22:37 +00:00
LEFT JOIN `#user` AS u ON f . forum_lastpost_user IS NOT NULL AND u . user_id = f . forum_lastpost_user
2015-05-22 15:37:46 -07: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
{
2016-11-21 17:21:07 -08:00
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 ;
}
2015-06-27 12:07:41 -07:00
$id = $row [ 'forum_id' ];
$ret [ 'all' ][ $id ] = $row ;
2008-12-17 04:22:37 +00:00
}
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
{
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
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
{
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
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 ;
2016-11-17 16:13:31 -08:00
$ret = array ();
// e107::getDebug()->log(e107::getParser()->toDate(USERLV,'relative'));
2013-03-24 18:59:18 +01:00
if ( $sql -> gen ( $_newqry ))
2006-12-02 04:36:16 +00:00
{
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
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
2016-01-31 19:26:08 -08:00
/**
* Topic / Thread tracking add / remove
* @ param $which
* @ param $uid
* @ param $threadId
* @ param bool | false $force
* @ return bool | int
*/
2008-12-23 20:48:24 +00:00
function track ( $which , $uid , $threadId , $force = false )
2006-12-02 04:36:16 +00:00
{
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
2016-01-31 19:26:08 -08:00
/**
* Send an email to users who are tracking the topic / thread .
* @ param $post
* @ return bool
*/
function trackEmail ( $post )
{
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
$trackingPref = $this -> prefs -> get ( 'track' );
2016-04-05 11:21:53 -07:00
$trackingEmailPref = $this -> prefs -> get ( 'trackemail' , true );
2016-01-31 19:26:08 -08:00
2016-04-05 11:21:53 -07:00
if ( empty ( $trackingPref ) || empty ( $trackingEmailPref ))
2016-01-31 19:26:08 -08:00
{
return false ;
}
$data = $sql -> retrieve ( 'SELECT t.*, u.user_id, u.user_name, u.user_email, u.user_lastvisit FROM `#forum_track` AS t LEFT JOIN `#user` AS u ON t.track_userid = u.user_id WHERE t.track_thread=' . intval ( $post [ 'post_thread' ]), true );
if ( empty ( $data ))
{
return false ;
}
$threadData = $this -> threadGet ( $post [ 'post_thread' ]);
$recipients = array ();
$thread_name = $tp -> toText ( $threadData [ 'thread_name' ]);
// $thread_name = str_replace('"', '"', $thread_name); // This not picked up by toText();
$datestamp = $tp -> toDate ( $post [ 'post_datestamp' ]);
$email_post = $tp -> toHTML ( $post [ 'post_entry' ], true );
// $mail_link = "<a href='".SITEURL.$PLUGINS_DIRECTORY."forum/forum_viewtopic.php?".$thread_parent.".last'>".SITEURL.$PLUGINS_DIRECTORY."forum/forum_viewtopic.php?".$thread_parent.".last</a>";
$query = array ( 'last' => 1 );
$mail_link = e107 :: url ( 'forum' , 'topic' , $threadData , array ( 'mode' => 'full' , 'query' => $query ));
$subject = $this -> prefs -> get ( 'eprefix' ) . " " . $thread_name ;
foreach ( $data as $row )
{
$recipients [] = array (
'mail_recipient_id' => $row [ 'user_id' ],
'mail_recipient_name' => $row [ 'user_name' ], // Should this use realname?
'mail_recipient_email' => $row [ 'user_email' ],
'mail_target_info' => array (
'USERID' => $row [ 'user_id' ],
'DISPLAYNAME' => $row [ 'user_name' ],
'SUBJECT' => $subject ,
'USERNAME' => $row [ 'user_name' ],
'USERLASTVISIT' => $row [ 'user_lastvisit' ],
// 'UNSUBSCRIBE' => (!in_array($notifyTarget, $exclude)) ? $unsubUrl : '',
// 'UNSUBSCRIBE_MESSAGE' => (!in_array($notifyTarget, $exclude)) ? $unsubMessage : '',
// 'USERCLASS' => $notifyTarget,
'DATE_SHORT' => $tp -> toDate ( time (), 'short' ),
'DATE_LONG' => $tp -> toDate ( time (), 'long' ),
)
);
}
require_once ( e_HANDLER . 'mail_manager_class.php' );
$mailer = new e107MailManager ;
$vars = array ( 'x' => USERNAME , 'y' => $thread_name , 'z' => $datestamp );
$message = " [html] " . $tp -> lanVars ( LAN_FORUM_8001 , $vars , true ) . " <br /><br /><blockquote> " . $tp -> toEmail ( $email_post , false ) . " </blockquote><br /> " . LAN_FORUM_8002 . " <br /><a href=' " . $mail_link . " '> " . $mail_link . " </a>[/html] " ;
// Create the mail body
$mailData = array (
'mail_total_count' => count ( $recipients ),
'mail_content_status' => MAIL_STATUS_TEMP ,
'mail_create_app' => 'forum' ,
'mail_title' => 'FORUM TRACKING' ,
'mail_subject' => $subject ,
'mail_sender_email' => e107 :: getPref ( 'replyto_email' , SITEADMINEMAIL ),
'mail_sender_name' => e107 :: getPref ( 'replyto_name' , SITEADMIN ),
'mail_notify_complete' => 0 , // NEVER notify when this email sent!
'mail_body' => $message ,
'template' => 'default' ,
'mail_send_style' => 'default'
);
/* if ( ! empty ( $media ) && is_array ( $media ))
{
foreach ( $media as $k => $v )
{
$mailData [ 'mail_media' ][ $k ] = array ( 'path' => $v );
}
} */
$opts = array (); // array('mail_force_queue'=>1);
$mailer -> sendEmails ( 'default' , $mailData , $recipients , $opts );
}
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 = "
2015-06-27 12:07:41 -07:00
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 , sp . forum_sef AS parent_sef
FROM #forum AS f
2006-12-02 04:36:16 +00:00
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
{
2016-11-21 17:21:07 -08:00
$row = $sql -> fetch ();
if ( empty ( $row [ 'forum_sef' ]))
{
e107 :: getDebug () -> log ( " Forum " . $row [ 'forum_name' ] . " is missing a SEF URL. Please add one via the admin area. " );
}
return $row ;
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 = "
2015-05-26 12:00:43 -07:00
SELECT forum_id , forum_name , forum_sef FROM `#forum`
WHERE forum_id IN ({ $forumList }) AND forum_parent != 0
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
{
2015-05-26 12:00:43 -07:00
while ( $row = $sql -> fetch ())
2006-12-02 04:36:16 +00:00
{
2015-05-26 12:00:43 -07:00
$ret [ $row [ 'forum_id' ]] = $row ;
2006-12-02 04:36:16 +00:00
}
}
return $ret ;
}
2015-04-25 12:57:00 -07:00
/**
* @ param $forumId
* @ param $from
* @ param $view
* @ return array
*/
2016-05-22 11:58:27 -07:00
function forumGetThreads ( $forumId , $from , $view , $filter = null )
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 = "
2016-11-21 17:21:07 -08:00
SELECT t .* , f . forum_id , f . forum_sef , f . forum_name , u . user_name , lpu . user_name AS lastpost_username , MAX ( p . post_id ) AS lastpost_id FROM `#forum_thread` as t
2015-04-25 12:57:00 -07:00
LEFT JOIN `#forum` AS f ON t . thread_forum_id = f . forum_id
2015-04-25 14:03:54 -07:00
LEFT JOIN `#forum_post` AS p ON t . thread_id = p . post_thread
2008-11-27 03:02:26 +00:00
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 }
2016-05-22 11:58:27 -07:00
" ;
if ( ! empty ( $filter ))
{
$qry .= " AND " . $filter ;
}
$qry .= "
2015-04-25 14:03:54 -07:00
GROUP BY thread_id
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
{
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
2006-12-02 04:36:16 +00:00
{
2016-11-21 17:21:07 -08:00
if ( empty ( $row [ 'forum_sef' ]))
{
e107 :: getDebug () -> log ( " Forum " . $row [ 'forum_name' ] . " is missing a SEF URL. Please add one via the admin area. " );
}
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 = "
2015-06-17 20:09:26 -07:00
SELECT p . post_user , p . post_id , p . post_user_anon , p . post_datestamp , p . post_thread , t . thread_name , u . user_name FROM `#forum_post` AS p
2015-04-25 14:03:54 -07:00
LEFT JOIN `#forum_thread` AS t ON p . post_thread = t . thread_id
2008-12-11 16:02:05 +00:00
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
{
2016-02-07 22:25:12 -08:00
$row = $sql -> fetch ();
2015-06-17 20:09:26 -07:00
$row [ 'thread_sef' ] = eHelper :: title2sef ( $row [ 'thread_name' ], 'dashl' );
return $row ;
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
{
2013-03-28 00:43:00 -07:00
$sql = e107 :: getDb ();
2008-12-04 21:36:09 +00:00
$forumId = ( int ) $forumId ;
$lastpost = ( int ) $lastpost ;
2015-05-26 12:00:43 -07:00
$dir = ( $which == 'next' ) ? '<' : '>' ;
2008-12-04 21:36:09 +00:00
$qry = "
2015-06-17 20:09:26 -07:00
SELECT t . thread_id , t . thread_name , f . forum_id , f . forum_sef FROM `#forum_thread` AS t
2015-05-26 12:00:43 -07:00
LEFT JOIN `#forum` AS f ON t . thread_forum_id = f . forum_id
WHERE t . thread_forum_id = $forumId
AND t . thread_lastpost { $dir } $lastpost
2006-12-02 04:36:16 +00:00
ORDER BY
2015-05-26 12:00:43 -07:00
t . thread_sticky DESC ,
t . thread_lastpost ASC
2008-12-04 21:36:09 +00:00
LIMIT 1 " ;
2015-05-26 12:00:43 -07:00
// e107::getMessage()->addDebug(ucfirst($which)." Thread Qry: ".$qry);
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 ();
2015-06-17 20:09:26 -07:00
$row [ 'thread_sef' ] = eHelper :: title2sef ( $row [ 'thread_name' ], 'dashl' );
2015-05-26 12:00:43 -07:00
// e107::getMessage()->addInfo(ucfirst($which).print_a($row,true));
return $row ;
// return $row['thread_id'];
2006-12-02 04:36:16 +00:00
}
2015-05-26 12:00:43 -07:00
else
{
// e107::getMessage()->addDebug(ucfirst($which)." Thread Qry Returned Nothing: ".$qry);
}
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 ();
2016-12-01 15:38:40 -08:00
$tp = e107 :: getParser ();
2008-12-18 18:32:54 +00:00
$prunedate = time () - ( int ) $days * 86400 ;
2016-12-01 15:38:40 -08:00
$forumList = implode ( ',' , $tp -> filter ( $forumArray , 'int' ));
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
2016-05-03 20:52:46 -07:00
/**
* @ param $threadID
* @ return int
*/
function threadUpdateCounts ( $threadID )
{
$sql = e107 :: getDb ();
$replies = $sql -> count ( 'forum_post' , '(*)' , 'WHERE post_thread=' . $threadID );
return $sql -> update ( 'forum_thread' , " thread_total_replies= { $replies } WHERE thread_id= " . $threadID );
}
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 ();
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
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
2016-06-14 13:34:52 +01:00
// Function eventually to be reworked (move full function to shortcode file, or make a new breadcrumb function, like in downloads, maybe?)
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
{
2015-06-27 12:07:41 -07:00
2013-03-26 12:33:03 +01:00
$tp = e107 :: getParser ();
2013-06-20 17:12:58 -07:00
$frm = e107 :: getForm ();
2016-03-23 17:25:21 -07:00
$forumTitle = e107 :: pref ( 'forum' , 'title' , LAN_PLUGIN_FORUM_NAME );
2013-06-20 17:12:58 -07:00
2016-06-15 10:08:20 +01:00
//-- global $FORUM_CRUMB, $forumInfo, $threadInfo, $thread;
//-- global $BREADCRUMB,$BACKLINK; // Eventually we should deprecate BACKLINK
global $FORUM_CRUMB , $forumInfo , $threadInfo , $thread , $BREADCRUMB ;
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 ))
{
2016-01-26 21:10:19 -08:00
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}' );
2016-03-23 17:25:21 -07:00
$replace = array ( $forumTitle , e107 :: url ( 'forum' , 'index' ));
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
2013-06-20 17:12:58 -07:00
$search = array ( '{PARENT_TITLE}' , '{PARENT_HREF}' );
2015-05-26 12:25:12 -07:00
$replace = array ( $tp -> toHTML ( $forumInfo [ 'parent_name' ]), e107 :: url ( 'forum' , 'index' ) . " # " . $frm -> name2id ( $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}' );
2016-01-26 21:10:19 -08:00
$replace = array ( ltrim ( $forumInfo [ 'sub_parent' ], '*' ), e107 :: url ( 'forum' , 'forum' , array ( 'forum_id' => $forumInfo [ 'parent_id' ], 'forum_sef' => $forumInfo [ 'parent_sef' ])));
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}' );
2016-01-26 21:10:19 -08:00
$replace = array ( ltrim ( $forumInfo [ 'forum_name' ], '*' ), e107 :: url ( 'forum' , 'forum' , $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}' );
2016-01-26 21:10:19 -08:00
$replace = array ( vartrue ( $threadInfo [ 'thread_name' ]), '' ); // $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-06-26 02:28:24 -07:00
2013-03-26 12:33:03 +01:00
$BREADCRUMB = $tp -> parseTemplate ( '{BREADCRUMB=FORUM_CRUMB}' , true );
2006-12-02 04:36:16 +00:00
}
else
{
2016-01-26 21:10:19 -08:00
2008-12-14 03:18:45 +00:00
$dfltsep = ' :: ' ;
2016-02-28 13:08:43 -08:00
$BREADCRUMB = " <a class='forumlink' href=' " . e_HTTP . " index.php'> " . SITENAME . " </a> " . $dfltsep .
2016-03-23 17:25:21 -07:00
" <a class='forumlink' href=' " . e107 :: url ( 'forum' , 'index' ) . " '> " . $forumTitle . " </a> " . $dfltsep ;
2016-02-28 13:08:43 -08:00
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' ]);
2016-02-28 13:08:43 -08:00
$BREADCRUMB .= " <a class='forumlink' href=' " . e_PLUGIN_ABS . " 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 ); }
2016-01-26 21:10:19 -08:00
2006-12-02 04:36:16 +00:00
if ( $forum_href )
{
2016-02-28 13:08:43 -08:00
$BREADCRUMB .= " <a class='forumlink' href=' " . e107 :: url ( 'forum' , 'forum' , $forumInfo ) . " '> " . $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 ;
}
}
2013-06-26 02:28:24 -07:00
2015-04-18 15:09:10 -07:00
// New v2.x Bootstrap Standardized Breadcrumb.
2015-06-27 12:07:41 -07:00
// print_a($forumInfo);
// return;
2013-06-26 02:28:24 -07:00
$breadcrumb = array ();
2016-03-23 17:25:21 -07:00
$breadcrumb [] = array ( 'text' => $forumTitle , 'url' => e107 :: url ( 'forum' , 'index' ));
2013-06-26 02:28:24 -07:00
if ( $forumInfo [ 'sub_parent' ])
{
$forum_sub_parent = ( substr ( $forumInfo [ 'sub_parent' ], 0 , 1 ) == '*' ? substr ( $forumInfo [ 'sub_parent' ], 1 ) : $forumInfo [ 'sub_parent' ]);
}
2015-04-25 12:57:00 -07:00
$breadcrumb [] = array ( 'text' => $tp -> toHTML ( $forumInfo [ 'parent_name' ]) , 'url' => e107 :: url ( 'forum' , 'index' ) . " # " . $frm -> name2id ( $forumInfo [ 'parent_name' ]));
2013-06-26 02:28:24 -07:00
if ( $forumInfo [ 'forum_sub' ])
{
2015-06-27 12:07:41 -07:00
$breadcrumb [] = array ( 'text' => ltrim ( $forumInfo [ 'sub_parent' ], '*' ) , 'url' => e107 :: url ( 'forum' , 'forum' , array ( 'forum_sef' => $forumInfo [ 'parent_sef' ])));
$breadcrumb [] = array ( 'text' => ltrim ( $forumInfo [ 'forum_name' ], '*' ) , 'url' => ( e_PAGE != 'forum_viewforum.php' ) ? e107 :: url ( 'forum' , 'forum' , $forumInfo ) : null );
2013-06-26 02:28:24 -07:00
}
2015-06-27 12:07:41 -07:00
else
{
$breadcrumb [] = array ( 'text' => ltrim ( $forumInfo [ 'forum_name' ], '*' ) , 'url' => ( e_PAGE != 'forum_viewforum.php' ) ? e107 :: url ( 'forum' , 'forum' , $forumInfo ) : null );
}
2013-06-26 02:28:24 -07:00
if ( vartrue ( $forumInfo [ 'thread_name' ]))
{
$breadcrumb [] = array ( 'text' => $forumInfo [ 'thread_name' ] , 'url' => null );
}
if ( deftrue ( 'BOOTSTRAP' ))
{
$BREADCRUMB = $frm -> breadcrumb ( $breadcrumb );
}
2016-06-14 13:34:52 +01:00
/*
2006-12-02 04:36:16 +00:00
$BACKLINK = $BREADCRUMB ;
2016-06-14 13:34:52 +01:00
2010-02-01 03:41:59 +00:00
$templateVar -> BREADCRUMB = $BREADCRUMB ;
2013-06-26 02:28:24 -07:00
2010-02-01 03:41:59 +00:00
$templateVar -> BACKLINK = $BACKLINK ;
$templateVar -> FORUM_CRUMB = $FORUM_CRUMB ;
2016-06-14 13:34:52 +01:00
*/
// Backlink shortcode is defined inside shortcode file....
//---- var_dump ($templateVar);
//---- echo "<hr>";
$templateVar [ 'breadcrumb' ] = $BREADCRUMB ;
$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
2014-08-04 15:51:39 +02:00
if ( $sql -> select ( 'polls' , '*' , 'poll_datestamp=' . $threadId ))
{
$sql -> delete ( 'polls' , 'poll_datestamp=' . $threadId );
}
// decrement user post counts
2008-12-18 18:32:54 +00:00
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
2014-08-04 15:51:39 +02:00
if ( $sql -> select ( 'forum_post' , 'post_id' , 'post_thread = ' . $threadId ))
2008-12-18 18:32:54 +00:00
{
$postList = array ();
2016-02-14 12:15:55 -08:00
while ( $row = $sql -> fetch ())
2008-12-18 18:32:54 +00:00
{
$postList [] = $row [ 'post_id' ];
}
2014-08-04 15:51:39 +02:00
2008-12-18 18:32:54 +00:00
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 ))
{
2015-02-10 10:32:37 +01:00
$status = true ;
2015-02-12 16:52:30 -08:00
e107 :: getEvent () -> trigger ( 'user_forum_topic_deleted' , $threadId );
2013-03-12 20:35:04 -07:00
}
2008-12-23 20:48:24 +00:00
2008-12-18 18:32:54 +00:00
//Delete any thread tracking
2014-08-04 15:51:39 +02:00
if ( $sql -> select ( 'forum_track' , '*' , 'track_thread=' . $threadId ))
{
$sql -> delete ( 'forum_track' , 'track_thread=' . $threadId );
}
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
2014-08-04 15:42:06 +02:00
2016-02-14 12:15:55 -08:00
$row = $sql -> fetch ();
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
2014-08-04 15:42:06 +02:00
// delete post from database
2013-03-14 16:25:24 -07:00
if ( $sql -> delete ( 'forum_post' , 'post_id=' . $postId ))
{
2015-02-10 10:32:37 +01:00
$deleted = true ;
2015-02-12 16:52:30 -08:00
e107 :: getEvent () -> trigger ( 'user_forum_post_deleted' , $postId );
2013-03-14 16:25:24 -07:00
}
2008-12-23 20:48:24 +00:00
2014-08-04 15:42:06 +02:00
// update statistics
2008-12-18 18:32:54 +00:00
if ( $updateCounts )
{
2014-08-04 15:42:06 +02:00
// decrement user post counts
2008-12-18 18:32:54 +00:00
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
2016-02-10 19:51:32 -08:00
/**
* Check for legacy Prefernces and upgrade if neccessary .
*/
public function upgradeLegacyPrefs ()
{
e107 :: getMessage () -> addDebug ( " Legacy Forum Menu Pref Detected. Upgrading.. " );
$legacyMenuPrefs = array (
'newforumposts_caption' => 'caption' ,
'newforumposts_display' => 'display' ,
'newforumposts_maxage' => 'maxage' ,
'newforumposts_characters' => 'chars' ,
'newforumposts_postfix' => 'postfix' ,
'newforumposts_title' => 'title'
);
if ( $newPrefs = e107 :: getConfig ( 'menu' ) -> migrateData ( $legacyMenuPrefs , true )) // returns false if no match found.
{
if ( e107 :: getMenu () -> setParms ( 'forum' , 'newforumposts_menu' , $newPrefs ) !== false )
{
e107 :: getMessage () -> addDebug ( " Sucessfully Migrated newforumposts prefs from core to menu table. " );
}
else
{
e107 :: getMessage () -> addDebug ( " Legacy Forum Menu Pref Detected. Upgrading.. " );
}
}
}
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
2015-01-30 18:14:06 -08:00
2006-12-02 04:36:16 +00:00
*
* @ 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
2015-01-30 18:14:06 -08:00
* default forum icon image in e_IMAGES . The additional args if specfied switch the process
* to the sister multi - language function
2006-12-02 04:36:16 +00:00
*
* @ 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
{
2015-06-26 18:13:08 -07:00
$image = ( $ML && is_readable ( THEME . 'forum/' . e_LANGUAGE . '_' . $filename )) ? THEME_ABS . 'forum/' . e_LANGUAGE . " _ " . $filename : THEME_ABS . '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 )
{
2015-06-26 18:13:08 -07:00
$image = ( is_readable ( e_PLUGIN . 'forum/images/icons/' . e_LANGUAGE . '_' . $filename )) ? e_PLUGIN_ABS . 'forum/images/icons/' . e_LANGUAGE . '_' . $filename : e_PLUGIN_ABS . 'forum/images/icons/English_' . $filename ;
2006-12-02 04:36:16 +00:00
}
else
{
2015-06-26 18:13:08 -07:00
$image = e_PLUGIN_ABS . 'forum/images/icons/' . $filename ;
2006-12-02 04:36:16 +00:00
}
}
else
{
if ( $ML )
{
2015-06-26 18:13:08 -07:00
$image = ( is_readable ( e_PLUGIN . " forum/images/lite/ " . e_LANGUAGE . '_' . $filename )) ? e_PLUGIN_ABS . 'forum/images/icons/' . e_LANGUAGE . '_' . $filename : e_PLUGIN_ABS . 'forum/images/icons/English_' . $filename ;
2006-12-02 04:36:16 +00:00
}
else
{
2015-06-26 18:13:08 -07:00
$image = e_PLUGIN_ABS . 'forum/images/icons/' . $filename ;
2006-12-02 04:36:16 +00:00
}
}
}
return $image ;
}
2013-07-08 11:42:22 -07:00
2006-12-02 04:36:16 +00:00
?>