Example #1
0
    $posts = App::getActivities($prms);
    echo json_encode(Utility::formatActivitiesToPosts($posts, $app));
});
$app->post('/users/:id/posts', function ($id) use($app) {
    $o = $app->request->getBody();
    $o = json_decode($o);
    $u = new User($app->environment()['testify.user_id']);
    if ($u->getID() != $id) {
        $app->response->status(403);
        echo json_encode(["status" => false, "description" => "Wrong account"]);
        return;
    }
    if (!isset($o->post)) {
        $o->post = " ";
    }
    $id = $u->createPost(["a" => $o->anonymous, "p" => $o->post, "i" => $o->images]);
    if (isset($o->category)) {
        $p = new Post($id);
        $p->setCategory($o->category);
    }
    if ($id) {
        $p = new Post($id);
        $app->response->status(201);
        if ($u = $p->getAuthor()) {
            $user = ["user_id" => $u->getID(), "avatar" => $u->getProfilePictureURL(), "name" => $u->getFullname()];
        } else {
            $user = ["user_id" => null, "avatar" => "img/favicon.png", "name" => "Anonymous"];
        }
        $ijson = [];
        if ($imgs = $p->getImages()) {
            foreach ($imgs as $i) {
    foreach ($friends as $friend) {
        build_friend_card($html, $friend);
    }
    $html .= '</div>';
    return $html;
}
$user = new User($_SESSION['username']);
$op = $_GET['op'];
if ($op == "create post") {
    // creates a post
    // needs post title and text
    $post;
    if (isset($_GET['file'])) {
        $post = $user->createPost_image($_GET['title'], $_GET['text'], $_GET['file']);
    } else {
        $post = $user->createPost($_GET['title'], $_GET['text']);
    }
    $html = '';
    build_post($html, $post, $user->get_username());
    $json = array('html' => $html, 'expanderid' => 'expander' . $post->get_postId(), 'commentexpanderid' => 'commentexpander' . $post->get_postId(), 'imageexpander' => 'imageexpander' . $post->get_postId(), 'replyid' => 'reply' . $post->get_postId());
    echo json_encode($json);
} else {
    if ($op == "get user images") {
        // gets all images from users posts
        $posts = $user->get_allPosts();
        $html = '';
        foreach ($posts as $post) {
            build_image_post($html, $post->get_postPath(), $post->get_title());
        }
        $json = array('html' => $html);
        echo json_encode($json);
Example #3
0
/**
 * User Handler
 * handles the User data
 */
require_once "../../config/db.php";
require_once "User.php";
if (isset($_POST["getUser"])) {
    $user = new User();
    $result = $user->getUser();
    echo $result;
}
if (isset($_POST["getFeed"])) {
    $user = new User();
    $result = $user->getFeed();
    echo $result;
}
if (isset($_POST["createPost"])) {
    $user = new User();
    $result = $user->createPost();
    echo $result;
}
if (isset($_POST["deletePost"])) {
    $user = new User();
    $result = $user->deletePost();
    echo $result;
}
if (isset($_POST["userName"]) || isset($_POST["email"]) || isset($_POST["firstName"]) || isset($_POST["lastName"])) {
    $user = new User();
    $result = $user->editProfile();
    echo $result;
}