mirror of
https://github.com/Neetpone/ponepaste.git
synced 2025-03-12 14:40:09 +01:00
Work on user.php; untested
This commit is contained in:
parent
75fa51f0c6
commit
e6f314e53a
5 changed files with 99 additions and 416 deletions
|
@ -7,27 +7,27 @@ require_once('config.php');
|
||||||
require_once('includes/functions.php');
|
require_once('includes/functions.php');
|
||||||
|
|
||||||
|
|
||||||
function getSiteInfo($conn) {
|
function getSiteInfo(PDO $conn) : array {
|
||||||
return $conn->query('SELECT * FROM site_info LIMIT 1')->fetch();
|
return $conn->query('SELECT * FROM site_info LIMIT 1')->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSiteLangAndTheme($conn) {
|
function getSiteLangAndTheme(PDO $conn) : array {
|
||||||
return $conn->query('SELECT lang, theme FROM interface LIMIT 1')->fetch();
|
return $conn->query('SELECT lang, theme FROM interface LIMIT 1')->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSitePermissions($conn) {
|
function getSitePermissions(PDO $conn) : array {
|
||||||
return $conn->query('SELECT * FROM site_permissions LIMIT 1')->fetch();
|
return $conn->query('SELECT * FROM site_permissions LIMIT 1')->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSiteAds($conn) {
|
function getSiteAds(PDO $conn) : array | bool {
|
||||||
return $conn->query('SELECT text_ads, ads_1, ads_2 FROM ads LIMIT 1')->fetch();
|
return $conn->query('SELECT text_ads, ads_1, ads_2 FROM ads LIMIT 1')->fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSiteTotalPastes($conn) {
|
function getSiteTotalPastes(PDO $conn) : int {
|
||||||
return intval($conn->query('SELECT COUNT(*) FROM pastes')->fetch(PDO::FETCH_NUM)[0]);
|
return intval($conn->query('SELECT COUNT(*) FROM pastes')->fetch(PDO::FETCH_NUM)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePageViews($conn) {
|
function updatePageViews(PDO $conn) : void {
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
$date = date('jS F Y');
|
$date = date('jS F Y');
|
||||||
$data_ip = file_get_contents('tmp/temp.tdata');
|
$data_ip = file_get_contents('tmp/temp.tdata');
|
||||||
|
|
|
@ -307,20 +307,14 @@ function isValidUsername($str) {
|
||||||
return !preg_match('/[^A-Za-z0-9._\\-$]/', $str);
|
return !preg_match('/[^A-Za-z0-9._\\-$]/', $str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function existingUser( $conn, $username ) {
|
function existingUser(PDO $conn, string $username) : bool {
|
||||||
$query = "SELECT username FROM users WHERE username = '$username'";
|
$query = $conn->prepare('SELECT 1 FROM users WHERE username = ?');
|
||||||
$result = mysqli_query( $conn, $query );
|
$query->execute([$username]);
|
||||||
$num_rows = mysqli_num_rows( $result );
|
|
||||||
if ( $num_rows == 0 ) {
|
return (bool) $query->fetch();
|
||||||
// No records. User doesn't exist.
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateMyView($conn, $paste_id)
|
function updateMyView($conn, $paste_id) {
|
||||||
{
|
|
||||||
$query = $conn->prepare("SELECT views, id FROM pastes WHERE id= ?");
|
$query = $conn->prepare("SELECT views, id FROM pastes WHERE id= ?");
|
||||||
$query->execute([$paste_id]);
|
$query->execute([$paste_id]);
|
||||||
if ($row = $query->fetch()) {
|
if ($row = $query->fetch()) {
|
||||||
|
|
|
@ -164,63 +164,6 @@ namespace {
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get information about the password hash. Returns an array of the information
|
|
||||||
* that was used to generate the password hash.
|
|
||||||
*
|
|
||||||
* array(
|
|
||||||
* 'algo' => 1,
|
|
||||||
* 'algoName' => 'bcrypt',
|
|
||||||
* 'options' => array(
|
|
||||||
* 'cost' => PASSWORD_BCRYPT_DEFAULT_COST,
|
|
||||||
* ),
|
|
||||||
* )
|
|
||||||
*
|
|
||||||
* @param string $hash The password hash to extract info from
|
|
||||||
*
|
|
||||||
* @return array The array of information about the hash.
|
|
||||||
*/
|
|
||||||
function password_get_info($hash) {
|
|
||||||
$return = array(
|
|
||||||
'algo' => 0,
|
|
||||||
'algoName' => 'unknown',
|
|
||||||
'options' => array(),
|
|
||||||
);
|
|
||||||
if (PasswordCompat\binary\_substr($hash, 0, 4) == '$2y$' && PasswordCompat\binary\_strlen($hash) == 60) {
|
|
||||||
$return['algo'] = PASSWORD_BCRYPT;
|
|
||||||
$return['algoName'] = 'bcrypt';
|
|
||||||
list($cost) = sscanf($hash, "$2y$%d$");
|
|
||||||
$return['options']['cost'] = $cost;
|
|
||||||
}
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the password hash needs to be rehashed according to the options provided
|
|
||||||
*
|
|
||||||
* If the answer is true, after validating the password using password_verify, rehash it.
|
|
||||||
*
|
|
||||||
* @param string $hash The hash to test
|
|
||||||
* @param int $algo The algorithm used for new password hashes
|
|
||||||
* @param array $options The options array passed to password_hash
|
|
||||||
*
|
|
||||||
* @return boolean True if the password needs to be rehashed.
|
|
||||||
*/
|
|
||||||
function password_needs_rehash($hash, $algo, array $options = array()) {
|
|
||||||
$info = password_get_info($hash);
|
|
||||||
if ($info['algo'] !== (int) $algo) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
switch ($algo) {
|
|
||||||
case PASSWORD_BCRYPT:
|
|
||||||
$cost = isset($options['cost']) ? (int) $options['cost'] : PASSWORD_BCRYPT_DEFAULT_COST;
|
|
||||||
if ($cost !== $info['options']['cost']) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify a password against a hash using a timing attack resistant approach
|
* Verify a password against a hash using a timing attack resistant approach
|
||||||
|
@ -230,7 +173,7 @@ namespace {
|
||||||
*
|
*
|
||||||
* @return boolean If the password matches the hash
|
* @return boolean If the password matches the hash
|
||||||
*/
|
*/
|
||||||
function password_verify($password, $hash) {
|
function password_verify(string $password, string $hash): bool {
|
||||||
if (!function_exists('crypt')) {
|
if (!function_exists('crypt')) {
|
||||||
trigger_error("Crypt must be loaded for password_verify to function", E_USER_WARNING);
|
trigger_error("Crypt must be loaded for password_verify to function", E_USER_WARNING);
|
||||||
return false;
|
return false;
|
||||||
|
|
162
profile.php
162
profile.php
|
@ -24,179 +24,59 @@ header('Content-Type: text/html; charset=utf-8');
|
||||||
|
|
||||||
$date = date('jS F Y');
|
$date = date('jS F Y');
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
$data_ip = file_get_contents('tmp/temp.tdata');
|
|
||||||
$con = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
|
|
||||||
|
|
||||||
if (mysqli_connect_errno()) {
|
|
||||||
die("Unable to connect to database");
|
|
||||||
}
|
|
||||||
$query = "SELECT * FROM site_info";
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$title = Trim($row['title']);
|
|
||||||
$des = Trim($row['des']);
|
|
||||||
$baseurl = Trim($row['baseurl']);
|
|
||||||
$keyword = Trim($row['keyword']);
|
|
||||||
$site_name = Trim($row['site_name']);
|
|
||||||
$email = Trim($row['email']);
|
|
||||||
$twit = Trim($row['twit']);
|
|
||||||
$face = Trim($row['face']);
|
|
||||||
$gplus = Trim($row['gplus']);
|
|
||||||
$ga = Trim($row['ga']);
|
|
||||||
$additional_scripts = Trim($row['additional_scripts']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set theme and language
|
|
||||||
$query = "SELECT * FROM interface";
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$default_lang = Trim($row['lang']);
|
|
||||||
$default_theme = Trim($row['theme']);
|
|
||||||
}
|
|
||||||
require_once("langs/$default_lang");
|
|
||||||
|
|
||||||
$p_title = $lang['myprofile']; //"My Profile";
|
$p_title = $lang['myprofile']; //"My Profile";
|
||||||
|
|
||||||
// Check if IP is banned
|
|
||||||
if ( is_banned($con, $ip) ) die($lang['banned']); // "You have been banned from ".$site_name;
|
|
||||||
|
|
||||||
// Site permissions
|
|
||||||
$query = "SELECT * FROM site_permissions where id='1'";
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$siteprivate = Trim($row['siteprivate']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
||||||
} else {
|
|
||||||
if ($siteprivate =="on") {
|
|
||||||
$privatesite = "on";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if already logged in
|
// Check if already logged in
|
||||||
if (isset($_SESSION['token'])) {
|
if (isset($_SESSION['token'])) {
|
||||||
} else {
|
} else {
|
||||||
header("Location: ./login.php");
|
header("Location: ./login.php");
|
||||||
}
|
}
|
||||||
|
$user_username = htmlentities(trim($_SESSION['username']));
|
||||||
|
|
||||||
// Logout
|
$query = $conn->prepare('SELECT * FROM users WHERE username = ?');
|
||||||
if (isset($_GET['logout'])) {
|
$query->execute([$user_username]);
|
||||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
$row = $query->fetch();
|
||||||
unset($_SESSION['token']);
|
$user_oauth_uid = $row['oauth_uid'];
|
||||||
unset($_SESSION['oauth_uid']);
|
$user_id = $row['id'];
|
||||||
unset($_SESSION['username']);
|
$user_email_id = $row['email_id'];
|
||||||
session_destroy();
|
$user_full_name = $row['full_name'];
|
||||||
}
|
$user_platform = Trim($row['platform']);
|
||||||
|
$user_verified = $row['verified'];
|
||||||
|
$user_date = $row['date'];
|
||||||
|
$user_ip = $row['ip'];
|
||||||
|
$user_password = $row['password'];
|
||||||
|
|
||||||
|
|
||||||
$user_username = htmlentities(Trim($_SESSION['username']));
|
|
||||||
$query = "SELECT * FROM users WHERE username='$user_username'";
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$user_oauth_uid = $row['oauth_uid'];
|
|
||||||
$user_id = $row['id'];
|
|
||||||
$user_email_id = $row['email_id'];
|
|
||||||
$user_full_name = $row['full_name'];
|
|
||||||
$user_platform = Trim($row['platform']);
|
|
||||||
$user_verified = $row['verified'];
|
|
||||||
$user_date = $row['date'];
|
|
||||||
$user_ip = $row['ip'];
|
|
||||||
$user_password = $row['password'];
|
|
||||||
}
|
|
||||||
if ($user_oauth_uid == '0') {
|
if ($user_oauth_uid == '0') {
|
||||||
$user_oauth_uid = "None";
|
$user_oauth_uid = "None";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||||
if (isset($_POST['cpassword'])) {
|
if (isset($_POST['cpassword'])) {
|
||||||
$user_new_full = Trim(htmlspecialchars($_POST['full']));
|
$user_new_full = trim(htmlspecialchars($_POST['full']));
|
||||||
$user_old_pass = $_POST['old_password'];
|
$user_old_pass = $_POST['old_password'];
|
||||||
$user_new_cpass = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
|
||||||
if (password_verify($user_old_pass, $user_password)) {
|
if (password_verify($user_old_pass, $user_password)) {
|
||||||
$query = "UPDATE users SET full_name='$user_new_full', password='$user_new_cpass' WHERE username='$user_username'";
|
$user_new_cpass = password_hash($_POST['password'], PASSWORD_DEFAULT);
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
if (mysqli_errno($con)) {
|
$conn->prepare('UPDATE users SET full_name = ?, password = ? WHERE username = ?')
|
||||||
$success = $lang['profileerror']; //" Unable to update the profile information ";
|
->execute([$user_new_full, $user_new_cpass, $user_username]);
|
||||||
} else {
|
|
||||||
$success = $lang['profileupdated']; //" Your profile information is updated ";
|
$success = $lang['profileupdated']; //" Your profile information is updated ";
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$error = $lang['oldpasswrong']; // " Your old password is wrong.";
|
$error = $lang['oldpasswrong']; // " Your old password is wrong.";
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$error = $lang['error']; //"Something went wrong.";
|
$error = $lang['error']; //"Something went wrong.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Page views
|
updatePageViews($conn);
|
||||||
$query = "SELECT @last_id := MAX(id) FROM page_view";
|
|
||||||
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$last_id = $row['@last_id := MAX(id)'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT * FROM page_view WHERE id=" . Trim($last_id);
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$last_date = $row['date'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($last_date == $date) {
|
|
||||||
if (str_contains($data_ip, $ip)) {
|
|
||||||
$query = "SELECT * FROM page_view WHERE id=" . Trim($last_id);
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$last_tpage = Trim($row['tpage']);
|
|
||||||
}
|
|
||||||
$last_tpage = $last_tpage + 1;
|
|
||||||
|
|
||||||
// IP already exists, update page views.
|
|
||||||
$query = "UPDATE page_view SET tpage=$last_tpage WHERE id=" . Trim($last_id);
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
} else {
|
|
||||||
$query = "SELECT * FROM page_view WHERE id=" . Trim($last_id);
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$last_tpage = Trim($row['tpage']);
|
|
||||||
$last_tvisit = Trim($row['tvisit']);
|
|
||||||
}
|
|
||||||
$last_tpage = $last_tpage + 1;
|
|
||||||
$last_tvisit = $last_tvisit + 1;
|
|
||||||
|
|
||||||
// Update both tpage and tvisit.
|
|
||||||
$query = "UPDATE page_view SET tpage=$last_tpage,tvisit=$last_tvisit WHERE id=" . Trim($last_id);
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
file_put_contents('tmp/temp.tdata', $data_ip . "\r\n" . $ip);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Delete the file and clear data_ip
|
|
||||||
unlink("tmp/temp.tdata");
|
|
||||||
$data_ip = "";
|
|
||||||
|
|
||||||
// New date is created
|
|
||||||
$query = "INSERT INTO page_view (date,tpage,tvisit) VALUES ('$date','1','1')";
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
|
|
||||||
// Update the IP
|
|
||||||
file_put_contents('tmp/temp.tdata', $data_ip . "\r\n" . $ip);
|
|
||||||
|
|
||||||
}
|
|
||||||
$total_pastes = getTotalPastes($con, $user_username);
|
$total_pastes = getTotalPastes($con, $user_username);
|
||||||
|
|
||||||
// Theme
|
// Theme
|
||||||
require_once('theme/' . $default_theme . '/header.php');
|
require_once('theme/' . $default_theme . '/header.php');
|
||||||
require_once('theme/' . $default_theme . '/profile.php');
|
require_once('theme/' . $default_theme . '/profile.php');
|
||||||
require_once('theme/' . $default_theme . '/footer.php');
|
require_once('theme/' . $default_theme . '/footer.php');
|
||||||
?>
|
|
264
user.php
264
user.php
|
@ -22,226 +22,93 @@ header('Content-Type: text/html; charset=utf-8');
|
||||||
|
|
||||||
$date = date('jS F Y');
|
$date = date('jS F Y');
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
$data_ip = file_get_contents('tmp/temp.tdata');
|
|
||||||
$con = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
|
|
||||||
|
|
||||||
if (mysqli_connect_errno()) {
|
|
||||||
die("Unable to connect to database");
|
|
||||||
}
|
|
||||||
$query = "SELECT * FROM site_info";
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$title = Trim($row['title']);
|
|
||||||
$des = Trim($row['des']);
|
|
||||||
$baseurl = Trim($row['baseurl']);
|
|
||||||
$keyword = Trim($row['keyword']);
|
|
||||||
$site_name = Trim($row['site_name']);
|
|
||||||
$email = Trim($row['email']);
|
|
||||||
$twit = Trim($row['twit']);
|
|
||||||
$face = Trim($row['face']);
|
|
||||||
$gplus = Trim($row['gplus']);
|
|
||||||
$ga = Trim($row['ga']);
|
|
||||||
$additional_scripts = Trim($row['additional_scripts']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set theme and language
|
|
||||||
$query = "SELECT * FROM interface";
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$default_lang = Trim($row['lang']);
|
|
||||||
$default_theme = Trim($row['theme']);
|
|
||||||
}
|
|
||||||
require_once("langs/$default_lang");
|
|
||||||
|
|
||||||
// Check if IP is banned
|
|
||||||
if ( is_banned($con, $ip) ) die($lang['banned']); // "You have been banned from ".$site_name;
|
|
||||||
|
|
||||||
// Site permissions
|
|
||||||
$query = "SELECT * FROM site_permissions where id='1'";
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$siteprivate = Trim($row['siteprivate']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
||||||
} else {
|
|
||||||
if ($siteprivate =="on") {
|
|
||||||
$privatesite = "on";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If username defined in URL, then check if it's exists in database. If invalid, redirect to main site.
|
// If username defined in URL, then check if it's exists in database. If invalid, redirect to main site.
|
||||||
$user_username = Trim($_SESSION['username']);
|
$user_username = trim($_SESSION['username']);
|
||||||
if ( isset( $_GET['user'] ) ) {
|
if (isset($_GET['user'])) {
|
||||||
$profile_username = trim( $_GET['user'] );
|
$profile_username = trim($_GET['user']);
|
||||||
if ( !existingUser( $con, $profile_username ) ) {
|
|
||||||
|
if (!existingUser( $con, $profile_username ) ) {
|
||||||
// Invalid username
|
// Invalid username
|
||||||
header("Location: ../error.php");
|
header("Location: ../error.php");
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No access to user.php
|
// No access to user.php
|
||||||
header("Location: ../error.php");
|
header("Location: ../error.php");
|
||||||
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
$p_title = $profile_username . $lang['user_public_pastes']; // "Username's Public Pastes"
|
$p_title = $profile_username . $lang['user_public_pastes']; // "Username's Public Pastes"
|
||||||
|
|
||||||
//Favorite Counts
|
// Favorite Counts
|
||||||
$query = "SELECT pins.f_time, pins.m_fav, pins.f_paste, pastes.member, pastes.title, pastes.now_time, pastes.tagsys FROM pins, pastes WHERE pins.f_paste = pastes.id AND pastes.member='$profile_username'";
|
$query = $conn->prepare(
|
||||||
$result = mysqli_query($con, $query);
|
'SELECT COUNT(*) FROM pins INNER JOIN pastes ON pins.f_paste = pastes.id WHERE pastes.member = ?'
|
||||||
$total_pfav = 0;
|
);
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
$query->execute([$profile_username]);
|
||||||
$total_pfav = $total_pfav + 1;
|
$total_pfav = intval($query->fetch(PDO::FETCH_NUM)[0]);
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT pins.f_time, pins.m_fav, pins.f_paste, pastes.id, pastes.title, pastes.now_time, pastes.tagsys FROM pins, pastes WHERE pins.f_paste = pastes.id AND pins.m_fav='$profile_username'";
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
$total_yfav = 0;
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$total_yfav = $total_yfav + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Badges System
|
|
||||||
$query = "SELECT * FROM users where username = '$profile_username'";
|
|
||||||
$result = mysqli_query( $con, $query );
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$profile_badge = $row['badge'];
|
|
||||||
switch ($profile_badge) {
|
|
||||||
case 1:
|
|
||||||
$profile_badge = '<img src = "/img/badges/donate.png" title="[Donated] Donated to Ponepaste" style="margin:5px">';
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
$profile_badge = '<img src = "/img/badges/spoon.png" title="[TheWoodenSpoon] You had one job" style="margin:5px">';
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$profile_badge = '<img src = "/img/badges/abadge.png" title="[>AFuckingBadge] Won a PasteJam Competition" style="margin:5px">';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "SELECT count(*) as count FROM pastes where member = '$profile_username'";
|
|
||||||
$result = mysqli_query( $con, $query );
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$profile_total_pastes = $row['count'];
|
|
||||||
}
|
|
||||||
$query = "SELECT count(*) as count FROM pastes where member = '$profile_username' and visible = 0";
|
|
||||||
$result = mysqli_query( $con, $query );
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$profile_total_public = $row['count'];
|
|
||||||
}
|
|
||||||
$query = "SELECT count(*) as count FROM pastes where member = '$profile_username' and visible = 1";
|
|
||||||
$result = mysqli_query( $con, $query );
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$profile_total_unlisted = $row['count'];
|
|
||||||
}
|
|
||||||
$query = "SELECT count(*) as count FROM pastes where member = '$profile_username' and visible = 2";
|
|
||||||
$result = mysqli_query( $con, $query );
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$profile_total_private = $row['count'];
|
|
||||||
}
|
|
||||||
$query = "SELECT sum(views) as total FROM pastes where member = '$profile_username'";
|
|
||||||
$result = mysqli_query( $con, $query );
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$profile_total_paste_views = $row['total'];
|
|
||||||
}
|
|
||||||
$query = "SELECT date FROM users where username = '$profile_username'";
|
|
||||||
$result = mysqli_query( $con, $query );
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$profile_join_date = $row['date'];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Logout
|
$query = $conn->prepare(
|
||||||
if (isset($_GET['logout'])) {
|
'SELECT COUNT(*) FROM pins INNER JOIN pastes ON pins.f_paste = pastes.id WHERE pins.m_fav = ?'
|
||||||
unset($_SESSION['token']);
|
);
|
||||||
unset($_SESSION['oauth_uid']);
|
$query->execute([$profile_username]);
|
||||||
unset($_SESSION['username']);
|
$total_yfav = intval($query->fetch(PDO::FETCH_NUM)[0]);
|
||||||
session_destroy();
|
|
||||||
header("location:index.php");
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Page views
|
// Badges
|
||||||
$query = "SELECT @last_id := MAX(id) FROM page_view";
|
$query = $conn->prepare('SELECT badge FROM users WHERE username = ?');
|
||||||
|
$query->execute([$profile_username]);
|
||||||
|
|
||||||
$result = mysqli_query($con, $query);
|
$profile_badge = match ($query->fetch()['badge']) {
|
||||||
|
1 => '<img src = "/img/badges/donate.png" title="[Donated] Donated to Ponepaste" style="margin:5px">',
|
||||||
|
2 => '<img src = "/img/badges/spoon.png" title="[TheWoodenSpoon] You had one job" style="margin:5px">',
|
||||||
|
3 => '<img src = "/img/badges/abadge.png" title="[>AFuckingBadge] Won a PasteJam Competition" style="margin:5px">',
|
||||||
|
default => '',
|
||||||
|
};
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
$query = $conn->prepare('SELECT COUNT(*) FROM pastes WHERE member = ?');
|
||||||
$last_id = $row['@last_id := MAX(id)'];
|
$query->execute([$profile_username]);
|
||||||
}
|
$profile_total_pastes = intval($query->fetch(PDO::FETCH_NUM)[0]);
|
||||||
|
|
||||||
$query = "SELECT * FROM page_view WHERE id=" . Trim($last_id);
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$last_date = $row['date'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($last_date == $date) {
|
|
||||||
if (str_contains($data_ip, $ip)) {
|
|
||||||
$query = "SELECT * FROM page_view WHERE id=" . Trim($last_id);
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$last_tpage = Trim($row['tpage']);
|
|
||||||
}
|
|
||||||
$last_tpage = $last_tpage + 1;
|
|
||||||
|
|
||||||
// IP already exists, update page views
|
|
||||||
$query = "UPDATE page_view SET tpage=$last_tpage WHERE id=" . Trim($last_id);
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
} else {
|
|
||||||
$query = "SELECT * FROM page_view WHERE id=" . Trim($last_id);
|
|
||||||
$result = mysqli_query($con, $query);
|
|
||||||
|
|
||||||
while ($row = mysqli_fetch_array($result)) {
|
|
||||||
$last_tpage = Trim($row['tpage']);
|
|
||||||
$last_tvisit = Trim($row['tvisit']);
|
|
||||||
}
|
|
||||||
$last_tpage = $last_tpage + 1;
|
|
||||||
$last_tvisit = $last_tvisit + 1;
|
|
||||||
|
|
||||||
// Update both tpage and tvisit.
|
|
||||||
$query = "UPDATE page_view SET tpage=$last_tpage,tvisit=$last_tvisit WHERE id=" . Trim($last_id);
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
file_put_contents('tmp/temp.tdata', $data_ip . "\r\n" . $ip);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Delete the file and clear data_ip
|
|
||||||
unlink("tmp/temp.tdata");
|
|
||||||
$data_ip = "";
|
|
||||||
|
|
||||||
// New date is created
|
|
||||||
$query = "INSERT INTO page_view (date,tpage,tvisit) VALUES ('$date','1','1')";
|
|
||||||
mysqli_query($con, $query);
|
|
||||||
|
|
||||||
// Update the IP
|
|
||||||
file_put_contents('tmp/temp.tdata', $data_ip . "\r\n" . $ip);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
$query = $conn->prepare('SELECT COUNT(*) FROM pastes WHERE member = ? AND visible = 0');
|
||||||
|
$query->execute([$profile_username]);
|
||||||
|
$profile_total_public = intval($query->fetch(PDO::FETCH_NUM)[0]);
|
||||||
|
|
||||||
if ( isset($_GET['del']) ) {
|
$query = $conn->prepare('SELECT COUNT(*) FROM pastes WHERE member = ? AND visible = 1');
|
||||||
if ( $_SESSION['token'] ) { // Prevent unauthorized deletes
|
$query->execute([$profile_username]);
|
||||||
$paste_id = htmlentities( Trim( $_GET['id'] ) );
|
$profile_total_unlisted = intval($query->fetch(PDO::FETCH_NUM)[0]);
|
||||||
// Check if logged in user owns the paste
|
|
||||||
$query = "SELECT * FROM pastes WHERE id='$paste_id' and member='$user_username'";
|
$query = $conn->prepare('SELECT COUNT(*) FROM pastes WHERE member = ? AND visible = 2');
|
||||||
$result = mysqli_query($con, $query);
|
$query->execute([$profile_username]);
|
||||||
$num_rows = mysqli_num_rows($result);
|
$profile_total_private = intval($query->fetch(PDO::FETCH_NUM)[0]);
|
||||||
if ( $num_rows == 0 ) {
|
|
||||||
|
$query = $conn->prepare('SELECT SUM(views) FROM pastes WHERE member = ?');
|
||||||
|
$query->execute([$profile_username]);
|
||||||
|
$profile_total_paste_views = intval($query->fetch(PDO::FETCH_NUM)[0]);
|
||||||
|
|
||||||
|
|
||||||
|
$query = $conn->prepare('SELECT date FROM users WHERE username = ?');
|
||||||
|
$query->execute([$profile_username]);
|
||||||
|
$profile_join_date = $query->fetch()['date'];
|
||||||
|
|
||||||
|
|
||||||
|
updatePageViews($conn);
|
||||||
|
|
||||||
|
if (isset($_GET['del'])) {
|
||||||
|
if ($_SESSION['token']) { // Prevent unauthorized deletes
|
||||||
|
$paste_id = intval(trim($_GET['id']));
|
||||||
|
|
||||||
|
$query = $conn->prepare('SELECT member FROM pastes WHERE id = ?');
|
||||||
|
$query->execute([$paste_id]);
|
||||||
|
$result = $query->fetch();
|
||||||
|
|
||||||
|
if (empty($result) || $result['member'] !== $user_username) {
|
||||||
$error = $lang['delete_error_invalid']; // Does not exist or not paste owner
|
$error = $lang['delete_error_invalid']; // Does not exist or not paste owner
|
||||||
} else {
|
} else {
|
||||||
$query = "DELETE FROM pastes WHERE id='$paste_id' and member='$user_username'";
|
$query = $conn->prepare('DELETE FROM pastes WHERE id = ?');
|
||||||
$result = mysqli_query($con, $query);
|
$query->execute([$paste_id]);
|
||||||
|
$success = $lang['pastedeleted']; // "Paste deleted successfully."
|
||||||
if ( mysqli_errno( $con ) ) {
|
|
||||||
$error = $lang['error']; // "Something went wrong";
|
|
||||||
} else {
|
|
||||||
$success = $lang['pastedeleted']; // "Paste deleted successfully.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$error = $lang['not_logged_in']; // Must be logged in to do that
|
$error = $lang['not_logged_in']; // Must be logged in to do that
|
||||||
|
@ -252,4 +119,3 @@ if ( isset($_GET['del']) ) {
|
||||||
require_once('theme/' . $default_theme . '/header.php');
|
require_once('theme/' . $default_theme . '/header.php');
|
||||||
require_once('theme/' . $default_theme . '/user_profile.php');
|
require_once('theme/' . $default_theme . '/user_profile.php');
|
||||||
require_once('theme/' . $default_theme . '/footer.php');
|
require_once('theme/' . $default_theme . '/footer.php');
|
||||||
?>
|
|
Loading…
Add table
Reference in a new issue