OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
Xpress
/
assets
/
php
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
03/05/2025 10:50:21 AM
rwxr-xr-x
📄
12-03-25social_navbar.php
24.96 KB
05/19/2025 10:07:16 AM
rw-r--r--
📁
PHPMailer
-
05/19/2025 10:07:16 AM
rwxr-xr-x
📄
backup-navbar.php
27.29 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
backupnavbar.php
21.23 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
blockAccount.php
2.23 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
bnavbar.php
35.82 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
bottom_navbar.php
6.18 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
common.js
46.89 KB
03/05/2025 10:50:22 AM
rw-r--r--
📄
config.php
9.38 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
db_config.php
3.43 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
db_connect.php
293 bytes
05/19/2025 10:07:16 AM
rw-r--r--
📄
delete_account.php
3.5 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
edit_post.php
2.23 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
footer.php
1.28 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
function.php
20.12 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
go_backbar.php
4.01 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
handler.php
3.46 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
indexFooter.php
597 bytes
05/19/2025 10:07:16 AM
rw-r--r--
📄
mail.php
2.67 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
navbar.php
24.1 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
process_data.php
3.87 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
readert_validate.logged.php
481 bytes
05/19/2025 10:07:16 AM
rw-r--r--
📄
report_account.php
1.42 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
report_stream.php
2.08 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
savePost.php
2.38 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
sidebar.php
19.71 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
siginupProcess.php
5.24 KB
05/19/2025 10:07:16 AM
rw-r--r--
📁
simplepie
-
05/19/2025 10:07:16 AM
rwxr-xr-x
📄
social_navbar.php
25.92 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
stream_post_handler.php
3.68 KB
05/19/2025 10:07:16 AM
rw-r--r--
📄
validate.logged.php
1.01 KB
05/19/2025 10:07:16 AM
rw-r--r--
Editing: handler.php
Close
<?php // Function to check if the user has already liked the post function hasUserLiked($conn, $userId, $streamId) { $query = "SELECT 1 FROM reader_stream_like WHERE userId = ? AND streamId = ?"; $stmt = $conn->prepare($query); $stmt->bind_param("ii", $userId, $streamId); $stmt->execute(); $stmt->store_result(); return $stmt->num_rows > 0; // Return true if the user has already liked, else false } // Function to insert a like (like the post) function insertLike($conn, $userId, $streamId) { $query = "INSERT INTO reader_stream_like (userId, streamId) VALUES (?, ?)"; $stmt = $conn->prepare($query); $stmt->bind_param("ii", $userId, $streamId); return $stmt->execute(); } // Function to delete a like (unlike the post) function deleteLike($conn, $userId, $streamId) { $query = "DELETE FROM reader_stream_like WHERE userId = ? AND streamId = ?"; $stmt = $conn->prepare($query); $stmt->bind_param("ii", $userId, $streamId); return $stmt->execute(); } // Function to get the like count for a stream function getLikeCount($conn, $streamId) { $query = "SELECT COUNT(*) AS like_count FROM reader_stream_like WHERE streamId = ?"; $stmt = $conn->prepare($query); $stmt->bind_param("i", $streamId); $stmt->execute(); $result = $stmt->get_result(); $data = $result->fetch_assoc(); return $data['like_count']; } // Include your database connection (assumed to be set up in db.php) include('db_connect.php'); // Get the raw POST data $data = json_decode(file_get_contents('php://input'), true); // Check if data is valid if (isset($data['request'], $data['userId'], $data['feedId'])) { $request = $data['request']; $userId = $data['userId']; $streamId = $data['feedId']; // FeedId corresponds to streamId // Handle like or unlike action if ($request === 'like') { // Check if the user has already liked this post if (!hasUserLiked($conn, $userId, $streamId)) { // User has not liked yet, so insert a new like if (insertLike($conn, $userId, $streamId)) { // After inserting, get the new like count $likeCount = getLikeCount($conn, $streamId); $response = ['status' => 'success', 'likeCount' => $likeCount]; } else { $response = ['status' => 'error', 'message' => 'Unable to like post']; } } else { $response = ['status' => 'error', 'message' => 'You already liked this post']; } } elseif ($request === 'unlike') { // User has liked this post, so remove the like if (deleteLike($conn, $userId, $streamId)) { // After deleting, get the updated like count $likeCount = getLikeCount($conn, $streamId); // If there are no likes, return null (or 0 depending on your preference) $response = ['status' => 'success', 'likeCount' => $likeCount > 0 ? $likeCount : null]; } else { $response = ['status' => 'error', 'message' => 'Unable to unlike post']; } } else { // Invalid request type $response = ['status' => 'error', 'message' => 'Invalid request']; } } else { $response = ['status' => 'error', 'message' => 'Invalid data']; } // Set the response content type to JSON and return the response header('Content-Type: application/json'); echo json_encode($response); ?>