Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Main
- {
- public $db;
- public $config;
- public $Errors;
- public $User;
- public function __construct($config)
- {
- $this->config = $config;
- $this->db = new DB(&$this);
- $this->Errors = new Errors($this);
- $this->User = new User_Integration(&$this);
- }
- function die_on_error($error)
- {
- global $Smarty;
- $Smarty->assign('error', $error);
- $Smarty->display('error.tpl');
- die;
- }
- function Get_Pages($num_results, $per_page)
- {
- $total_pages = ceil($num_results / $per_page);
- if (!($total_pages > 0))
- {
- $total_pages = 1;
- }
- for ($i = 0; $i < $total_pages; $i++)
- {
- $pages[] = $i + 1;
- }
- return $pages;
- }
- function Thread_Count($where)
- {
- if (!is_numeric($where))
- {
- $get_threads = $this->db->Execute("SELECT `id` FROM `" . $this->config['database']['tables']['posts'] . "` WHERE `where`LIKE '%" . $where . "%'");
- }
- return $get_threads->RecordCount();
- }
- function Load_Board($info)
- {
- $query = "SELECT * FROM `" . $this->config['database']['tables']['boards'] . "`";
- if (isset($info['where']))
- {
- $query .= " WHERE `where` LIKE '%" . $info['where'] . "%'";
- }
- elseif (isset($info['id']))
- {
- $query .= " WHERE `id`='" . $info['id'] . "'";
- }
- elseif (isset($info['parent_id']))
- {
- $query .= " WHERE `parent_id`='" . $info['parent_id'] . "'";
- }
- else
- {
- $query .= " LIMIT 1";
- }
- $get_board = $this->db->Execute($query);
- while ($board = $get_board->FetchRow())
- {
- $board['thread_count'] = $this->Thread_Count('board:' . $board['id'] . '/;');
- if (is_numeric($info['thread_info']['limit']))
- {
- $board['threads'] = $this->Load_Threads(
- array(
- 'where' => 'board:' . $board['id'] . '/;',
- 'limit' => $info['thread_info']['limit'],
- 'start' => $info['thread_info']['start']
- )
- );
- }
- $board['children'] = $this->Load_Board(array('parent_id' => $board['id'], 'thread_info' => $info['thread_info']));
- $return[] = $board;
- }
- if (is_array($return))
- {
- return $return;
- }
- }
- function Load_Threads($info)
- {
- if (!isset($info['limit']) || !is_numeric($info['limit']))
- {
- $info['limit'] = 1;
- }
- if (!isset($info['order']))
- {
- $info['order'] = 'DESC';
- }
- $order = "ORDER BY `id` " . $info['order'];
- $query = "SELECT * FROM `" . $this->config['database']['tables']['posts'] . "`";
- if (isset($info['where']))
- {
- $query .= " WHERE `where` LIKE '%" . $info['where'] . "%'";
- }
- elseif (isset($info['id']))
- {
- $query .= " WHERE `id`='" . $info['id'] . "'";
- }
- if (!is_numeric($info['start']))
- {
- $start = 0;
- }
- else
- {
- $start = ($info['start'] - 1) * $info['limit'];
- }
- $query .= $order . " LIMIT " . $start . ", " . $info['limit'];
- $get_threads = $this->db->Execute($query);
- while ($thread = $get_threads->FetchRow())
- {
- $thread['post_count'] = $this->Thread_Count('thread:' . $thread['id'] . '/;');
- $thread['author'] = $this->strtoarray($thread['user_info']);
- $thread['message'] = urldecode($thread['message']);
- $thread['message'] = htmlspecialchars($thread['message']);
- $thread['message'] = nl2br($thread['message']);
- $thread['posts'] = $this->Load_Threads(array('where' => 'thread:' . $thread['id'] . '/', 'limit' => 1, 'order'=>'DESC'));
- $return[] = $thread;
- }
- if (is_array($return))
- {
- return $return;
- }
- }
- function strtoarray($str)
- {
- $info = explode("&", $str);
- if (is_array($info))
- {
- foreach ($info as $data)
- {
- $data = explode("=", $data);
- if (is_array($data))
- {
- $array[$data[0]] = urldecode($data[1]);
- }
- }
- }
- return $array;
- }
- function arraytostr($array)
- {
- foreach ($array as $key => $value)
- {
- $str .= $key . "=" . urlencode($value) . "&";
- }
- return $str;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement