it's 3:15 am, why am i still down code

*doing
This commit is contained in:
flash 2016-03-28 03:18:59 +02:00
parent c29f352bdd
commit 3b2df3b96c
15 changed files with 502 additions and 5 deletions

112
libraries/Comment.php Normal file
View file

@ -0,0 +1,112 @@
<?php
/**
* Holds the comment object.
*
* @package Sakura
*/
namespace Sakura;
/**
* Comment object.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class Comment
{
public $id = 0;
public $category = "";
public $time = 0;
public $user = 0;
public $reply = 0;
public $text = "";
public $upvotes = 0;
public $downvotes = 0;
private $replyCache = [];
public function __construct($id = 0)
{
// Get comment data from the database
$data = DB::table('comments')
->where('comment_id', $id)
->get();
// Check if anything was returned and assign data
if ($data) {
$data = $data[0];
$this->id = $data->comment_id;
$this->category = $data->comment_category;
$this->time = $data->comment_timestamp;
$this->user = $data->comment_poster;
$this->reply = $data->comment_reply_to;
$this->text = $data->comment_text;
$this->getVotes();
}
}
public function save()
{
// Create submission data, insert and update take the same format
$data = [
'comment_category' => $this->category,
'comment_timestamp' => $this->time,
'comment_poster' => $this->user,
'comment_reply_to' => $this->reply,
'comment_text' => $this->text,
];
// Update if id isn't 0
if ($this->id) {
DB::table('comments')
->where('comment_id', $this->id)
->update($data);
} else {
$this->id = DB::table('comments')
->insertGetId($data);
}
}
private function getVotes()
{
$votes = DB::table('comment_votes')
->where('vote_comment', $this->id)
->get();
foreach ($votes as $vote) {
if ($vote->vote_state) {
$upvotes += 1;
} else {
$downvotes += 1;
}
}
}
public function replies()
{
if (!$this->replyCache) {
$commentIds = DB::table('comments')
->where('comment_reply_to', $this->id)
->get(['comment_id']);
$commentIds = array_column($comments, 'comment_id');
foreach ($commentIds as $comment) {
$this->replyCache[$comment] = new Comment($comment);
}
}
return $this->replyCache;
}
public function userData()
{
return User::construct($this->user);
}
public function vote()
{
// can't be fucked to implement this right now
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* Holds the account section controller.
*
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
/**
* Account settings.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class AccountController extends Controller
{
public function email()
{
return $this->go('account.email');
}
public function username()
{
return $this->go('account.username');
}
public function title()
{
return $this->go('account.usertitle');
}
public function password()
{
return $this->go('account.password');
}
public function ranks()
{
return $this->go('account.ranks');
}
}

View file

@ -0,0 +1,27 @@
<?php
/**
* Holds the advanced section controller.
*
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
/**
* Advanced settings.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class AdvancedController extends Controller
{
public function sessions()
{
return $this->go('advanced.sessions');
}
public function deactivate()
{
return $this->go('advanced.deactivate');
}
}

View file

@ -0,0 +1,42 @@
<?php
/**
* Holds the appearance section controller.
*
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
/**
* Appearance settings.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class AppearanceController extends Controller
{
public function avatar()
{
return $this->go('appearance.avatar');
}
public function background()
{
return $this->go('appearance.background');
}
public function header()
{
return $this->go('appearance.header');
}
public function userpage()
{
return $this->go('appearance.userpage');
}
public function signature()
{
return $this->go('appearance.signature');
}
}

View file

@ -0,0 +1,36 @@
<?php
/**
* Holds the base settings controller.
*
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
use Sakura\Controllers\Controller as BaseController;
use Sakura\Urls;
/**
* Base controller (which other controllers should extend on).
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class Controller extends BaseController
{
private $urls;
public function __construct()
{
$this->urls = new Urls();
}
public function go($location)
{
$location = explode('.', $location);
$url = $this->urls->format('SETTING_MODE', $location, null, false);
return header("Location: {$url}");
}
}

View file

@ -0,0 +1,27 @@
<?php
/**
* Holds the friends section controller.
*
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
/**
* Friends settings.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class FriendsController extends Controller
{
public function listing()
{
return $this->go('friends.listing');
}
public function requests()
{
return $this->go('friends.requests');
}
}

View file

@ -0,0 +1,32 @@
<?php
/**
* Holds the general settings section controller.
*
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
/**
* General settings.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class GeneralController extends Controller
{
public function home()
{
return $this->go('general.home');
}
public function profile()
{
return $this->go('general.profile');
}
public function options()
{
return $this->go('general.options');
}
}

View file

@ -0,0 +1,27 @@
<?php
/**
* Holds the groups section controller.
*
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
/**
* Group settings.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class GroupsController extends Controller
{
public function listing()
{
return "";
}
public function invites()
{
return "";
}
}

View file

@ -0,0 +1,22 @@
<?php
/**
* Holds the notifications section controller.
*
* @package Sakura
*/
namespace Sakura\Controllers\Settings;
/**
* Notification settings.
*
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class NotificationsController extends Controller
{
public function history()
{
return $this->go('notifications.history');
}
}

View file

@ -0,0 +1 @@
donderdag

1
libraries/News/Post.php Normal file
View file

@ -0,0 +1 @@
vrijdag

View file

@ -73,9 +73,23 @@ class Notification
}
}
public function delete()
{
DB::table('comments')
->where('comment_id', $this->id)
->delete();
$this->id = 0;
}
public function toggleRead()
{
// Set read to the negative value of itself
$this->read = !$this->read;
}
public function userData()
{
return User::construct($this->user);
}
}

View file

@ -68,7 +68,19 @@ class Router
// Check if the method exists
if (in_array($name = strtoupper($name), self::$methods)) {
$path = isset($args[2]) && $args !== null ? [$args[0], $args[2]] : $args[0];
$handler = is_callable($args[1]) || is_array($args[1]) ? $args[1] : explode('@', ('Sakura\Controllers\\' . $args[1]));
$handler = is_callable($args[1]) || is_array($args[1])
? $args[1]
: explode(
'@',
(
'Sakura\\Controllers\\'
. str_replace(
'.',
'\\',
$args[1]
)
)
);
$filter = isset($args[3]) ? $args[3] : [];
self::$router->addRoute($name, $path, $handler, $filter);

View file

@ -301,7 +301,7 @@ class Urls
*
* @return null|string The formatted URL.
*/
public function format($lid, $args = [], $rewrite = null)
public function format($lid, $args = [], $rewrite = null, $b = true)
{
// Check if the requested url exists
@ -309,11 +309,24 @@ class Urls
return null;
}
// Check if mod_rewrite is enabled
$rewrite = 0; // Pretty much disabled forever because of the router -- ($rewrite === null ? Config::get('url_rewrite') : $rewrite) ? 1 : 0;
if ($b && ($lid === 'SETTING_CAT' || $lid === 'SETTING_MODE')) {
if (in_array('messages', $args)) {
return null;
}
if ($lid === 'SETTING_CAT') {
return Router::route("settings.{$args[0]}");
}
if ($lid === 'SETTING_MODE') {
$a = implode('.', $args);
$a = str_replace("usertitle", "title", $a);
return Router::route("settings.{$a}");
}
}
// Format urls
$formatted = vsprintf($this->urls[$lid][$rewrite], $args);
$formatted = vsprintf($this->urls[$lid][0], $args);
// Return the formatted url
return $formatted;

