Source for file forum.inc.php
Documentation is available at forum.inc.php
* @author Matthias Reuter ($LastChangedBy: matthias $)
* @version $LastChangedDate: 2009-08-26 19:19:41 +0200 (Mi, 26 Aug 2009) $
* @copyright 2007-2010 IPBWI development team
* @link http://ipbwi.com/examples/forum.php
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
* @desc Loads and checks different vars when class is initiating
* @author Matthias Reuter
public function __construct($ipbwi){
* @desc Converts forum name to forum-ids
* @param string $name Forum's Name
* @author Matthias Reuter
* $ipbwi->forum->name2id('forumname');
$sql = $this->ipbwi->ips_wrapper->DB->query('SELECT id FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'forums WHERE name="'. addslashes(htmlentities($name)). '"');
$forums = $this->ipbwi->ips_wrapper->DB->fetch($sql);
if($this->ipbwi->ips_wrapper->DB->getTotalRows($sql) == 0){
// return matching forum-id
// return array of matched forum-ids
* @desc Returns information on a forum.
* @param int $forumID Forum's ID
* @return array Forum's Information.
* @author Matthias Reuter
* $ipbwi->forum->info(55);
public function info($forumID){
if($cache = $this->ipbwi->cache->get('forumInfo', $forumID)){
$sql = $this->ipbwi->ips_wrapper->DB->query('SELECT f.* from '. $this->ipbwi->board['sql_tbl_prefix']. 'forums f WHERE f.id="'. $forumID. '"');
if($row = $this->ipbwi->ips_wrapper->DB->fetch($sql)){
$row['last_poster_name'] = $this->ipbwi->properXHTML($row['last_poster_name']);
$row['name'] = $this->ipbwi->properXHTML($row['name']);
$row['description'] = $this->ipbwi->properXHTML($row['description']);
$row['last_title'] = $this->ipbwi->properXHTML($row['last_title']);
$row['newest_title'] = $this->ipbwi->properXHTML($row['newest_title']);
$perms = $this->ipbwi->permissions->sort($row['permission_array']);
$row['read_perms'] = $perms['read_perms'];
$row['reply_perms'] = $perms['reply_perms'];
$row['start_perms'] = $perms['start_perms'];
$row['upload_perms'] = $perms['upload_perms'];
$row['show_perms'] = $perms['show_perms'];
$this->ipbwi->cache->save('forumInfo', $forumID, $row);
* @desc Returns forum permission data
* @param string $field, these are allowed: perm_view, perm_2, perm_3, perm_4, perm_5, perm_6, perm_7
* @return array permission data
* @author Matthias Reuter
* $ipbwi->forum->getData('perm_view');
private function getData($field){
// search in permission index
$query = 'SELECT perm_type_id, '. $field. ' FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'permission_index WHERE perm_type = "forum"';
$sql = $this->ipbwi->ips_wrapper->DB->query($query);
while($row = $this->ipbwi->ips_wrapper->DB->fetch($sql)){
if(strpos($row[$field],','. $this->ipbwi->member->myInfo['g_perm_id']. ',') !== false || $row[$field] == '*'){
$forums[$row['perm_type_id']] = $row['perm_type_id'];
* @desc Returns whether a forum can be read by the current member.
* @param int $forumID Forum's ID
* @return bool Forum is readable
* @author Matthias Reuter
* $ipbwi->forum->isReadable(55);
if(isset ($readable[$forumID])){
* @desc Returns forums readable by the current member.
* @return array Readable Forum Details
* @author Matthias Reuter
* $ipbwi->forum->getReadable();
if($cache = $this->ipbwi->cache->get('forumsGetReadable', $this->ipbwi->member->myInfo['member_id'])){
$forums = $this->getData('perm_2');
$this->ipbwi->cache->save('forumsGetReadable', $this->ipbwi->member->myInfo['member_id'], $forums);
* @desc Returns whether a forum can be posted in by the current member.
* @param int $forumID Forum's ID
* @return bool Forum is postable in
* @author Matthias Reuter
* $ipbwi->forum->isPostable(55);
if(isset ($postable[$forumID])){
* @desc Returns forums postable in by the current member.
* @return array Postable Forum Details
* @author Matthias Reuter
* $ipbwi->forum->getPostable();
if($cache = $this->ipbwi->cache->get('forumsGetPostable', $this->ipbwi->member->myInfo['member_id'])){
$forums = $this->getData('perm_3');
$this->ipbwi->cache->save('forumsGetPostable', $this->ipbwi->member->myInfo['member_id'], $forums);
* @desc Returns whether a forum can start topics in.
* @param int $forumID Forum's ID
* @return bool Forum is startable in.
* @author Matthias Reuter
* $ipbwi->forum->isStartable(55);
if(isset ($startable[$forumID])){
* @desc Returns forums in which the current member can start new topics in.
* @return array Startable Forum Details
* @author Matthias Reuter
* $ipbwi->forum->getStartable();
if($cache = $this->ipbwi->cache->get('forumsGetStartable', $this->ipbwi->member->myInfo['member_id'])){
$forums = $this->getData('perm_4');
$this->ipbwi->cache->save('forumsGetStartable', $this->ipbwi->member->myInfo['member_id'], $forums);
* @desc Returns whether a forum can have uploads in topics
* @param int $forumID Forum's ID
* @return bool Forum allows uploads.
* @author Matthias Reuter
* $ipbwi->forum->isUploadable(55);
if(isset ($uploadable[$forumID])){
* @desc Returns forums in which the current member can upload in topics.
* @return array Uploadable Forum Details
* @author Matthias Reuter
* $ipbwi->forum->getUploadable();
if($cache = $this->ipbwi->cache->get('forumsgetUploadable', $this->ipbwi->member->myInfo['member_id'])){
$forums = $this->getData('perm_5');
$this->ipbwi->cache->save('forumsgetUploadable', $this->ipbwi->member->myInfo['member_id'], $forums);
* @desc Returns whether a forum can have downloads in topics
* @param int $forumID Forum's ID
* @return bool Forum allows downloads.
* @author Matthias Reuter
* $ipbwi->forum->isDownloadable(55);
if(isset ($Downloadable[$forumID])){
* @desc Returns forums in which the current member can download in topics.
* @return array Downloadable Forum Details
* @author Matthias Reuter
* $ipbwi->forum->getDownloadable();
if($cache = $this->ipbwi->cache->get('forumsgetDownloadable', $this->ipbwi->member->myInfo['member_id'])){
$forums = $this->getData('perm_5');
$this->ipbwi->cache->save('forumsgetDownloadable', $this->ipbwi->member->myInfo['member_id'], $forums);
* @desc Returns all subforums of the delivered forums.
* @param mixed $forums Forum IDs as int or array
* @param string $outputType The following output types are supported:<br>
* 'html_form' to get a list of <option>-tags<br>
* 'array' (default) for an array-list<br>
* 'array_ids_only' for an array-list with forum IDs only<br>
* 'name_id_with_indent' for an array list of names with indent according to the forum structure
* @param string $indentString The string for indent, default is '-'
* @return mixed List of all subforums
* @author Matthias Reuter
* $ipbwi->forum->getAllSubs(array(55,22,77),'html_form');
public function getAllSubs($forums,$outputType= 'array',$indentString= '—',$indent= false,$selectedID= false){
// get all categories, if needed
// get forum information of requested category
$forums = array($this->info($forums));
// save original indent string
// grab all forums from every delivered cat-id
if($outputType == 'html_form'){ // give every forum its own option-tag
$output .= '<option'. (($selectedID == $i['id']) ? ' selected="selected"' : ''). (($i['parent_id'] == '-1') ? ' style="background-color:#2683AE;color:#FFF;font-weight:bold;"' : ' style="color:#666;"'). ' value="'. $i['id']. '"> '. $indent. ' '. $i['name']. '</option>';
}elseif($outputType == 'array'){ // merge all forum-data in one, big array
}elseif($outputType == 'array_ids_only'){ // merge all forum-data in one, big array
$output[$i['id']] = $i['id'];
}elseif($outputType == 'name_id_with_indent'){ // return name and id, with indent
$output[$i['id']]['id'] = $i['id'];
$output[$i['id']]['name'] = $indent. $i['name'];
// grab all subforums from each delivered cat-id
$sql = 'SELECT '. $select. ' FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'forums WHERE parent_id = '. (isset ($i['id']) ? $i['id'] : $i). ' ORDER BY position ASC';
if($subqery = $this->ipbwi->ips_wrapper->DB->query($sql)){
$indent = $indent. $indentString;
// get all subforums in an array
while($row = $this->ipbwi->ips_wrapper->DB->fetch($subqery)){
if($outputType == 'array_ids_only'){
$subforums[$row['id']] = $row;
}elseif($outputType == 'name_id_with_indent'){
$subforums[$row['id']]['id'] = $row['id'];
$subforums[$row['id']]['name'] = $this->ipbwi->properXHTML($row['name']);
$row['last_poster_name'] = $this->ipbwi->properXHTML($row['last_poster_name']);
$row['name'] = $this->ipbwi->properXHTML($row['name']);
$row['description'] = $this->ipbwi->properXHTML($row['description']);
$row['last_title'] = $this->ipbwi->properXHTML($row['last_title']);
$row['newest_title'] = $this->ipbwi->properXHTML($row['newest_title']);
$subforums[$row['id']] = $row;
if(isset ($subforums) && is_array($subforums) && count($subforums) > 0){
if($outputType == 'html_form'){
// give every forum its own option-tag
$output .= $this->getAllSubs($subforums,$outputType,$indentString,$indent,$selectedID);
}elseif($outputType == 'array' || $outputType == 'array_ids_only'){
// merge all forum-data in one, big array
$output = $output+ $this->getAllSubs($subforums,$outputType,$indentString,$indent,$selectedID);
}elseif($outputType == 'name_id_with_indent'){
$output = $output+ $this->getAllSubs($subforums,$outputType,$indentString,$indent,$selectedID);
* @desc Deletes the forum with delivered forum_id including all subforums, topics, polls and posts.
* @param int $forumID Forum's ID
* @return bool true or false
* @author Matthias Reuter
* $ipbwi->forum->delete(55);
public function delete($forumID){
if(isset ($forumsArray) && is_array($forumsArray) && count($forumsArray) > 0){
if($this->ipbwi->ips_wrapper->DB->query('SELECT tid FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'topics WHERE forum_id IN ('. $forumsString. ')')){
while($row = $this->ipbwi->ips_wrapper->DB->fetch()){
$topicsArray[] = $row['tid'];
if(isset ($topicsArray) && is_array($topicsArray) && count($topicsArray) > 0){
$topicsString = '"'. implode('","',$topicsArray). '"';
if(isset ($topicsString)){
$this->ipbwi->ips_wrapper->DB->query('DELETE FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'posts WHERE topic_id IN ('. $topicsString. ')');
if(isset ($topicsString)){
$this->ipbwi->ips_wrapper->DB->query('DELETE FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'polls WHERE tid IN ('. $topicsString. ')');
if(isset ($forumsString)){
$this->ipbwi->ips_wrapper->DB->query('DELETE FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'topics WHERE forum_id IN ('. $forumsString. ')');
if(isset ($forumsString)){
$this->ipbwi->ips_wrapper->DB->query('DELETE FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'forums WHERE id IN ('. $forumsString. ')');
$this->ipbwi->ips_wrapper->update_forum_cache();
* @desc Creates a forum in the specified category
* @param string $forumName Forum's name
* @param string $forumDesc Forum's description
* @param catID $forumID Categories ID
* @param perms $forumID Forum's permissions as array
* + int <b>$perms[startperms]:</b> Group IDs for Start posts permission
* + int <b>$perms[replyperms]:</b> Group IDs for Reply-To posts permission
* + int <b>$perms[readperms]:</b> Group IDs for Read posts permission
* + int <b>$perms[uploadperms]:</b> Group IDs for Fileupload permission
* + int <b>$perms[showperms]:</b> Group IDs for Show permission
* @return long new forum's ID or false
* @author Matthias Reuter
* $ipbwi->forum->create('Forumname','Forum Description',2,array('show' => '*','read' => '*','start' => '*','reply' => '*','upload' => '*','download' => '*'));
public function create($forumName, $forumDesc, $catID, $perms){
$forumName = $this->ipbwi->makeSafe($forumName);
$forumDesc = $this->ipbwi->makeSafe($forumDesc);
$this->ipbwi->ips_wrapper->DB->query('LOCK TABLE '. $this->ipbwi->board['sql_tbl_prefix']. 'forums WRITE');
$this->ipbwi->ips_wrapper->DB->query('SELECT MAX(id) as max FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'forums');
$row = $this->ipbwi->ips_wrapper->DB->fetch();
$this->ipbwi->ips_wrapper->DB->query('UNLOCK TABLES');
$this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'forums WHERE id="'. intval($catID). '"');
if(!$this->ipbwi->ips_wrapper->DB->fetch()){
$this->ipbwi->addSystemMessage('Error',$this->ipbwi->getLibLang('catNotExist'),'Located in file <strong>'.__FILE__. '</strong> at class <strong>'.__CLASS__. '</strong> in function <strong>'.__FUNCTION__. '</strong> on line #<strong>'.__LINE__. '</strong>');
$this->ipbwi->ips_wrapper->DB->query('SELECT MAX(position) as pos FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'forums WHERE parent_id="'. intval($catID). '"');
$row = $this->ipbwi->ips_wrapper->DB->fetch();
'start_perms' => $perms['start'],
'reply_perms' => $perms['reply'],
'read_perms' => $perms['read'],
'upload_perms' => $perms['upload'],
'download_perms' => $perms['download'],
'show_perms' => $perms['show']
$this->ipbwi->ips_wrapper->DB->query('SELECT perm_id FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'forum_perms');
while($groupsr = $this->ipbwi->ips_wrapper->DB->fetch()){
$groups[] = $groupsr['perm_id'];
foreach($permissions as $i => $j){
// if permission is to be set for category
if($j == '*' && $catID == '-1'){
$permsfinal[$i] = implode (',', $x);
// if permission is to be set for forum
$permsfinal[$i] = implode (',', $x);
// Finally Add it to the Database
$DB_string = $this->ipbwi->ips_wrapper->DB->compile_db_insert_string(
'last_poster_name' => '',
'description' => $forumDesc,
'password_override' => '',
'sort_key' => 'last_post',
'notify_modq_emails' => '',
'permission_custom_error'=> '',
'permission_array' => $perm_array,
'permission_showtopic' => 1,
'forum_last_deletion' => 0,
'forum_allow_rating' => 0,
'newest_title' => 'NULL',
$DB_string = $this->ipbwi->ips_wrapper->DB->compile_db_insert_string(
'last_poster_name' => '',
'description' => $forumDesc,
'password_override' => '',
'sort_key' => 'last_post',
'parent_id' => intval($catID),
'notify_modq_emails' => '',
'permission_custom_error' => '',
'permission_array' => $perm_array,
'permission_showtopic' => 0,
'forum_last_deletion' => 0,
'forum_allow_rating' => 1,
$this->ipbwi->ips_wrapper->DB->query('LOCK TABLE '. $this->ipbwi->board['sql_tbl_prefix']. 'forums WRITE');
$this->ipbwi->ips_wrapper->DB->query('INSERT INTO '. $this->ipbwi->board['sql_tbl_prefix']. 'forums ('. $DB_string['FIELD_NAMES']. ') VALUES ('. $DB_string['FIELD_VALUES']. ')');
$this->ipbwi->ips_wrapper->DB->query('UNLOCK TABLES');
$this->ipbwi->ips_wrapper->update_forum_cache();
* @return array Board's Categories
* @author Matthias Reuter
* $ipbwi->forum->catList();
if($cache = $this->ipbwi->cache->get('listCategories', '1')){
$query = $this->ipbwi->ips_wrapper->DB->query('SELECT * FROM '. $this->ipbwi->board['sql_tbl_prefix']. 'forums WHERE parent_id = "-1"');
if($this->ipbwi->ips_wrapper->DB->getTotalRows() == 0) return false;
while($row = $this->ipbwi->ips_wrapper->DB->fetch($query)){
$row['last_poster_name'] = $this->ipbwi->properXHTML($row['last_poster_name']);
$row['name'] = $this->ipbwi->properXHTML($row['name']);
$row['description'] = $this->ipbwi->properXHTML($row['description']);
$row['last_title'] = $this->ipbwi->properXHTML($row['last_title']);
$row['newest_title'] = $this->ipbwi->properXHTML($row['newest_title']);
$this->ipbwi->cache->save('listCategories', '1', $cat);
* @desc Get Information on a Category
* @param int $catID Unique ID of the category
* @return array Information of category categoryid
* @author Matthias Reuter
* $ipbwi->forum->categoryInfo(5);
|