Advertisement
Corey

Untitled

Mar 31st, 2011
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.79 KB | None | 0 0
  1. <?php
  2. class Main
  3. {
  4.     public $db;
  5.     public $config;
  6.     public $Errors;
  7.     public $User;
  8.     public function __construct($config)
  9.     {
  10.         $this->config = $config;
  11.         $this->db = new DB(&$this);
  12.         $this->Errors = new Errors($this);
  13.         $this->User = new User_Integration(&$this);
  14.     }
  15.     function die_on_error($error)
  16.     {
  17.         global $Smarty;
  18.         $Smarty->assign('error', $error);
  19.         $Smarty->display('error.tpl');
  20.         die;
  21.     }
  22.     function Get_Pages($num_results, $per_page)
  23.     {
  24.         $total_pages = ceil($num_results / $per_page);
  25.         if (!($total_pages > 0))
  26.         {
  27.             $total_pages = 1;
  28.         }
  29.         for ($i = 0; $i < $total_pages; $i++)
  30.         {
  31.             $pages[] = $i + 1;
  32.         }
  33.         return $pages;
  34.     }
  35.     function Thread_Count($where)
  36.     {
  37.         if (!is_numeric($where))
  38.         {
  39.             $get_threads = $this->db->Execute("SELECT `id` FROM `" . $this->config['database']['tables']['posts'] . "` WHERE `where`LIKE '%" . $where . "%'");
  40.         }
  41.         return $get_threads->RecordCount();
  42.     }
  43.     function Load_Board($info)
  44.     {
  45.         $query = "SELECT * FROM `" . $this->config['database']['tables']['boards'] . "`";
  46.         if (isset($info['where']))
  47.         {
  48.             $query .= " WHERE `where` LIKE '%" . $info['where'] . "%'";
  49.         }
  50.         elseif (isset($info['id']))
  51.         {
  52.             $query .= " WHERE `id`='" . $info['id'] . "'";         
  53.         }
  54.         elseif (isset($info['parent_id']))
  55.         {
  56.             $query .= " WHERE `parent_id`='" . $info['parent_id'] . "'";
  57.         }
  58.         else
  59.         {
  60.             $query .= " LIMIT 1";
  61.         }
  62.         $get_board = $this->db->Execute($query);
  63.         while ($board = $get_board->FetchRow())
  64.         {
  65.             $board['thread_count'] = $this->Thread_Count('board:' . $board['id'] . '/;');
  66.             if (is_numeric($info['thread_info']['limit']))
  67.             {
  68.                 $board['threads'] = $this->Load_Threads(
  69.                     array(
  70.                         'where' => 'board:' . $board['id'] . '/;',
  71.                         'limit' => $info['thread_info']['limit'],
  72.                         'start' => $info['thread_info']['start']
  73.                     )
  74.                 );
  75.             }
  76.             $board['children'] = $this->Load_Board(array('parent_id' => $board['id'], 'thread_info' => $info['thread_info']));
  77.             $return[] = $board;
  78.         }
  79.         if (is_array($return))
  80.         {
  81.             return $return;
  82.         }
  83.     }
  84.     function Load_Threads($info)
  85.     {
  86.         if (!isset($info['limit']) || !is_numeric($info['limit']))
  87.         {
  88.             $info['limit'] = 1;
  89.         }
  90.         if (!isset($info['order']))
  91.         {
  92.             $info['order'] = 'DESC';
  93.         }
  94.  
  95.         $order = "ORDER BY `id` " . $info['order'];
  96.  
  97.         $query = "SELECT * FROM `" . $this->config['database']['tables']['posts'] . "`";
  98.         if (isset($info['where']))
  99.         {
  100.             $query .= " WHERE `where` LIKE '%" . $info['where'] . "%'";
  101.         }
  102.         elseif (isset($info['id']))
  103.         {
  104.             $query .= " WHERE `id`='" . $info['id'] . "'";         
  105.         }
  106.         if (!is_numeric($info['start']))
  107.         {
  108.             $start = 0;
  109.         }
  110.         else
  111.         {
  112.             $start = ($info['start'] - 1) * $info['limit'];
  113.         }
  114.         $query .= $order . " LIMIT " . $start . ", " . $info['limit'];
  115.         $get_threads = $this->db->Execute($query);
  116.         while ($thread = $get_threads->FetchRow())
  117.         {
  118.             $thread['post_count'] = $this->Thread_Count('thread:' . $thread['id'] . '/;');
  119.             $thread['author'] = $this->strtoarray($thread['user_info']);
  120.             $thread['message'] = urldecode($thread['message']);
  121.             $thread['message'] = htmlspecialchars($thread['message']);
  122.             $thread['message'] = nl2br($thread['message']);
  123.             $thread['posts'] = $this->Load_Threads(array('where' => 'thread:' . $thread['id'] . '/', 'limit' => 1, 'order'=>'DESC'));
  124.             $return[] = $thread;
  125.         }
  126.         if (is_array($return))
  127.         {
  128.             return $return;
  129.         }
  130.     }
  131.     function strtoarray($str)
  132.     {
  133.         $info = explode("&", $str);
  134.         if (is_array($info))
  135.         {
  136.             foreach ($info as $data)
  137.             {
  138.                 $data = explode("=", $data);
  139.                 if (is_array($data))
  140.                 {
  141.                     $array[$data[0]] = urldecode($data[1]);
  142.                 }
  143.             }
  144.         }
  145.         return $array;
  146.     }
  147.     function arraytostr($array)
  148.     {
  149.         foreach ($array as $key => $value)
  150.         {
  151.             $str .= $key . "=" . urlencode($value) . "&";
  152.         }
  153.         return $str;
  154.     }  
  155. }
  156. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement