Example #1
0
<?php

require_once 'connection.php';
require_once 'stlib.php';
if ($_GET["mode"] == "post") {
    $message = $_GET["msg"];
    $rid = $_GET["rid"];
    postToStream($rid, $message);
} else {
    if ($_GET["mode"] == "get") {
        echo getStream($_GET["object"]);
    } else {
        if ($_GET["mode"] == "gets") {
            echo getStreamByObject($_GET["object"]);
        }
    }
}
Example #2
0
<?php

// include the config file
require "../includes/config.php";
if ($_SERVER["REQUEST_METHOD"] == "GET") {
    $posts = getStream($_SESSION["id"]);
    if ($posts === false) {
        render("stream_view.php", ["title" => "stream", "id" => $_SESSION["id"]]);
    } else {
        render("stream_view.php", ["title" => "stream", "id" => $_SESSION["id"], "posts" => $posts]);
    }
} else {
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        if (empty($_POST["text"])) {
            $posts = getStream($_SESSION["id"]);
            if ($posts === false) {
                render("stream_view.php", ["title" => "stream", "id" => $_SESSION["id"], "err_str" => "You may not make a blank post"]);
            } else {
                render("stream_view.php", ["title" => "stream", "id" => $_SESSION["id"], "posts" => $posts, "err_str" => "You may not make a blank post"]);
            }
            exit;
        }
        $text = filter($_POST["text"]);
        $public = empty($_POST["public"]) ? FALSE : TRUE;
        $poster_id = $_SESSION["id"];
        query("INSERT INTO `posts` (text, public, poster_id) VALUES(?, ?, ?)", $text, $public, $poster_id);
        redirect("stream.php");
    }
}
Example #3
0
 /**
  * Constructor: __construct
  * Allow for CORS, assemble and pre-process the data
  */
 public function __construct($request)
 {
     /*    header("Access-Control-Allow-Orgin: *");
         header("Access-Control-Allow-Methods: *");*/
     header("Content-Type: application/json");
     $this->args = explode('/', rtrim($request, '/'));
     $this->endpoint = array_shift($this->args);
     if (array_key_exists(0, $this->args) && !is_numeric($this->args[0])) {
         $this->verb = array_shift($this->args);
     }
     $this->method = $_SERVER['REQUEST_METHOD'];
     if ($this->method == 'POST' && array_key_exists('HTTP_X_HTTP_METHOD', $_SERVER)) {
         if ($_SERVER['HTTP_X_HTTP_METHOD'] == 'DELETE') {
             $this->method = 'DELETE';
         } else {
             if ($_SERVER['HTTP_X_HTTP_METHOD'] == 'PUT') {
                 $this->method = 'PUT';
             } else {
                 throw new Exception("Unexpected Header");
             }
         }
     }
     switch ($this->method) {
         case 'DELETE':
         case 'POST':
             $this->request = $this->_cleanInputs($_POST);
             $this->file = getStream();
             break;
         case 'GET':
             $this->request = $this->_cleanInputs($_GET);
             break;
         case 'PUT':
             $this->request = $this->_cleanInputs($_GET);
             $this->file = getStream();
             break;
         default:
             $this->_response('Invalid Method', 405);
             break;
     }
 }