View file

@ -122,6 +122,95 @@ Router::group(['prefix' => 'helper'], function () {
});
// Settings
Router::group(['prefix' => 'settings', 'before' => 'loginCheck'], function () {
Router::get('/', function () {
$route = Router::route('settings.general.home');
return header("Location: {$route}");
});
// General section
Router::group(['prefix' => 'general'], function () {
Router::get('/', function () {
$route = Router::route('settings.general.home');
return header("Location: {$route}");
});
Router::get('/home', 'Settings.GeneralController@home', 'settings.general.home');
Router::get('/profile', 'Settings.GeneralController@profile', 'settings.general.profile');
Router::get('/options', 'Settings.GeneralController@options', 'settings.general.options');
});
// Friends section
Router::group(['prefix' => 'friends'], function () {
Router::get('/', function () {
$route = Router::route('settings.friends.listing');
return header("Location: {$route}");
});
Router::get('/listing', 'Settings.FriendsController@listing', 'settings.friends.listing');
Router::get('/requests', 'Settings.FriendsController@requests', 'settings.friends.requests');
});
// Groups section
Router::group(['prefix' => 'groups'], function () {
Router::get('/', function () {
$route = Router::route('settings.groups.listing');
return header("Location: {$route}");
});
Router::get('/listing', 'Settings.GroupsController@listing', 'settings.groups.listing');
Router::get('/invites', 'Settings.GroupsController@invites', 'settings.groups.invites');
});
// Notifications section
Router::group(['prefix' => 'notifications'], function () {
Router::get('/', function () {
$route = Router::route('settings.notifications.history');
return header("Location: {$route}");
});
Router::get('/history', 'Settings.NotificationsController@history', 'settings.notifications.history');
});
// Appearance section
Router::group(['prefix' => 'appearance'], function () {
Router::get('/', function () {
$route = Router::route('settings.appearance.avatar');
return header("Location: {$route}");
});
Router::get('/avatar', 'Settings.AppearanceController@avatar', 'settings.appearance.avatar');
Router::get('/background', 'Settings.AppearanceController@background', 'settings.appearance.background');
Router::get('/header', 'Settings.AppearanceController@header', 'settings.appearance.header');
Router::get('/userpage', 'Settings.AppearanceController@userpage', 'settings.appearance.userpage');
Router::get('/signature', 'Settings.AppearanceController@signature', 'settings.appearance.signature');
});
// Account section
Router::group(['prefix' => 'account'], function () {
Router::get('/', function () {
$route = Router::route('settings.account.email');
return header("Location: {$route}");
});
Router::get('/email', 'Settings.AccountController@avatar', 'settings.account.email');
Router::get('/username', 'Settings.AccountController@username', 'settings.account.username');
Router::get('/title', 'Settings.AccountController@title', 'settings.account.title');
Router::get('/password', 'Settings.AccountController@password', 'settings.account.password');
Router::get('/ranks', 'Settings.AccountController@ranks', 'settings.account.ranks');
});
// Advanced section
Router::group(['prefix' => 'advanced'], function () {
Router::get('/', function () {
$route = Router::route('settings.advanced.sessions');
return header("Location: {$route}");
});
Router::get('/sessions', 'Settings.AdvancedController@sessions', 'settings.advanced.sessions');
Router::get('/deactivate', 'Settings.AdvancedController@deactivate', 'settings.advanced.deactivate');
});
});
/*
* General
* - Home (make this not worthless while you're at it)