/inc/class.MyBBIntegrator.php
PHP | 3406 lines | 2107 code | 462 blank | 837 comment | 425 complexity | 0b93b9726a5e3f87e6110875d1acfc3c MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * MyBBIntegrator - The integration class for MyBB and your website
- *
- * The MyBBIntegrator is a useful collection of variables and functions for easy MyBB integration
- * into the own website
- *
- * @author: David Olah (aka PHPDave - http://phpdave.com)
- * @version 1.3.1
- * @date July 2010
- * @copyright Copyright (c) 2009, David Olah
- *
- *
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- class MyBBIntegrator
- {
- /**
- * Cache Handler of MyBB
- *
- * @var object
- */
- var $cache;
-
- /**
- * Config Data of MyBB
- *
- * @var array
- */
- var $config;
-
- /**
- * Database Handler of MyBB
- *
- * @var object
- */
- var $db;
-
- /**
- * MyBB Super Variable containing a whole lot of information
- *
- * @var object
- */
- var $mybb;
-
- /**
- * MyBB's Post Parser
- *
- * @var object
- */
- var $parser;
-
- /**
- * Shows a message for errors occuring in this class.
- * Afterwards it stops the script
- *
- * @param string $message The error message
- */
- function _errorAndDie($message)
- {
- echo '<div style="width:92%; margin:4px auto; border:1px #DDD solid; background:#F1F1F1; padding:5px; color:#C00; font-weight:bold;">An error occured during script run.<br />'.$message.'</div>';
- die;
- }
-
- /**
- * Let's see if the correct password is given for a forum!
- * Possible Todo: Pass passowrds in an array for defining passwords for parent categories (so far this only works when parent foums have same pass)
- *
- * @param integer $forum_id ID of Forum
- * @param string $password Wow, what might this be??
- * @return boolean
- */
- function checkForumPassword($forum_id, $password = '', $pid = 0)
- {
- global $forum_cache;
-
- if(!is_array($forum_cache))
- {
- $forum_cache = cache_forums();
- if(!$forum_cache)
- {
- return false;
- }
- }
-
- // Loop through each of parent forums to ensure we have a password for them too
- $parents = explode(',', $forum_cache[$fid]['parentlist']);
- rsort($parents);
- if(!empty($parents))
- {
- foreach($parents as $parent_id)
- {
- if($parent_id == $forum_id || $parent_id == $pid)
- {
- continue;
- }
-
- if($forum_cache[$parent_id]['password'] != "")
- {
- if (!$this->checkForumPassword($parent_id, $password))
- {
- return false;
- }
- }
-
- }
- }
-
- $forum_password = $forum_cache[$forum_id]['password'];
-
- // A password is required
- if ($forum_password)
- {
- if (empty($password))
- {
- if (!$this->mybb->cookies['forumpass'][$forum_id] || ($this->mybb->cookies['forumpass'][$forum_id] && md5($this->mybb->user['uid'].$forum_password) != $this->mybb->cookies['forumpass'][$forum_id]))
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- else
- {
- if ($forum_password == $password)
- {
- $this->setCookie('forumpass['.$forum_id.']', md5($this->mybb->user['uid'].$password), NULL, true);
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- else
- {
- return true;
- }
- }
-
- /**
- * Enables you to close one or more threads
- * One thread: $thread_id is int
- * More threads: $thread_id is array with ints
- *
- * @param integer|array $thread_id See above
- * @param integer $forum_id This can be filled for a nice moderator log!
- * @return boolean
- */
- function closeThread($thread_id, $forum_id = 0)
- {
- if (!is_moderator($fid, "canopenclosethreads"))
- {
- return false;
- }
-
- $this->lang->load('moderation');
-
- $this->MyBBIntegratorClassObject('moderation', 'Moderation', MYBB_ROOT.'/inc/class_moderation.php');
-
- $this->moderation->close_threads($thread_id);
-
- $modlogdata['fid'] = $forum_id;
-
- $this->logModeratorAction($modlogdata, $this->lang->mod_process);
-
- return true;
- }
-
- /**
- * Insert a new Category into Database
- *
- * @param array $data Array with keys according to database layout, which holds the data of the forum
- * @param array $permissions Array with Permission entries (structure: array( 'canview' => array( 'usergroupid' => 1 ) )) (an example)
- * @param array $default_permissions Array which defines, if default permissions shall be used (structure: array( usergroupid => 0 / 1 )
- * Can be left empty, then this function will take care of it
- * @return $data with more values, like fid and parentlist
- */
- function createCategory($data, $permissions = array(), $default_permissions = array())
- {
- require_once MYBB_ADMIN_DIR.'inc/functions.php';
-
- if (!isset($data['name']))
- {
- $this->_errorAndDie('A new forum needs to have a name and a type');
- }
-
- $data['type'] = 'c';
-
- // Let's leave the parentlist creation to the script and let's not trust the dev :)
- if ($data['parentlist'] != '')
- {
- $data['parentlist'] = '';
- }
-
- // If there is no defined Parent ID, parent ID will be set to 0
- if (!isset($data['pid']) || $data['pid'] < 0)
- {
- $data['pid'] = 0;
- }
- else
- {
- $data['pid'] = intval($data['pid']);
- }
-
- if (!empty($permissions))
- {
- if (
- (!isset($permissions['canview']) || empty($permissions['canview'])) ||
- (!isset($permissions['canpostthreads']) || empty($permissions['canpostthreads'])) ||
- (!isset($permissions['canpostreplys']) || empty($permissions['canpostreplys'])) ||
- (!isset($permissions['canpostpolls']) || empty($permissions['canpostpolls'])) ||
- (!isset($permissions['canpostattachments']) || empty($permissions['canpostattachments']))
- )
- {
- $this->_errorAndDie('The $permissions Parameter does not have the correct format. It requires following keys: <i>canview, canpostthreads, canpostreplys, canpostpolls and canpostattachments</i>');
- }
-
- /**
- * If no default permissions are given, we will initiate them, default: yes
- * Since there is the possibility of additional usergroups, we will get the usergroups from the permissions array!
- * The structure of the inherit array is: keys = groupid
- * If the value of an inherit array item is 1, this means that the default_permissions shall be used
- */
- if (empty($default_permissions))
- {
- foreach ($permissions['canview'] as $gid)
- {
- $default_permissions[$gid] = 1;
- }
- }
- }
-
- $data['fid'] = $this->db->insert_query("forums", $data);
-
- $data['parentlist'] = make_parent_list($data['fid']);
- $this->db->update_query("forums", array("parentlist" => $data['parentlist']), 'fid=\''.$data['fid'].'\'');
-
- $this->cache->update_forums();
-
- if (!empty($permissions))
- {
- $inherit = $default_permissions;
-
- /**
- * $permissions['canview'][1] = 1 OR $permissions['canview'][1] = 0
- * --> $permissions[$name][$gid] = yes / no
- */
-
- $canview = $permissions['canview'];
- $canpostthreads = $permissions['canpostthreads'];
- $canpostpolls = $permissions['canpostpolls'];
- $canpostattachments = $permissions['canpostattachments'];
- $canpostreplies = $permissions['canpostreplys'];
- save_quick_perms($data['fid']);
- }
-
- return $data;
- }
-
- /**
- * Insert a new Forum into Database
- *
- * @param array $data Array with keys according to database layout, which holds the data of the forum
- * @param array $permissions Array with Permission entries (structure: array( 'canview' => array( 'usergroupid' => 1 ) )) (an example)
- * @param array $default_permissions Array which defines, if default permissions shall be used (structure: array( usergroupid => 0 / 1 )
- * Can be left empty, then this function will take care of it
- * @return $data with more values, like fid and parentlist
- */
- function createForum($data, $permissions = array(), $default_permissions = array())
- {
- require_once MYBB_ADMIN_DIR.'inc/functions.php';
-
- if (!isset($data['name']))
- {
- $this->_errorAndDie('A new forum needs to have a name and a type');
- }
-
- $data['type'] = 'f';
-
- // Let's leave the parentlist creation to the script and let's not trust the dev :)
- if ($data['parentlist'] != '')
- {
- $data['parentlist'] = '';
- }
-
- // If there is no defined Parent ID, parent ID will be set to 0
- if (!isset($data['pid']) || $data['pid'] < 0)
- {
- $data['pid'] = 0;
- }
- else
- {
- $data['pid'] = intval($data['pid']);
- }
-
- if (!empty($permissions))
- {
- if (
- (!isset($permissions['canview']) || empty($permissions['canview'])) ||
- (!isset($permissions['canpostthreads']) || empty($permissions['canpostthreads'])) ||
- (!isset($permissions['canpostreplys']) || empty($permissions['canpostreplys'])) ||
- (!isset($permissions['canpostpolls']) || empty($permissions['canpostpolls'])) ||
- (!isset($permissions['canpostattachments']) || empty($permissions['canpostattachments']))
- )
- {
- $this->_errorAndDie('The $permissions Parameter does not have the correct format. It requires following keys: <i>canview, canpostthreads, canpostreplys, canpostpolls and canpostattachments</i>');
- }
-
- /**
- * If no default permissions are given, we will initiate them, default: yes
- * Since there is the possibility of additional usergroups, we will get the usergroups from the permissions array!
- * The structure of the inherit array is: keys = groupid
- * If the value of an inherit array item is 1, this means that the default_permissions shall be used
- */
- if (empty($default_permissions))
- {
- foreach ($permissions['canview'] as $gid)
- {
- $default_permissions[$gid] = 1;
- }
- }
- }
-
- $data['fid'] = $this->db->insert_query("forums", $data);
-
- $data['parentlist'] = make_parent_list($data['fid']);
- $this->db->update_query("forums", array("parentlist" => $data['parentlist']), 'fid=\''.$data['fid'].'\'');
-
- $this->cache->update_forums();
-
- if (!empty($permissions))
- {
- $inherit = $default_permissions;
-
- /**
- * $permissions['canview'][1] = 1 OR $permissions['canview'][1] = 0
- * --> $permissions[$name][$gid] = yes / no
- */
-
- $canview = $permissions['canview'];
- $canpostthreads = $permissions['canpostthreads'];
- $canpostpolls = $permissions['canpostpolls'];
- $canpostattachments = $permissions['canpostattachments'];
- $canpostreplies = $permissions['canpostreplys'];
- save_quick_perms($data['fid']);
- }
-
- return $data;
- }
-
- /**
- * Create a new poll and assign it to a thread
- * Taken frm polls.php
- *
- * @param integer $thread_id ID of Thread where the poll should be assigned to
- * @param array $data The Data
- */
- function createPoll($thread_id, $data)
- {
- // Required keys in data array: options, question
- if (!isset($data['options']) || !isset($data['question']))
- {
- $this->_errorAndDie('One or more required array keys in parameter <i>$data</i> missing. Required keys are: <i>options</i>, <i>question</i>');
- }
-
- $this->lang->load('polls');
-
- $this->plugins->run_hooks("polls_do_newpoll_start");
- $query = $this->db->simple_select("threads", "*", "tid='".(int) $thread_id."'");
- $thread = $this->db->fetch_array($query);
- $fid = $thread['fid'];
- $forumpermissions = forum_permissions($fid);
-
- if (!$thread['tid'])
- {
- return $this->lang->error_invalidthread;
- }
- // No permission if: Not thread author; not moderator; no forum perms to view, post threads, post polls
- if (($thread['uid'] != $this->mybb->user['uid'] && !is_moderator($fid)) || ($forumpermissions['canview'] == 0 || $forumpermissions['canpostthreads'] == 0 || $forumpermissions['canpostpolls'] == 0))
- {
- return false;
- }
-
- if ($thread['poll'])
- {
- return $this->lang->error_pollalready;
- }
-
- $polloptions = count($data['options']);
- if($this->mybb->settings['maxpolloptions'] && $polloptions > $this->mybb->settings['maxpolloptions'])
- {
- $polloptions = $this->mybb->settings['maxpolloptions'];
- }
-
- if (!isset($data['postoptions']))
- {
- $data['postoptions'] = array('multiple', 'public');
- }
-
- $postoptions = $data['postoptions'];
-
- if ($postoptions['multiple'] != '1')
- {
- $postoptions['multiple'] = 0;
- }
-
- if ($postoptions['public'] != '1')
- {
- $postoptions['public'] = 0;
- }
-
- if ($polloptions < 2)
- {
- $polloptions = "2";
- }
-
- $optioncount = "0";
-
- $options = $data['options'];
-
- for($i = 0; $i < $polloptions; ++$i)
- {
- if (trim($options[$i]) != "")
- {
- $optioncount++;
- }
-
- if (my_strlen($options[$i]) > $this->mybb->settings['polloptionlimit'] && $this->mybb->settings['polloptionlimit'] != 0)
- {
- $lengtherror = 1;
- break;
- }
- }
-
- if ($lengtherror)
- {
- return $this->lang->error_polloptiontoolong;
- }
-
- if (empty($data['question']) || $optioncount < 2)
- {
- return $this->lang->error_noquestionoptions;
- }
-
- $optionslist = '';
- $voteslist = '';
- for($i = 0; $i < $optioncount; ++$i)
- {
- if(trim($options[$i]) != '')
- {
- if($i > 0)
- {
- $optionslist .= '||~|~||';
- $voteslist .= '||~|~||';
- }
- $optionslist .= $options[$i];
- $voteslist .= '0';
- }
- }
-
- if (!isset($data['timeout']))
- {
- $data['timeout'] = 0;
- }
-
- if($data['timeout'] > 0)
- {
- $timeout = intval($data['timeout']);
- }
- else
- {
- $timeout = 0;
- }
-
- $newpoll = array(
- "tid" => $thread['tid'],
- "question" => $this->db->escape_string($data['question']),
- "dateline" => TIME_NOW,
- "options" => $this->db->escape_string($optionslist),
- "votes" => $this->db->escape_string($voteslist),
- "numoptions" => intval($optioncount),
- "numvotes" => 0,
- "timeout" => $timeout,
- "closed" => 0,
- "multiple" => $postoptions['multiple'],
- "public" => $postoptions['public']
- );
-
- $this->plugins->run_hooks("polls_do_newpoll_process");
-
- $pid = $this->db->insert_query("polls", $newpoll);
-
- $this->db->update_query("threads", array('poll' => $pid), "tid='".$thread['tid']."'");
-
- $this->plugins->run_hooks("polls_do_newpoll_end");
-
- return true;
- }
-
- /**
- * Insert a new post into Database
- *
- * @param array $data Post Data
- * @return array|string When true it will return an array with postID and status of being visible - false = error array or inline string
- */
- function createPost($data, $inline_errors = true)
- {
- require_once MYBB_ROOT.'inc/functions_post.php';
- require_once MYBB_ROOT.'/inc/datahandlers/post.php';
- $posthandler = new PostDataHandler('insert');
-
- $this->plugins->run_hooks('newreply_do_newreply_start');
-
- $posthandler->set_data($data);
-
- if (!$posthandler->validate_post())
- {
- $errors = $posthandler->get_friendly_errors();
- return ($inline_errors === true) ? inline_error($errors) : $errors;
- }
-
- $this->plugins->run_hooks('newreply_do_newreply_end');
-
- return $posthandler->insert_post();
- }
-
- /**
- * Inserts a thread into the database
- *
- * @param array $data Thread data
- * @param boolean $inline_errors Defines if we want a formatted error string or an array
- * @return array|string
- * @return array|string When true it will return an array with threadID, postID and status of being visible - false = error array or inline string
- */
- function createThread($data, $inline_errors = true)
- {
- require_once MYBB_ROOT.'inc/functions_post.php';
- require_once MYBB_ROOT.'/inc/datahandlers/post.php';
- $posthandler = new PostDataHandler('insert');
- $posthandler->action = 'thread';
- $posthandler->set_data($data);
- if (!$posthandler->validate_thread())
- {
- $errors = $posthandler->get_friendly_errors();
- return ($inline_errors === true) ? inline_error($errors) : $errors;
- }
- return $posthandler->insert_thread();
- }
-
- /**
- * Insert a new user into Database
- *
- * @param array $data User data
- * @param boolean $inline_errors Defines if we want a formatted error string or an array
- * @return array|string When true it will return an array with some user data - false = error array or inline string
- */
- function createUser($data, $inline_errors = true)
- {
- require_once MYBB_ROOT.'inc/functions_user.php';
- require_once MYBB_ROOT.'/inc/datahandlers/user.php';
- $userhandler = new UserDataHandler('insert');
-
- $this->plugins->run_hooks('admin_user_users_add');
-
- $userhandler->set_data($data);
-
- if (!$userhandler->validate_user())
- {
- $errors = $userhandler->get_friendly_errors();
- return ($inline_errors === true) ? inline_error($errors) : $errors;
- }
-
- $this->plugins->run_hooks('admin_user_users_add_commit');
-
- return $userhandler->insert_user();
- }
-
- /**
- * Escapes a value for DB usage
- *
- * @param mixed $value Any value to use with the database
- * @return string
- */
- function dbEscape($value)
- {
- return $this->db->escape_string($value);
- }
-
- /**
- * Remove a poll
- * Taken from moderation.php
- *
- * @param integer $poll_id ID of Poll to be deleted
- * @return boolean|string
- */
- function deletePoll($poll_id)
- {
- $this->lang->load('moderation');
-
- $this->MyBBIntegratorClassObject('moderation', 'Moderation', MYBB_ROOT.'/inc/class_moderation.php');
-
- $query = $this->db->simple_select("polls", "*", "pid='$poll_id'");
- $poll = $this->db->fetch_array($query);
- if(!$poll['pid'])
- {
- return $this->lang->error_invalidpoll;
- }
-
- $thread = $this->getThread($poll['tid']);
-
- if(!is_moderator($thread['fid'], "candeleteposts"))
- {
- if($permissions['candeletethreads'] != 1 || $this->mybb->user['uid'] != $thread['uid'])
- {
- return false;
- }
- }
-
- $modlogdata = array();
- $modlogdata['tid'] = $poll['tid'];
- $this->plugins->run_hooks("moderation_do_deletepoll");
- $this->lang->poll_deleted = $this->lang->sprintf($this->lang->poll_deleted, $thread['subject']);
- $this->logModeratorAction($modlogdata, $this->lang->poll_deleted);
- $this->moderation->delete_poll($poll['pid']);
-
- return true;
- }
-
- /**
- * Delete the poll of a thread
- * Taken from moderation.php
- *
- * @param integer $thread_id Thread-ID where the poll is located
- * @return boolean|string
- */
- function deletePollOfThread($thread_id)
- {
- $this->lang->load('polls');
- $this->lang->load('moderation');
-
- $this->MyBBIntegratorClassObject('moderation', 'Moderation', MYBB_ROOT.'/inc/class_moderation.php');
-
- $thread = $this->getThread($thread_id);
- $permissions = forum_permissions($thread['fid']);
-
- if (!is_moderator($thread['fid'], "candeleteposts"))
- {
- if($permissions['candeletethreads'] != 1 || $this->mybb->user['uid'] != $thread['uid'])
- {
- return false;
- }
- }
-
- $query = $this->db->simple_select("polls", "*", "tid='$thread_id'");
- $poll = $this->db->fetch_array($query);
- if(!$poll['pid'])
- {
- return $this->lang->error_invalidpoll;
- }
-
- $modlogdata = array();
- $modlogdata['tid'] = $poll['tid'];
- $this->plugins->run_hooks("moderation_do_deletepoll");
- $this->lang->poll_deleted = $this->lang->sprintf($this->lang->poll_deleted, $thread['subject']);
- $this->logModeratorAction($modlogdata, $this->lang->poll_deleted);
- $this->moderation->delete_poll($poll['pid']);
-
- return true;
- }
-
- /**
- * Flag private messages as deleted
- *
- * @param integer|array $pm_id ID(s) of Private Messages (many IDs require an array)
- */
- function deletePrivateMessage($pm_id)
- {
- require_once MYBB_ROOT.'inc/functions_user.php';
-
- $this->plugins->run_hooks('private_delete_start');
-
- $data = array(
- 'folder' => 4,
- 'deletetime' => TIME_NOW
- );
-
- if (is_array($pm_id))
- {
- $this->db->update_query('privatemessages', $data, 'pmid IN ('.implode(',', array_map('intval', $pm_id)).')');
- }
- else
- {
- $this->db->update_query('privatemessages', $data, 'pmid = '.intval($pm_id));
- }
-
- update_pm_count();
-
- $this->plugins->run_hooks('private_delete_end');
-
- }
-
- /**
- * Flag all private messages of a user as deleted
- * It is also possible to flag pms as deleted of multiple users, when paramater is an array with IDs
- *
- * @param integer|array $pm_id ID(s) of User IDs (many IDs require an array)
- */
- function deletePrivateMessagesOfUser($user_id)
- {
- require_once MYBB_ROOT.'inc/functions_user.php';
-
- $this->plugins->run_hooks('private_delete_start');
-
- $data = array(
- 'folder' => 4,
- 'deletetime' => TIME_NOW
- );
-
- if (is_array($user_id))
- {
- $this->db->update_query('privatemessages', $data, 'uid IN ('.implode(',', array_map('intval', $user_id)).')');
- }
- else
- {
- $this->db->update_query('privatemessages', $data, 'uid = '.intval($user_id));
- }
-
- update_pm_count();
-
- $this->plugins->run_hooks('private_delete_end');
- }
-
- /**
- * Generates a Captcha
- *
- * @return array
- */
- function generateCaptcha()
- {
- $randomstr = random_str(5);
- $imagehash = md5(random_str(12));
- $imagearray = array(
- "imagehash" => $imagehash,
- "imagestring" => $randomstr,
- "dateline" => TIME_NOW
- );
- $this->db->insert_query("captcha", $imagearray);
- return array_merge($imagearray, array(
- 'captcha' => '<img src="'.$this->mybb->settings['bburl'].'/captcha.php?imagehash='.$imagehash.'" />'
- ));
- }
-
- /**
- * Generates a posthash
- *
- * @param integer $user_id User-ID
- * @return string MD5
- */
- function generatePosthash($user_id = 0)
- {
- mt_srand((double) microtime() * 1000000);
- if ($user_id == 0)
- {
- return md5($this->mybb->user['uid'].mt_rand());
- }
- else
- {
- return md5($user_id.mt_rand());
- }
- }
-
- /**
- * Get the Hottest Threads within a defined timespan
- *
- * @param integer $timespan The timespan you want to use for fetching the hottest topics (in seconds)
- * @param string $post_sort_order Sort Order to the posts you are fetching (ordered by the dateline)
- * @param string $postamount_sort_order Sort order of the threads (ordered by the amount of posts)
- * @return array
- */
- function getBusyThreadsWithinTimespan($timespan = 86400, $post_sort_order = 'DESC', $postamount_sort_order = 'DESC')
- {
- $threads = array();
-
- // Make sure the parameters have correct values
- $post_sort_order = ($post_sort_order == 'DESC') ? 'DESC' : 'ASC';
- $postamount_sort_order = ($postamount_sort_order == 'DESC') ? 'DESC' : 'ASC';
-
- $query = $this->db->query('
- SELECT p.`pid`, p.`message`, p.`uid` as postuid, p.`username` as postusername, p.`dateline`,
- t.`tid`, t.`fid`, t.`subject`, t.`uid` as threaduid, t.`username` as threadusername, t.`lastpost`, t.`lastposter`, t.`lastposteruid`, t.`views`, t.`replies`
- FROM '.TABLE_PREFIX.'posts p
- INNER JOIN '.TABLE_PREFIX.'threads t ON t.`tid` = p.`tid`
- WHERE p.`dateline` >= '.(TIME_NOW - $timespan).'
- ORDER BY p.`dateline` '.$post_sort_order.'
- ');
- while ($post = $this->db->fetch_array($query))
- {
- /**
- * The return array we are building is being filled with the thread itself, but also with the posts
- * We will later increase the Postamount, so we can sort it
- */
- if (!isset($threads[$post['tid']]))
- {
- $threads[$post['tid']] = array(
- 'tid' => $post['tid'],
- 'fid' => $post['fid'],
- 'subject' => $post['subject'],
- 'uid' => $post['threaduid'],
- 'username' => $post['threadusername'],
- 'lastpost' => $post['lastpost'],
- 'lastposter' => $post['lastposter'],
- 'lastposteruid' => $post['lastposteruid'],
- 'views' => $post['views'],
- 'replies' => $post['replies'],
- 'postamount' => 1,
- 'posts' => array()
- );
-
- // The first run of one thread also brings a post, so we assign this post
- $threads[$post['tid']]['posts'][] = array(
- 'pid' => $post['pid'],
- 'message' => $post['message'],
- 'uid' => $post['postuid'],
- 'username' => $post['postusername'],
- 'dateline' => $post['dateline']
- );
- }
- else
- {
- // The thread array key exists already, so we increment the postamount and save another post
- $threads[$post['tid']]['postamount']++;
- $threads[$post['tid']]['posts'][] = array(
- 'pid' => $post['pid'],
- 'message' => $post['message'],
- 'uid' => $post['postuid'],
- 'username' => $post['postusername'],
- 'dateline' => $post['dateline']
- );
- }
- }
-
- // Sort function for ascending posts
- function arraySortByPostamountASC($item1, $item2)
- {
- if ($item1['postamount'] == $item2['postamount'])
- {
- return 0;
- }
-
- if ($item1['postamount'] > $item2['postamount'])
- {
- return 1;
- }
- else
- {
- return -1;
- }
- }
-
- // Sort function for descending posts
- function arraySortByPostamountDESC($item1, $item2)
- {
- if ($item1['postamount'] == $item2['postamount'])
- {
- return 0;
- }
-
- if ($item1['postamount'] > $item2['postamount'])
- {
- return -1;
- }
- else
- {
- return 1;
- }
- }
-
- // Let's sort the threads now
- usort($threads, 'arraySortByPostamount'.$postamount_sort_order);
-
- return $threads;
- }
-
- /**
- * Returns data of a specified forum
- * Refers to: inc/functions.php
- *
- * @param integer $forum_id ID of forum to fetch data from
- * @param integer $active_override If set to 1, will override the active forum status
- * @return array|boolean If unsuccessful, it returns false - Otherwise the Database row
- */
- function getForum($forum_id, $active_override = 0)
- {
- $forum = get_forum($forum_id, $active_override);
-
- // Do we have permission?
- $forumpermissions = forum_permissions($forum['fid']);
- if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
- {
- // error_no_permission();
- return false;
- }
- else
- {
- return $forum;
- }
- }
-
- /**
- * Return members of the board with administrative function
- * Taken from /showteam.php
- *
- * @return array
- */
- function getForumStaff()
- {
- $this->lang->load('showteam');
-
- $usergroups = array();
- $moderators = array();
- $users = array();
- // Fetch the list of groups which are to be shown on the page
- $query = $this->db->simple_select("usergroups", "gid, title, usertitle", "showforumteam=1", array('order_by' => 'disporder'));
-
- while($usergroup = $this->db->fetch_array($query))
- {
- $usergroups[$usergroup['gid']] = $usergroup;
- }
-
- if (empty($usergroups))
- {
- return $this->lang->error_noteamstoshow;
- }
-
- // Fetch specific forum moderator details
- if ($usergroups[6]['gid'])
- {
- $query = $this->db->query("
- SELECT m.*, f.name
- FROM ".TABLE_PREFIX."moderators m
- LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=m.uid)
- LEFT JOIN ".TABLE_PREFIX."forums f ON (f.fid=m.fid)
- WHERE f.active = 1
- ORDER BY u.username
- ");
-
- while($moderator = $this->db->fetch_array($query))
- {
- $moderators[$moderator['uid']][] = $moderator;
- }
- }
-
- // Now query the users of those specific groups
- $groups_in = implode(",", array_keys($usergroups));
- $users_in = implode(",", array_keys($moderators));
- if (!$groups_in)
- {
- $groups_in = 0;
- }
- if (!$users_in)
- {
- $users_in = 0;
- }
-
- $forum_permissions = forum_permissions();
-
- $query = $this->db->simple_select("users", "uid, username, displaygroup, usergroup, ignorelist, hideemail, receivepms", "displaygroup IN ($groups_in) OR (displaygroup='0' AND usergroup IN ($groups_in)) OR uid IN ($users_in)", array('order_by' => 'username'));
-
- while ($user = $this->db->fetch_array($query))
- {
- // If this user is a moderator
- if (isset($moderators[$user['uid']]))
- {
- foreach ($moderators[$user['uid']] as $forum)
- {
- if ($forum_permissions[$forum['fid']]['canview'] == 1)
- {
- $forum_url = get_forum_link($forum['fid']);
- }
- }
- $usergroups[6]['user_list'][$user['uid']] = $user;
- }
-
- if ($user['displaygroup'] == '6' || $user['usergroup'] == '6')
- {
- $usergroups[6]['user_list'][$user['uid']] = $user;
- }
-
- // Are they also in another group which is being shown on the list?
- if ($user['displaygroup'] != 0)
- {
- $group = $user['displaygroup'];
- }
- else
- {
- $group = $user['usergroup'];
- }
-
- if ($usergroups[$group] && $group != 6)
- {
- $usergroups[$group]['user_list'][$user['uid']] = $user;
- }
- }
-
- return $usergroups;
- }
-
- /**
- * Return the latest threads of one forum, where a post has been posted
- *
- * @param integer $forum_id Forum ID to fetch threads from
- * @param integer $limit Amount of threads to get
- * @param boolean $excluse_invisible Shall we also get invisible threads?
- * @return array
- */
- function getLatestActiveThreads($forum_id = 0, $limit = 7, $exclude_invisible = true)
- {
- if ($forum_id == 0)
- {
- $this->_errorAndDie('Specified forum ID cannot be 0!');
- }
- else
- {
- // Do we have permission?
- $forumpermissions = forum_permissions($forum_id);
- if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
- {
- // error_no_permission();
- return false;
- }
- }
-
- // This will be the array, where we can save the threads
- $threads = array();
-
- // We want to get a list of threads, starting with the newest one
- $query_params = array(
- 'order_by' => 'lastpost',
- 'order_dir' => 'DESC',
- 'limit' => intval($limit)
- );
-
- /**
- * If defined forum id is 0, we do not fetch threads from only one forum,
- * but we fetch the latest threads of all forums
- * Therefore we add the forum_id in the where condition
- * We only fetch visible threads, if there is anything we want to hide ;)
- * However we can also define that we want the invisible threads as well
- */
- $fetch_invisible_threads = ($exclude_invisible == true) ? '1' : '0';
- $condition = ($forum_id != 0) ? ' `visible` = '.$fetch_invisible_threads.' AND `fid` = '.intval($forum_id) : '';
-
- // Run the Query
- $query = $this->db->simple_select('threads', '*', $condition, $query_params);
-
- // Now let's iterate through the fetched threads to create the return array
- while ($thread = $this->db->fetch_array($query))
- {
- $threads[] = $thread;
- }
-
- return $threads;
- }
-
- /**
- * Return newly created threads, regardless of replies
- *
- * @param integer|array $forum_id Forum ID / Forum IDs to fetch threads from
- * @param string $fields Name of fields if you want to fetch specific fields
- * @param integer $limit Amount of threads to get
- * @param boolean $excluse_invisible Shall we also get invisible threads?
- * @param boolean $join_forums Shall we also get the information from the forums where the threads are located in?
- * @param boolean $join_first_post Shall we get the first post of this thread as well?
- * @return array
- */
- function getLatestThreads($forum_id = 0, $fields = '*', $limit = 7, $exclude_invisible = true, $join_forums = true, $join_first_post = true)
- {
- if ($forum_id != 0)
- {
- // If we have multiple values, we have to check permission for each forum!
- if (is_array($forum_id))
- {
- foreach ($forum_id as $single_forum_id)
- {
- $forum_permissions = forum_permissions($single_forum_id);
- if ($forum_permissions['canview'] != 1 || $forum_permissions['canviewthreads'] != 1)
- {
- // error_no_permission();
- return false;
- }
- }
- }
- else
- {
- // Do we have permission?
- $forumpermissions = forum_permissions($forum_id);
- if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
- {
- // error_no_permission();
- return false;
- }
- }
- }
-
- // This is what we will be returning
- $threads = array();
-
- // Do we want to get invisible threads as well?
- $fetch_invisible_threads = ($exclude_invisible == true) ? '1' : '0';
- $condition = 't.`visible` = '.$fetch_invisible_threads;
-
- // Are we fetching threads from multiple forums?
- if (is_array($forum_id) || is_object($forum_id))
- {
- $condition .= ' AND t.`fid` IN ('.implode(', ', $forum_id).')';
-
- }
- // Or are we just fetching threads from one forum?
- else
- {
- $condition .= ($forum_id == 0) ? '' : ' AND t.`fid` = '.$forum_id;
- }
-
- // Do we want to get information of the forum where the thread is located in?
- $forum_join = ($join_forums == true) ? 'INNER JOIN '.TABLE_PREFIX.'forums f ON f.`fid` = t.`fid`' : '';
-
- // Do we want to get the first post from the thread?
- $first_post_join = ($join_first_post == true) ? 'INNER JOIN '.TABLE_PREFIX.'posts p ON p.`pid` = t.`firstpost`' : '';
-
- // Run the Query
- $query = $this->db->query('
- SELECT '.$fields.'
- FROM '.TABLE_PREFIX.'threads t
- '.$forum_join.'
- '.$first_post_join.'
- WHERE '.$condition.'
- ORDER BY t.`dateline` DESC
- LIMIT '.intval($limit).'
- ');
-
- // Iterate through the results and assign it to our returning array
- while ($thread = $this->db->fetch_array($query))
- {
- $threads[] = $thread;
- }
-
- return $threads;
- }
-
- /**
- * Return recently posted posts
- *
- * @param integer|array Either a single Thread ID or an array containing thread IDs
- * @param string Fields, which shall be fetched from the posts table
- * @param integer How many posts shall be fetched?
- * @param boolean Shall we also return invisible ones?
- * @return array
- */
- function getLatestPosts($thread_id = 0, $fields = '*', $limit = 7, $exclude_invisible = true)
- {
- // Posts will be stored in this array
- $posts = array();
-
- // Posts will be returned in descending order, starting with the newest
- $query_params = array(
- 'order_by' => 'dateline',
- 'order_dir' => 'DESC',
- 'limit' => intval($limit)
- );
-
- // We want to fetch posts from multiple threads
- if (is_array($thread_id) || is_object($thread_id))
- {
- // Multiple threads = IN (...) Operator
- $condition = '`fid` IN ('.implode(', ', $thread_id).')';
- }
- else
- {
- // Single thread = normal WHERE X = Y - if set 0 we fetch posts from all threads
- $condition = ($thread_id == 0) ? '1 = 1' : '`fid` = '.intval($thread_id);
- }
-
- /**
- * If defined forum id is 0, we do not fetch threads from only one forum,
- * but we fetch the latest threads of all forums
- * Therefore we add the forum_id in the where condition
- * We only fetch visible threads, if there is anything we want to hide ;)
- * However we can also define that we want the invisible threads as well
- */
- $fetch_invisible_threads = ($exclude_invisible == true) ? '1' : '0';
- $condition .= ' AND `visible` = '.$fetch_invisible_threads;
-
- // Run the Query
- $query = $this->db->simple_select('posts', $fields, $condition, $query_params);
-
- // Now let's iterate through the fetched posts to create the return array
- while ($post = $this->db->fetch_array($query))
- {
- $posts[] = $post;
- }
-
- return $posts;
- }
-
- /**
- * Retrieve member list
- * Ideal to offer a multi-page member list
- *
- * @param array $data Contains data affecting the member query - List of Array keys below
- * - orderby: What table column will the member list be sorted by?
- * - orderdir: Ascending or Descending order direction
- * - perpage: Amount of members to fetch (set 0 for all members)
- * - letter: Beginning character of member name
- * - username: Searching for a matching username
- * - username_match: Set this to "begins" when username shall being with given token - otherwise it goes or "contains"
- * - website: String contained in website
- * - aim: Search for an AIM
- * - icq: Search for an ICQ number
- * - msn: Search for a MSN ID
- * - yahoo: Search for a Yahoo ID
- * - page: Which page of the list will we be retrieving
- * @return array
- */
- function getMembers($data = array())
- {
- /**
- * Make sure we have initial values in the data array
- */
-
- $data['orderby'] = (!isset($data['orderby'])) ? 'u.`username`' : $data['orderby'];
- $data['orderdir'] = (!isset($data['orderdir'])) ? 'ASC' : strtoupper($data['orderdir']);
- $data['orderdir'] = ($data['orderdir'] == 'ASC') ? 'ASC' : 'DESC';
- $data['perpage'] = (!isset($data['perpage'])) ? (int) $this->mybb->settings['membersperpage'] : (int) $data['perpage'];
- $data['letter'] = (!isset($data['letter'])) ? '' : $data['letter'];
- $data['username'] = (!isset($data['username'])) ? '' : $data['username'];
- $data['username_match'] = (!isset($data['username_match'])) ? 'begins' : $data['username_match'];
- $data['website'] = (!isset($data['website'])) ? '' : $data['website'];
- $data['aim'] = (!isset($data['aim'])) ? '' : $data['aim'];
- $data['icq'] = (!isset($data['icq'])) ? '' : $data['icq'];
- $data['msn'] = (!isset($data['msn'])) ? '' : $data['msn'];
- $data['yahoo'] = (!isset($data['yahoo'])) ? '' : $data['yahoo'];
- $data['page'] = (!isset($data['page'])) ? 1 : (int) $data['page'];
-
- /**
- * Let's build the DB query now!
- */
-
- $sql_where = 'WHERE 1 = 1';
-
- // Username begins with a letter or number
- if (strlen($data['letter']) == 1)
- {
- $data['letter'] = chr(ord($data['letter']));
- // Letter is 0: Shall start with number
- if ($data['letter'] == '0')
- {
- $sql_where .= " AND u.`username` NOT REGEXP('[a-zA-Z]')";
- }
- // letter is not 0, so it will be fetching names according to first char
- else
- {
- $sql_where .= " AND u.`username` LIKE '".$this->db->escape_string($data['letter'])."%'";
- }
- }
-
- // Search for matching username
- if (strlen($data['username']) > 0)
- {
- $data['username'] = htmlspecialchars_uni($data['username']);
- if ($data['username_match'] == 'begins')
- {
- $sql_where .= " AND u.`username` LIKE '".$this->db->escape_string_like($data['username'])."%'";
- }
- else
- {
- $sql_where .= " AND u.`username` LIKE '%".$this->db->escape_string_like($data['username'])."%'";
- }
- }
-
- // Search for website
- if (strlen($data['website']) > 0)
- {
- $data['website'] = trim(htmlspecialchars_uni($data['website']));
- $sql_where .= " AND u.`website` LIKE '%".$this->db->escape_string_like($data['website'])."%'";
- }
-
- // Search for AIM
- if (strlen($data['aim']) > 0)
- {
- $sql_where .= " AND u.`aim` LIKE '%".$this->db->escape_string_like($data['aim'])."%'";
- }
-
- // Search for ICQ
- if (strlen($data['icq']) > 0)
- {
- $sql_where .= " AND u.`icq` LIKE '%".$this->db->escape_string_like($data['icq'])."%'";
- }
-
- // Search for MSN
- if (strlen($data['msn']) > 0)
- {
- $sql_where .= " AND u.`msn` LIKE '%".$this->db->escape_string_like($data['msn'])."%'";
- }
-
- // Search for Yahoo
- if (strlen($data['yahoo']) > 0)
- {
- $sql_where .= " AND u.`yahoo` LIKE '%".$this->db->escape_string_like($data['yahoo'])."%'";
- }
-
- // Build the LIMIT-part of the query here
- if ($data['perpage'] == 0)
- {
- $limit_string = '';
- }
- else
- {
- if ($data['page'] > 0)
- {
- $limit_string = 'LIMIT '.(($data['page'] - 1) * $data['perpage']).', '.$data['perpage'];
- }
- else
- {
- $limit_string = 'LIMIT '.$data['perpage'];
- }
- }
-
- $sql .= '
- SELECT u.*, f.*
- FROM '.TABLE_PREFIX.'users u
- LEFT JOIN '.TABLE_PREFIX.'userfields f ON f.`ufid` = u.`uid`
- '.$sql_where.'
- ORDER BY '.$data['orderby'].' '.$data['orderdir'].'
- '.$limit_string.'
- ';
-
- $query = $this->db->query($sql);
-
- $arr = array();
-
- while ($member = $this->db->fetch_array($query))
- {
- $arr[] = $member;
- }
-
- return $arr;
- }
-
- /**
- * Read some info about a poll
- *
- * @param integer $poll_id ID of Poll to fetch infos from
- * @return array
- */
- function getPoll($poll_id)
- {
- if ($poll_id == 0)
- {
- $this->_errorAndDie('Specified poll ID cannot be 0!');
- }
-
- $query = $this->db->query('
- SELECT *
- FROM '.TABLE_PREFIX.'polls
- WHERE `pid` = '.(int) $poll_id.'
- LIMIT 1
- ');
-
- $poll = $this->db->fetch_array($query);
-
- $separator = '||~|~||';
-
- $poll['optionsarray'] = explode($separator, $poll['options']);
- $poll['votesarray'] = explode($separator, $poll['votes']);
-
- /**
- * At this point we are doing another query, so it is easier
- * Little Todo: Include an INNER JOIN in the initial Poll-fetching query to save one query
- * YOu have to make sure that columns of "thread" won't override columns of "poll"
- * Therefore the solution right now at hand will be sufficient, until people start to moan :)
- */
- $poll['thread'] = $this->getThread($poll['tid']);
-
- $poll['whovoted'] = $this->getWhoVoted($poll_id);
-
- return $poll;
- }
-
- /**
- * Returns post data of specified post
- * Refers to: inc/functions.php & inc/class_parser.php
- *
- * @param integer $post_id Post ID to fetch data from
- * @param boolean $parsed Shall the Post message be parsed?
- * @param array $parse_options Array of yes/no options - allow_html,filter_badwords,allow_mycode,allow_smilies,nl2br,me_username
- * @param array $override_forum_parse_options Whether parse options should be defined by forum or by the script.
- If they are being overridden, the array will contain the options
- * @return array|boolean: If unsuccessful, it returns false - Otherwise the Database row
- */
- function getPost($post_id, $parsed = false, $override_forum_parse_options = array())
- {
- if ($post_id == 0)
- {
- $this->_errorAndDie('Specified post ID cannot be 0!');
- }
-
- // Get the Post data
- $post = get_post($post_id);
-
- // Post not found? --> False
- if (empty($post))
- {
- return false;
- }
-
- // Do we have permission?
- $forumpermissions = forum_permissions($post['fid']);
- if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
- {
- // error_no_permission();
- return false;
- }
-
- // If the post shall not be parsed, we can already return it at this point
- if ($parsed == false || empty($post))
- {
- return $post;
- }
-
- // So we want to parse the message
-
- /**
- * We don't want to override the parse options defined by the forum,
- * so we have first to get these options defined for the forum
- */
- if (count($override_forum_parse_options) == 0)
- {
- // Get the Forum data according to the forum id stored with the post
- $forum = $this->getForum($post['fid']);
-
- // Set up the parser options.
- $parser_options = array(
- "allow_html" => $forum['allowhtml'],
- "allow_mycode" => $forum['allowmycode'],
- "allow_smilies" => $forum['allowsmilies'],
- "allow_imgcode" => $forum['allowimgcode'],
- "filter_badwords" => 1
- );
-
- }
- else
- {
- // Self-defined options given in the function parameter
- $parser_options = array(
- 'allow_html' => (isset($override_forum_parse_options['allow_html']) && $override_forum_parse_options['allow_html'] == 1) ? 1 : 0,
- 'allow_mycode' => (isset($override_forum_parse_options['allow_mycode']) && $override_forum_parse_options['allow_mycode'] == 1) ? 1 : 0,
- 'allow_smilies' => (isset($override_forum_parse_options['allow_smilies']) && $override_forum_parse_options['allow_smilies'] == 1) ? 1 : 0,
- 'allow_imgcode' => (isset($override_forum_parse_options['allow_imgcode']) && $override_forum_parse_options['allow_imgcode'] == 1) ? 1 : 0,
- 'filter_badwords' => (isset($override_forum_parse_options['filter_badwords']) && $override_forum_parse_options['filter_badwords'] == 1) ? 1 : 0,
- );
- }
-
- // Overwrite the message with the parsed message
- $post['message'] = $this->parser->parse_message($post['message'], $parser_options);
-
- return $post;
- }
-
- /**
- * Get posts which match the given criteria
- *
- * @param array $params Parameters for the query
- * @return array
- */
- function getPosts($params = array('fields' => '*', 'order_by' => 'dateline', 'order_dir' => 'DESC', 'limit_start' => 0, 'limit' => 0, 'where' => ''))
- {
- // We will store the posts in here
- $posts = array();
-
- // No matter what parameters will be given, the query starts with the following
- $sql = 'SELECT '.$params['fields'].'
- FROM '.TABLE_PREFIX.'posts';
-
- // Get all posts or just (hopefully) posts which match certain criteria?
- $sql .= ($params['where'] != '') ? ' WHERE '.$params['where'] : '';
-
- // Are the posts going to be ordered by a field?
- if ($params['order_by'] != '')
- {
- $sql .= ' ORDER BY '.$params['order_by'];
- if ($params['order_dir'] != '')
- {
- $sql .= ' '.$params['order_dir'];
- }
- else
- {
- $sql .= ' ASC';
- }
- }
-
- // Get all posts or (hopefully) just a few?
- if ($params['limit'] != 0)
- {
- $sql .= ' LIMIT ';
- if (isset($params['limit_start']))
- {
- $sql .= $params['limit_start'].', '.$params['limit'];
- }
- else
- {
- $sql .= $params['limit'];
- }
- }
-
- // Run the query
- $query = $this->db->query($sql);
-
- // Store the returned data in the array we return
- while ($post = $this->db->fetch_array($query))
- {
- $posts[] = $post;
- }
-
- return $posts;
- }
-
- /**
- * Get the Posts of a particular thread
- *
- * @param integer $thread_id
- * @param string $fields If you want to fetch certain fields, define them as a string here (separated by comma)
- * @param array $options Options for the query [ array('limit_start', 'limit', 'orderby', 'order_dir') ]
- * @return array
- */
- function getPostsOfThread($thread_id, $fields = '*', $options = array())
- {
- // This is what we will be returning
- $arr = array();
-
- $query_thread = $this->db->query('SELECT `fid` FROM '.TABLE_PREFIX.'threads WHERE `tid` = '.intval($thread_id).' LIMIT 1');
- $thread_forumid = $this->db->fetch_field($query_thread, 'fid');
-
- // Do we have permission?
- $forumpermissions = forum_permissions($thread_forumid);
- if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
- {
- // error_no_permission();
- return false;
- }
-
- // Let's request the posts from the database
- $query = $this->db->simple_select('posts', $fields, '`tid` = '.intval($thread_id), $options);
-
- // All we need to do now is to assign them to our returning array
- while ($post = $this->db->fetch_array($query))
- {
- $arr[] = $post;
- }
-
- return $arr;
- }
-
- /**
- * Read the messages from database of a user
- *
- * @param integer $user_id ID of user
- * @param array $params Array with options for SQL Query (orderby, sort)
- * @param boolean $translate_folders If the folders should be turned into readable format ŕ la "inbox"
- * @return array
- */
- function getPrivateMessagesOfUser($user_id, $params = array('orderby' => 'pm.dateline', 'sort' => 'DESC'), $translate_folders = true)
- {
- /**
- * This is what we will be returning
- * Structure of the array to return:
- * array(
- * 'Inbox' => array( ... Messages ... )
- * )
- *
- * 'Inbox' is the translated folder of folder #1
- */
- $arr = array();
-
- // If we want to translate the folder names, we need to include the file which contains the translation function
- if ($translate_folders == true)
- {
- include_once MYBB_ROOT.'inc/functions_user.php';
- }
-
- // Run the Query for Private Messages
- $query = $this->db->query('
- SELECT pm.*, fu.username AS fromusername, tu.username as tousername
- FROM '.TABLE_PREFIX.'privatemessages pm
- LEFT JOIN '.TABLE_PREFIX.'users fu ON (fu.uid=pm.fromid)
- LEFT JOIN '.TABLE_PREFIX.'users tu ON (tu.uid=pm.toid)
- WHERE pm.uid = '.intval($user_id).'
- ORDER BY '.$params['orderby'].' '.$params['sort'].'
- ');
-
- // Do we have messages?
- if ($this->db->num_rows($query) > 0)
- {
- // Uhh, let's iterate the messages!
- while ($message = $this->db->fetch_array($query))
- {
- // If we translate the folder names, our array index will be the translated folder name
- if ($translate_folders == true)
- {
- $arr[get_pm_folder_name($message['folder'])][] = $message;
- }
- // If we don't want translated folder names, our array index will be the folder number
- else
- {
- $arr[$message['folder']][] = $message;
- }
- }
- }
-
- return $arr;
- }
-
- /**
- * Returns data of a specified thread
- * Refers to: inc/functions.php
- *
- * @param integer $thread_id ID of the thread to fetch data from
- * @return array|boolean If unsuccessful, it returns false - Otherwise the Database row
- */
- function getThread($thread_id)
- {
- $thread = get_thread($thread_id);
-
- // Do we have permission?
- $forumpermissions = forum_permissions($thread['fid']);
- if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
- {
- // error_no_permission();
- return false;
- }
- else
- {
- return $thread;
- }
- }
-
- /**
- * Get Threads of one or more forums
- *
- * @param integer $forum_id IDs of Forums to fetch threads from
- * @param string $fields If you want to fetch certain fields, define a string with them
- * @param string $where Additional WHERE constellation if needed
- * @pararm array $query_params Parameters for the Query to run in the database
- (order_by, order_dir, limit_start, limit [limit will only be acknowledged if both limit vars are defined])
- * @param boolean $excluse_invisible Shall we get invisible threads too?
- * @param boolean $join_forums Do we also want to get the forum information of where the threads are located?
- * @param boolean $join_first_post Shall we get the first post of the thread? (= initial post)
- * @return array
- */
- function getThreads($forum_id, $fields = '*', $where = '', $query_params = array('order_by' => 't.`subject`', 'order_dir' => 'ASC'), $exclude_invisible = true, $join_forums = false, $join_first_post = false)
- {
- // Do we have permission?
- if (!is_array($forum_id))
- {
- $forumpermissions = forum_permissions($forum_id);
- if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
- {
- // error_no_permission();
- return false;
- }
- }
- else
- {
- // Check for every single forum
- foreach ($forum_id as $forum_id_single)
- {
- $forumpermissions = forum_permissions($forum_id_single);
- if ($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
- {
- // error_no_perm…
Large files files are truncated, but you can click here to view the full file