Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php session_start();
- class API
- {
- // A function to make FP API calls.
- public function call($actions = array())
- {
- if ($actions)
- {
- $firstAction = false;
- $url = "http://api.facepun.ch/?";
- $curl = curl_init();
- foreach($actions as $k => $v)
- {
- if (!$firstAction)
- {
- $url = $url."$k=$v";
- $firstAction = true;
- }
- else
- {
- $url = $url."&$k=$v";
- }
- }
- if ($actions['action'] != "authenticate" && $this->isLoggedin())
- {
- $url = $url."&username=".$_SESSION['username']."&password=".$_SESSION['password'];
- }
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- $result = curl_exec($curl);
- curl_close($curl);
- return json_decode($result);
- }
- }
- // A function to check if the user is logged in.
- public function isLoggedin()
- {
- if (isset($_SESSION['loggedin']) && isset($_SESSION['username']) && isset($_SESSION['password']) && $_SESSION['loggedin'])
- {
- return true;
- }
- }
- // A function to login the user.
- public function login($username = false, $password = false)
- {
- if ($username && $password)
- {
- $password = md5($password);
- $result = $this->call(array(
- "action" => "authenticate",
- "username" => $username,
- "password" => $password
- ));
- if ($result && $result->login == "Login OK")
- {
- // REWRITE THIS SHIT, IT'S INSECURE.
- $_SESSION['loggedin'] = true;
- $_SESSION['username'] = $username;
- $_SESSION['password'] = $password;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- // A function to get forum layout.
- public function getforums()
- {
- $result = $this->call(array("action" => "getforums"));
- return $result->categories;
- }
- // A function to get all the threads in a forum.
- public function getthreads($id = false, $page = false)
- {
- if ($id)
- {
- $params = array("action" => "getthreads", "forum_id" => $id);
- if ($page)
- {
- $params["page"] = $page;
- }
- $result = $this->call($params);
- return $result;
- }
- }
- // A function to get all the posts in a thread.
- public function getposts($id = false, $page = false)
- {
- if ($id)
- {
- $params = array("action" => "getposts", "thread_id" => $id);
- if ($page)
- {
- $params["page"] = $page;
- }
- $result = $this->call($params);
- return $result;
- }
- }
- // A function to post a reply to a thread.
- public function newreply($id = false, $message = false)
- {
- if ($id && $message)
- {
- $result = $this->call(array("action" => "new reply", "thread_id" => $id, "message" => $message));
- return true;
- }
- }
- // A function to get the popular threads.
- public function getpopularthreads()
- {
- $result = $this->call(array("action" => "getpopularthreads"));
- return $result;
- }
- // A function to get the read threads.
- public function getreadthreads()
- {
- $result = $this->call(array("action" => "getreadthreads"));
- return $result->threads;
- }
- public function getpms($page = 1)
- {
- $result = $this->call(array("action" => "getpms", "page" => $page));
- return $result;
- }
- public function getpm($id = false)
- {
- if ($id)
- {
- $result = $this->call(array("action" => "getpm", "pm_id" => $id));
- return $result;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement