<?php
require_once 'libraries/DB.php';
class Account {
public const ID = 0;
public const USERNAME = 1;
public const EMAIL = 2;
public const AVATAR = 3;
public const FOLLOWING = 0;
public const NOTFOLLOWING = 1;
public const BLOCKED = 2;
public static function verify($username, $password) {
$data = DB::getData('accounts', 'Username', 'username', $username);
if ($data != NULL) {
$pass = DB::getData('accounts', 'Password', 'username', $username);
if (password_verify($password, $pass))
return true;
return false;
}
return false;
}
public static function getLatestPosts($userid, $limit) {
return DB::query('SELECT * FROM posts WHERE user_id=:user_id ORDER BY id DESC LIMIT '.$limit, array(':user_id'=>$userid));
}
public static function isLoggedIn() {
$cookie = cookies::getCookie('SNID');
if ($cookie != NULL) {
$enct = self::encryptedToken($cookie);
$query = DB::getData('logintokens', 'id', 'value', $enct);
if ($query)
return true;
}
return false;
}
public static function createPost($class, $index, $date, $message, $userid) {
echo '<script>';
echo '$("'.$class.'").append("<div class=\"userpost\" id=\"userpost'.$index.'\"></div>");';
echo '$("'.$class.' #userpost'.$index.'").append("';
echo '<div id=\"postdate\"> '.$date.'</div>';
echo '<div id=\"message\">'.$message.'</div>';
echo '<div id=\"username\"><img src=\"'.self::getData(self::AVATAR, $userid).'\"> '.self::getData(self::USERNAME, $userid).'</div>';
echo '");';
echo '</script>';
}
public static function signOut() {
$cookie = cookies::getCookie('SNID');
if ($cookie != null) {
$enct = self::encryptedToken($cookie);
DB::deleteData('logintokens', 'value', $enct);
cookies::removeCookie('SNID');
return true;
}
return false;
}
public static function getData($type, $id = 0) {
if ($id == 0)
$id = self::getID();
if ($type == self::ID) {
return $id;
}
elseif ($type == self::USERNAME) {
return DB::getData('accounts', 'Username', 'id', $id);
}
elseif ($type == self::EMAIL) {
return DB::getData('accounts', 'Email', 'id', $id);
}
elseif ($type == self::AVATAR) {
$a = DB::getData('accounts', 'Profileimg', 'id', $id);
if ($a == NULL)
return 'images/default_avatar.jpg';
else
return $a;
}
}
public static function getUserForumPosts($userid) {
$data = DB::getData('forum_posts', 'id', 'user_id', $userid);
if ($data == NULL)
return 0;
if (!isset($data[0]['id']))
return (count(array($data)));
return count($data);
}
public static function getFollowers($userid) {
$a = array();
$data = DB::getData('followers', 'follower_id', 'user_id', $userid, 'blocked', '0');
if ($data == NULL) return array();
if (!is_array($data)) {
array_push($a, $data);
return $a;
} else {
return $data;
}
return NULL;
}
public static function getFollowing($userid) {
$a = array();
$data = DB::getData('followers', 'user_id', 'follower_id', $userid, 'blocked', '0');
if ($data == NULL) return array();
if (!is_array($data)) {
array_push($a, $data);
return $a;
} else {
return $data;
}
return NULL;
}
public static function followUser($userid) {
$following = self::isFollowing($userid);
$selfID = self::getID();
if ($following != self::FOLLOWING && $following != self::BLOCKED) {
DB::setData('followers', array('user_id'=>$userid, 'follower_id'=>$selfID, 'blocked'=>'0'), false);
} else {
DB::deleteData('followers', 'user_id', $userid, 'follower_id', $selfID);
}
return 0;
}
public static function blockUser($userid) {
$following = self::isFollowing($userid);
$selfID = self::getID();
if ($following != self::BLOCKED) {
if (DB::getData('followers', '', 'user_id', $userid, 'follower_id', $selfID) != NULL)
DB::updateData('followers', array('blocked'=>'1'), 'user_id', $userid, 'follower_id', $selfID);
else
DB::setData('followers', array('user_id'=>$userid, 'follower_id'=>$selfID, 'blocked'=>'1'), false);
} else {
DB::deleteData('followers', 'user_id', $userid, 'follower_id', $selfID);
}
}
public static function isFollowing($userid) {
$selfID = self::getID();
$userfollowed = DB::getData('followers', '', 'user_id', $userid, 'follower_id', $selfID);
if ($userfollowed != NULL)
if ($userfollowed['blocked'] == 0)
return self::FOLLOWING;
else
return self::BLOCKED;
return self::NOTFOLLOWING;
}
public static function getIDFromType($type, $value) {
if ($type == self::USERNAME)
return DB::getData('accounts', 'id', 'Username', $value);
elseif ($type == self::EMAIL)
return DB::getData('accounts', 'id', 'Email', $value);
return NULL;
}
public static function setVerified($id = 0) {
if ($id == 0)
$id = self::getID();
DB::updateData('accounts', array('Verified'=>'1'), 'id', $id);
}
public static function createToken() {
try {
$cstrong = true;
$token = bin2hex(openssl_random_pseudo_bytes(64, $cstrong));
return $token;
} catch(Exception $e) {
return null;
}
}
public static function createLoginCookies($userid) {
try {
$token = self::createToken();
$encryptedToken = self::encryptedToken($token);
cookies::setCookie('SNID', $token, cookies::TIME_HOUR);
if (DB::getData('logintokens', 'id', 'user_id', $userid) != NULL) {
DB::updateData('logintokens', array('value'=>$encryptedToken), 'user_id', $userid);
} else {
DB::setData('logintokens', array('value'=>$encryptedToken, 'user_id'=>$userid));
}
return true;
} catch (Exception $e) {
return false;
}
}
private function getID() {
$cookie = cookies::getCookie('SNID');
if ($cookie != NULL) {
$enct = self::encryptedToken($cookie);
return DB::getData('logintokens', 'user_id', 'value', $enct);
}
return 0;
}
private function encryptedToken($token) {
try {
$enc = sha1($token);
return $enc;
} catch(Exception $e) {
return null;
}
}
public static function getUserCount() {
$data = DB::query('SELECT COUNT(*) FROM accounts');
if (!isset($data[0][0]))
return array($data)[0][0];
return $data[0][0];
}
public static function getLatestUser() {
$data = DB::query('SELECT username FROM accounts ORDER BY id DESC LIMIT 1');
if (isset($data[0]['username']))
return $data[0]['username'];
return NULL;
}
}
<?php
class DB {
private static function connect() {
try {
$pdo = new PDO('mysql:host=127.0.0.1;dbname=eventhorizon;charset=utf8', 'root', '');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo;
} catch (PDOException $e) {
return NULL;
}
}
public static function query($query, $params = array()) {
$pdo = self::connect();
if ($pdo != NULL) {
$statement = $pdo->prepare($query);
$statement->execute($params);
if (explode(' ', $query)[0] == 'SELECT') {
$data = $statement->fetchAll();
return $data;
}
}
return NULL;
}
/**
parameters:
* $table = NAME OF TABLE
* $value = VALUE TO BE RETURNED FROM DATABASE
* $identifier = IDENTIFIER TO LOOK FOR
* $identifiervalue = VALUE OF IDENTIFIER TO LOOK FOR
**/
public static function getData($table, $value) {
$identifiers = array();
$v = '*';
if ($value != '') $v = $value;
$q = 'SELECT ' . $v . ' FROM ' . $table;
if (func_num_args() > 2) {
$q = $q . ' WHERE ';
for ($i = 2; $i < func_num_args(); $i+=2) {
if ($i == 2) {
$q = $q . func_get_arg($i) . '=:' . func_get_arg($i);
} else {
$q = $q . ' AND ' . func_get_arg($i) . '=:' . func_get_arg($i);
}
$identifiers[':' . func_get_arg($i)] = func_get_arg($i+1);
}
}
$query = self::query($q, $identifiers);
if (!count($query))
return NULL;
if (count($query) == 1) {
if ($v == '*')
return $query[0];
else
return $query[0][$v];
} else {
return $query;
}
}
public static function updateData($table, $data, $identifier, $identifiervalue) {
if (count($data) < 1) return false;
$q = 'UPDATE ' . $table . ' SET ';
$identifiers = array();
foreach ($data as $key => $value) {
if (count($data) <= 1)
$q = $q . $key . '=:' . $key;
else
if ($data[$key] == $value && end($data) == $value)
$q = $q . $key . '=:' . $key;
else
$q = $q . $key . '=:' . $key . ', ';
$identifiers[':'.$key] = $value;
}
$q = $q . ' WHERE ';
for ($i = 2; $i < func_num_args(); $i+=2) {
if ($i == 2) {
$q = $q . func_get_arg($i) . '=:' . func_get_arg($i);
} else {
$q = $q . ' AND ' . func_get_arg($i) . '=:' . func_get_arg($i);
}
$identifiers[':' . func_get_arg($i)] = func_get_arg($i+1);
}
self::query($q, $identifiers);
return true;
}
public static function setData($table, $data, $primarykey = true) {
$q = '';
if ($primarykey)
$q = 'INSERT INTO ' . $table . ' VALUES ' . '(\'\', ';
else
$q = 'INSERT INTO ' . $table . ' VALUES ' . '(';
$a = array();
$num = 0;
foreach ($data as $key => $value) {
if (count($data) <= 1)
$q = $q . ':' . $key . ')';
else
if (count($data)-1 == $num)
$q = $q . ' :' . $key . ')';
else
$q = $q . ':' . $key . ', ';
$a[$key] = $value;
$num++;
}
echo $q;
self::query($q, $a);
}
public static function deleteData($table, $identifier, $identifiervalue) {
$identifiers = array();
$q = 'DELETE FROM ' . $table . ' WHERE ';
for ($i = 1; $i < func_num_args(); $i+=2) {
if ($i == 1) {
$q = $q . func_get_arg($i) . '=:' . func_get_arg($i);
} else {
$q = $q . ' AND ' . func_get_arg($i) . '=:' . func_get_arg($i);
}
$identifiers[':' . func_get_arg($i)] = func_get_arg($i+1);
}
self::query($q, $identifiers);
}
public static function createLoginTokensTable() {
try {
self::query('CREATE TABLE logintokens (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
value VARCHAR(255) NOT NULL,
user_id INT(6) NOT NULL
)');
return true;
} catch (Exception $e) {
return false;
}
}
public static function createUserTable() {
try {
self::query('CREATE TABLE accounts (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
RegistrationDate TIMESTAMP NOT NULL,
Username VARCHAR(32) NOT NULL,
Password VARCHAR(60) NOT NULL,
Email TEXT NOT NULL,
Role VARCHAR(32) NOT NULL,
BirthDate DATE NOT NULL,
Verified TINYINT(1) NOT NULL,
ProfileImg VARCHAR(255)
)');
return true;
} catch (Exception $e) {
return false;
}
}
public static function createFollowerTable() {
try {
self::query(
'CREATE TABLE followers (
user_id INT(6) NOT NULL,
follower_id INT(6) NOT NULL,
blocked INT(1) NOT NULL
)');
return true;
} catch (Exception $e) {
return false;
}
}
public static function createPostTable() {
try {
self::query('CREATE TABLE posts (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
PostDate TIMESTAMP NOT NULL,
post TEXT(300) NOT NULL,
user_id INT(6) NOT NULL,
homepage INT(6) NOT NULL
)');
return true;
} catch (Exception $e) {
return false;
}
}
public static function createForumCategories() {
try {
self::query('CREATE TABLE forum_category (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL
)');
return true;
} catch (Exception $e) {
return false;
}
}
public static function createForumTopics() {
try {
self::query('CREATE TABLE forum_topics (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
categoryID INT(6) NOT NULL,
parent_id INT(10) NOT NULL,
name VARCHAR(255) NOT NULL,
description VARCHAR(255),
type INT(1) NOT NULL
)');
return true;
} catch (Exception $e) {
return false;
}
}
public static function createForumPosts() {
try {
self::query('CREATE TABLE forum_posts (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id INT(6) NOT NULL,
topic_id INT(10) NOT NULL,
creation_date TIMESTAMP NOT NULL,
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
message TEXT NOT NULL,
homepage INT(1) NOT NULL
)');
} catch (Exception $e) {
return false;
}
}
public static function createForumComments() {
try {
self::query('CREATE TABLE forum_comments (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_id INT(6) NOT NULL,
post_id INT(10) NOT NULL,
creation_date TIMESTAMP NOT NULL,
message TEXT NOT NULL,
reply INT(255) NOT NULL
)');
} catch (Exception $e) {
return false;
}
}
}
/*
comments
id
user_id
post_id
creation_date
message
*/
<?php
require_once 'libraries/DB.php';
class Forum {
public const TOPICTYPE_POSTS = 0;
public const TOPICTYPE_LINK = 1;
public const HOMEPAGE_IDLE = 0;
public const HOMEPAGE_ACTIVE = 1;
public static function getCategoryIDFromName($name) {
return DB::getData('forum_category', 'id', 'name', $name);
}
public static function getCategories() {
$data = DB::getData('forum_category', '');
if ($data == NULL) return NULL;
if (!isset($data[0]['name']))
return array($data);
return $data;
}
public static function getCategory($name) {
$data = DB::getData('forum_category', '', 'name', $name);
if ($data == NULL)
return NULL;
return $data;
}
public static function createCategory($name) {
DB::setData('forum_category', array('name'=>$name));
}
public static function getAllTopics() {
$data = DB::getData('forum_topics', '', 'type', self::TOPICTYPE_POSTS);
if (!isset($data[0]['name']))
return array($data);
return $data;
}
public static function getAllTopicsInCategory($categoryID) {
$data = DB::getData('forum_topics', '', 'categoryID', $categoryID, 'type', self::TOPICTYPE_POSTS);
if (!isset($data[0]['name']))
return array($data);
return $data;
}
public static function getTopicsInCategory($categoryID, $parent = 0) {
$data = DB::getData('forum_topics', '', 'categoryID', $categoryID, 'parent_id', $parent, 'type', self::TOPICTYPE_POSTS);
if (!isset($data[0]['name']))
return array($data);
return $data;
}
public static function getCategoryFromTopic($TopicID) {
return DB::getData('forum_topics', 'categoryID', 'id', $TopicID);
}
public static function getTopicIDFromName($name) {
$data = DB::getData('forum_topics', 'id', 'name', $name);
if ($data == NULL) return NULL;
return $data;
}
public static function getCategoryNameFromID($id) {
return DB::getData('forum_category', 'name', 'id', $id);
}
public static function getTopicNameFromID($id) {
return DB::getData('forum_topics', 'name', 'id', $id);
}
public static function createTopic($categoryID, $name, $description, $parent = 0, $type = 0) {
if ($type != self::TOPICTYPE_POSTS)
$type = self::TOPICTYPE_LINK;
DB::setData('forum_topics', array('categoryID'=>$categoryID, 'parent_id'=>$parent,'name'=>$name, 'description'=>$description, 'type'=>$type));
}
public static function getTopicParentFromName($topicName) {
return DB::getData('forum_topics', 'parent_id', 'name', $topicName);
}
public static function getTopicParentFromID($topicID) {
return DB::getData('forum_topics', 'parent_id', 'id', $topicID);
}
public static function getAllParents() {
$parents = array();
$allTopics = self::getAllTopics();
if ($allTopics == NULL) return NULL;
foreach ($allTopics as $t) {
$exists = false;
foreach ($parents as $p) {
if ($p == $t['parent_id'] || $t['parent_id'] == 0)
$exists = true;
}
if (!$exists)
array_push($parents, $t['parent_id']);
}
return $parents;
}
public static function createPost($userid, $topicid, $creation_date, $title, $desc, $message, $homepage = 0) {
DB::setData('forum_posts', array('user_id'=>$userid, 'topic_id'=>$topicid, 'creation_date'=>$creation_date, 'title'=>$title, 'description'=>$desc, 'message'=>$message, 'homepage'=>$homepage));
}
public static function getPosts($topicid) {
$data = DB::getData('forum_posts', '', 'topic_id', $topicid);
if (!isset($data[0]['message']))
return array($data);
return $data;
}
public static function getPost($postid) {
return DB::getData('forum_posts', '', 'id', $postid);
}
public static function breadCrumbs($topic = '', $thread = false) {
//return self::getCategoryFromTopic($topic);
$topicID = self::getTopicIDFromName($topic);
$categoryID = self::getCategoryFromTopic($topicID);
$categoryName = self::getCategoryNameFromID($categoryID);
$bread = array();
$parent = self::getTopicParentFromID($topicID);
do {if ($parent == 0) continue;
$name = self::getTopicNameFromID($parent);
$link = 'forum.php?topic='.$name;
array_unshift($bread, array('link'=>$link, 'name'=>$name));
//array_push($bread, self::getTopicNameFromID($parent));
$parent = self::getTopicParentFromID($parent);
} while ($parent != 0);
if ($topic != '') {
$name = $categoryName;
$link = 'forum.php?category='.$categoryName;
array_unshift($bread, array('link'=>$link, 'name'=>$name));
if ($thread) {
$name = $topic;
$link = 'forum.php?topic='.$topic;
array_push($bread, array('link'=>$link, 'name'=>$name));
}
}
array_unshift($bread, array('link'=>'forum.php', 'name'=>'Forum'));
$s = '';
//return $bread;
for ($i = 0; $i < count($bread); $i++) {
if (count($bread)-1 == $i)
$s = $s . '<a href="'.$bread[$i]['link'].'">' . $bread[$i]['name'] . '</a>';
else
$s = $s . '<a href="'.$bread[$i]['link'].'">' . $bread[$i]['name'] . '</a>' . ' > ';
}
return $s;
}
public static function getTopicChildren($topicID) {
$data = DB::getData('forum_topics', '', 'parent_id', $topicID);
if (!isset($data[0]['name']))
return array($data);
return $data;
}
public static function getAllChildrenTopics($topicID) {
$children = array();
$t = DB::getData('forum_topics', '', 'id', $topicID);
if ($t['name'] == NULL)
return NULL;
array_push($children, $t);
$currentChecked = 0;
do {
$topics = self::getTopicChildren($children[$currentChecked]['id']);
foreach ($topics as $to) {
array_push($children, $to);
}
$currentChecked = $currentChecked + 1;
} while ($children[$currentChecked]['parent_id'] != 0 && $currentChecked < count($children));
for ($i = 0; $i <= count($children); $i++) {
if (!isset($children[$i]['name']))
unset($children[$i]);
}
return $children;
}
public static function getLatestPost($topicID) {
$childrenTopics = self::getAllChildrenTopics($topicID);
$latestpost = NULL;
foreach ($childrenTopics as $topics) {
$t = DB::query('SELECT * FROM forum_posts WHERE topic_id = :topic_id ORDER BY creation_date DESC LIMIT 1', array('topic_id'=>$topics['id']));
if ($t == NULL) continue;
//if (!isset($t['creation_date'])) continue;
if ($latestpost != NULL && isset($t['creation_date'])) {
$lpdt = new DateTime($latestpost['creation_date']);
$tdt = new DateTime($t['creation_date']);
if ($tdt > $lpdt) {
$latestpost = $t;
}
} else {
$latestpost = $t;
}
}
return $latestpost;
}
public static function getForumLatestPost($limit = 5) {
$data = DB::query('SELECT * FROM forum_posts ORDER BY creation_date DESC LIMIT '.$limit, array());
if (!isset($data[0]['creation_date']))
return array($data);
return $data;
}
public static function getPostAmount($topicID) {
$childrenTopics = self::getAllChildrenTopics($topicID);
$amount = 0;
foreach ($childrenTopics as $topics) {
$data = DB::query('SELECT COUNT(*) FROM forum_posts WHERE topic_id = :topic_id', array('topic_id'=>$topics['id']));
if ($data != NULL)
$amount = $amount + $data[0][0];
}
return $amount;
}
public static function getCommentAmount($topicID) {
$childrenTopics = self::getAllChildrenTopics($topicID);
$amount = 0;
foreach ($childrenTopics as $topics) {
$query = DB::query('SELECT COUNT(*) FROM forum_comments
INNER JOIN forum_posts ON forum_posts.id = forum_comments.post_id
WHERE forum_posts.topic_id = :topicID', array('topicID'=>$topics['id']));
$amount = $amount + $query[0][0];
//return $query;
}
return $amount;
}
public static function getTopicEcho($topic) {
$latest = self::getLatestPost($topic['id']);
$latestTitle = $latest[0]['title'];
$latestDescription = $latest[0]['description'];
$latestDescription = strlen($latestDescription) > 50 ? substr($latestDescription,0,50)."..." : $latestDescription;
if ($latestDescription == '')
$latestDescription = 'No description has been set.';
if ($latestTitle == '')
$latestDescription = '';
$postAmount = self::getPostAmount($topic['id']);
$commentAmount = self::getCommentAmount($topic['id']);
$avatar = Account::getData(Account::AVATAR, $latest[0]['user_id']);
$username = Account::getData(Account::USERNAME, $latest[0]['user_id']);
$string = '<div id="topic">';
$string = $string .'<div id="name"><div id="border"><div id="info"><a href="forum.php?topic='.$topic['name'].'">'.$topic['name'].'</a></div></div></div>';
$string = $string .'<div id="posts"><div id="border"><div id="info">Posts</div><div id="amount">'.$postAmount.'</div></div></div>';
$string = $string .'<div id="comments"><div id="border"><div id="info">Comments</div><div id="amount">'.$commentAmount.'</div></div></div>';
if ($latest[0]['user_id'] != 0) {
$string = $string .'<div id="latest">
<div id="border">
<div id="avatarimage"><a href="profile.php?profile='.$username.'"><img src="'.$avatar.'" /></a></div>
<div id="latestinfo">
<div id="info"><a href="Thread.php?post='.$latest[0]['id'].'">'.$latestTitle.'</a></div>
<div id="description">'.$latestDescription.'</div>
</div>
</div>
</div>';
}
$string = $string .'</div>';
return $string;
}
public static function getPostComments($post_id) {
$data = DB::getData('forum_comments', '', 'post_id', $post_id, 'reply', '0');
if (!isset($data[0]['message']))
return array($data);
return $data;
}
public static function createComment($user_id, $post_id, $creation_date, $message, $reply = 0) {
DB::setData('forum_comments', array('user_id'=>$user_id, 'post_id'=>$post_id, 'creation_date'=>$creation_date, 'message'=>$message, 'reply'=>$reply));
}
public static function totalTopics() {
return DB::query('SELECT COUNT(*) FROM forum_topics', array())[0][0];
}
public static function totalPosts() {
return DB::query('SELECT COUNT(*) FROM forum_posts', array())[0][0];
}
public static function totalComments() {
return DB::query('SELECT COUNT(*) FROM forum_comments', array())[0][0];
}
public static function totalPostComments($post_id) {
return DB::query('SELECT COUNT(*) FROM forum_comments WHERE post_id=:post_id', array('post_id'=>$post_id))[0][0];
}
public static function setHomepage($id) {
try {
$data = self::getHomepage($id);
if ($data == NULL) return false;
$homepage = self::HOMEPAGE_IDLE;
if ($data == self::HOMEPAGE_IDLE)
$homepage = self::HOMEPAGE_ACTIVE;
DB::updateData('forum_posts', array('homepage'=>$homepage), 'id', $id);
return true;
} catch(Exception $e) {
return false;
}
}
public static function getHomepage($id) {
$data = DB::getData('forum_posts', 'homepage', 'id', $id);
if ($data == NULL) return NULL;
return $data;
}
public static function getHomepagePosts() {
$data = DB::getData('forum_posts', '', 'homepage', self::HOMEPAGE_ACTIVE);
if (!isset($data[0]['homepage']))
return array($data);
return $data;
}
}
/**
categories
id
parent
name
topic
id
categoryid
name
description
type - posts,link
posts
id
user_id
topic_id
creation_date
title
description
message
comments
id
user_id
post_id
creation_date
message
**/
<?php
class Image {
public static function uploadImage($formname, $query, $params) {
$image = base64_encode(file_get_contents($_FILES[$formname]['tmp_name']));
$options = array('http'=>array('method'=>"POST", 'header'=> "Authorization: Bearer 9f433c4b012416034c502f5f2c14305df499b6f1\n"."Content-Type: application/x-www-form-urlencoded", 'content'=>$image));
$context = stream_context_create($options);
$imgurURL = 'https://api.imgur.com/3/image';
if ($_FILES[$formname]['size'] > 10240000) {
die('Image too big, must be 10MB or less!');
}
$response = file_get_contents($imgurURL, false, $context);
$response = json_decode($response);
$preparams = array($formname=>$response->data->link);
$params = $preparams + $params;
DB::query($query, $params);
}
}
<?php
class cookies {
public const TIME_HOUR = 3600;
public const TIME_DAY = cookies::TIME_HOUR * 24;
public const TIME_MONTH = cookies::TIME_DAY * 30;
public const TIME_YEAR = cookies::TIME_MONTH * 12;
public static function setCookie($name, $value, $time) {
try {
setcookie($name, $value, time() + $time, "/");
return true;
} catch (Exception $e) {
return false;
}
}
public static function getCookie($name) {
if (self::isValid($name))
return $_COOKIE[$name];
return NULL;
}
public static function removeCookie($name) {
if (self::isValid($name)) {
self::setCookie($name, "", time() - self::TIME_HOUR);
return true;
}
return false;
}
public static function isCookieEnabled() {
self::setCookie("test_cookie", "test", self::TIME_HOUR);
if(count($_COOKIE) > 0) {
return true;
}
return false;
}
public static function isValid($name) {
if (isset($_COOKIE[$name]))
return true;
return false;
}
}