Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share post api, conflicts resolved #51

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor

/Helpers/Config.php
/Helpers/ForgotPassword
60 changes: 60 additions & 0 deletions Api/share_post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
require_once('../autoloader.php');
use Helper\Database as DB;
use Helper\Jwt_client as jwt;

// connect to the databse file
$conn = DB::db_connect();

if (isset($_GET['id'])) {
$post_id = $_GET['id'];

// get all posts from the database
$getPosts = DB::getPostsToShare($conn, $post_id);

// if the query is successful display the posts and the share link
if ($getPosts) {
// posts array
$posts_arr = array();
$posts_arr['data'] = array();

while($row = mysqli_fetch_assoc($getPosts)) {
// get current url
$url = $_SERVER['REQUEST_URI'].$row['post_id'];

$post_item = array(
'status' => true,
'post_id' => $row['post_id'],
'post_title' => $row['post_topic'],
'post_body' => html_entity_decode($row['post']),
'post_author' => $row['name'],
'post_date' => $row['post_date_time'],
'twitter_share_link' => "<a href='http://www.twitter.com/intent/tweet?url=http://www.localhost".$url."&text=".$row['post_topic']." target='_blank'>Share On Twitter</a>",
'facebook_share_link' => "<a href='https://www.facebook.com/sharer/sharer.php?u=http://www.localhost".$url." target='_blank'>Share On Facebook</a>"
);

// push to data array
array_push($posts_arr['data'], $post_item);
}

// convert the result to json and output it
echo json_encode($posts_arr);
} else {
// if there is no post in the database
echo json_encode(
array(
'status' => 404,
'message' => 'No posts found'
)
);
}
} else {
// if there is no post in the database
echo json_encode(
array(
'status' => 404,
'message' => 'Invalid post request'
)
);
}
?>
36 changes: 0 additions & 36 deletions Helpers/Config.php

This file was deleted.

14 changes: 14 additions & 0 deletions Helpers/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,21 @@ public static function makeAdmin(){

}

// share post feature by Kazeem
public static function getPostsToShare($conn, $post_id)
{
// join the table of the users and the posts so as to get the user's name where the user_id is the same as the post_author
$query = "SELECT posts.*, users.name FROM posts INNER JOIN users ON posts.post_author = users.user_id WHERE post_id = '$post_id' ORDER BY post_id DESC";
$result = mysqli_query($conn, $query);

if(mysqli_num_rows($result) > 0){
return $result;
}else{
$arr=[];
return $arr;
}
}
}



Expand Down
161 changes: 0 additions & 161 deletions Helpers/ForgotPassword.php

This file was deleted.