YaWK  24.1
Yet another WebKit
follow-user.php
Go to the documentation of this file.
1 <?php
2 /*
3 if (!isset($_POST['token'])) {
4  die ('no direct access allowed.');
5 }
6 else if ($_POST['token'] != "U3E44ERG0H0M3") {
7  die ('no direct access allowed!');
8 }
9 */
10 include '../../system/classes/db.php';
11 include '../../system/classes/sys.php';
12 include '../../system/classes/user.php';
13 include '../../system/classes/alert.php';
14 include '../../system/classes/settings.php';
15 
16 /* set database object */
17 if (!isset($db))
18 { // create new db object
19  $db = new \YAWK\db();
20 }
21 
22 $uid = $_POST['uid'];
23 $hunted = $_POST['hunted'];
24 $userB = $_POST['user'];
25 $userA = \YAWK\user::getUserNameFromID($db, $uid);
26 
27 // check if uid follows hunted already
28 if ($sql = $db->query("SELECT id FROM {follower} WHERE follower = '".$uid."' AND hunted = '".$hunted."'"))
29 { // if user is already following each other...
30  if ($res = mysqli_fetch_row($sql))
31  { // already exists
32  if ($sql = $db->query("DELETE FROM {follower} WHERE follower = '".$uid."' AND hunted = '".$hunted."'"))
33  { // un-followd with user
34  \YAWK\sys::setSyslog($db, 17, 0, "$userA un-followed $userB.", $uid, $hunted, 0, 0);
35  // \YAWK\sys::setNotification($db, 3, "$userA do not follow you anymore.", $uid, $hunted, 0, 0);
36  \YAWK\sys::setNotification($db, 3, 0, $uid, $hunted, 0, 0,0);
37  \YAWK\alert::draw("warning","Disconnected with $userB", "You are not following $userB anymore.","",4200);
38  }
39  }
40  else
41  { // user is not in db, follow now:
42  if ($db->query("INSERT INTO {follower} (follower, hunted) VALUES ('$uid', '$hunted')"))
43  { // follow successful
44  \YAWK\sys::setSyslog($db, 17, 0, "$userA follows $userB.", $uid, $hunted, 0, 0);
45  // \YAWK\sys::setNotification($db, 3, "$userA follows you.", $uid, $hunted, 0, 0);
46  \YAWK\sys::setNotification($db, 3, 0, $uid, $hunted, 0, 0,0);
47  echo \YAWK\alert::draw("success", "You follow $userB from now.", "Good to keep your network up :)","",4200);
48  }
49  else
50  { // follow not successful
51  echo \YAWK\alert::draw("warning", "Error!", "A database error occured, your request could not be done. Please try again.","",4200);
52  }
53  }
54 }
55 else
56  { // follow not successful
57  echo \YAWK\alert::draw("danger", "Error!", "Some kind of error happened to the database. Please try again.","",4200);
58  }
static draw($type, $title, $text, $redirect, $delay)
Definition: alert.php:30
$userB
Definition: follow-user.php:24
$userA
Definition: follow-user.php:25
if(!isset($db)) $uid
Definition: follow-user.php:22
$hunted
Definition: follow-user.php:23
$sql
Definition: message-new.php:32