r20150130
This commit is contained in:
parent
7d23f1b6c7
commit
232ddc6114
9 changed files with 151 additions and 12 deletions
|
@ -7,6 +7,7 @@
|
||||||
"phpmailer/phpmailer": "*",
|
"phpmailer/phpmailer": "*",
|
||||||
"paypal/rest-api-sdk-php": "*",
|
"paypal/rest-api-sdk-php": "*",
|
||||||
"jbbcode/jbbcode": "*",
|
"jbbcode/jbbcode": "*",
|
||||||
"corneltek/cliframework": "*"
|
"corneltek/cliframework": "*",
|
||||||
|
"phroute/phroute": "^2.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
libraries/Controllers/Meta.php
Normal file
16
libraries/Controllers/Meta.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Meta controllers
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Sakura\Controllers;
|
||||||
|
|
||||||
|
use Sakura\Template;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Meta
|
||||||
|
* @package Sakura
|
||||||
|
*/
|
||||||
|
class Meta
|
||||||
|
{
|
||||||
|
}
|
|
@ -1,14 +1,85 @@
|
||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* Router class
|
* Router Wrapper
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Sakura;
|
namespace Sakura;
|
||||||
|
|
||||||
|
use Phroute\Phroute\RouteCollector;
|
||||||
|
use Phroute\Phroute\Dispatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Router
|
* Class Router
|
||||||
* @package Sakura
|
* @package Sakura
|
||||||
*/
|
*/
|
||||||
class Router
|
class Router
|
||||||
{
|
{
|
||||||
|
// Router container
|
||||||
|
protected static $router = null;
|
||||||
|
|
||||||
|
// Base path
|
||||||
|
protected static $basePath = null;
|
||||||
|
|
||||||
|
// Dispatcher
|
||||||
|
protected static $dispatcher = null;
|
||||||
|
|
||||||
|
// Request methods
|
||||||
|
protected static $methods = [
|
||||||
|
'GET',
|
||||||
|
'POST',
|
||||||
|
'PUT',
|
||||||
|
'PATCH',
|
||||||
|
'DELETE',
|
||||||
|
'HEAD',
|
||||||
|
'ANY'
|
||||||
|
];
|
||||||
|
|
||||||
|
// Add a handler
|
||||||
|
public static function __callStatic($name, $args)
|
||||||
|
{
|
||||||
|
// 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];
|
||||||
|
$filter = isset($args[3]) ? $args[3] : [];
|
||||||
|
|
||||||
|
self::$router->addRoute($name, $path, $args[1], $filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialisation function
|
||||||
|
public static function init($basePath = '/')
|
||||||
|
{
|
||||||
|
// Set base path
|
||||||
|
self::setBasePath($basePath);
|
||||||
|
|
||||||
|
// Create router
|
||||||
|
self::$router = new RouteCollector;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set base path
|
||||||
|
public static function setBasePath($basePath)
|
||||||
|
{
|
||||||
|
self::$basePath = $basePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse the url
|
||||||
|
private static function parseUrl($url)
|
||||||
|
{
|
||||||
|
return parse_url(str_replace(self::$basePath, '', $url), PHP_URL_PATH);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle requests
|
||||||
|
public static function handle($method, $url)
|
||||||
|
{
|
||||||
|
// Check if the dispatcher is defined
|
||||||
|
if (self::$dispatcher === null) {
|
||||||
|
self::$dispatcher = new Dispatcher(self::$router->getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse url
|
||||||
|
$url = self::parseUrl($url);
|
||||||
|
|
||||||
|
// Handle the request
|
||||||
|
return self::$dispatcher->dispatch($method, $url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,12 @@ var DynLoad = (function () {
|
||||||
}
|
}
|
||||||
// Add the hooks
|
// Add the hooks
|
||||||
DynLoad.init = function () {
|
DynLoad.init = function () {
|
||||||
|
if (this.active) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.active = true;
|
||||||
|
}
|
||||||
// Add an event listener to the document
|
// Add an event listener to the document
|
||||||
document.addEventListener("click", function (e) {
|
document.addEventListener("click", function (e) {
|
||||||
// Check if a href attribute is set
|
// Check if a href attribute is set
|
||||||
|
@ -21,7 +27,7 @@ var DynLoad = (function () {
|
||||||
var doc = (new DOMParser()).parseFromString(loader.response(), "text/html");
|
var doc = (new DOMParser()).parseFromString(loader.response(), "text/html");
|
||||||
history.pushState(null, null, e.target['href']);
|
history.pushState(null, null, e.target['href']);
|
||||||
document.head.innerHTML = doc.head.innerHTML;
|
document.head.innerHTML = doc.head.innerHTML;
|
||||||
document.getElementById("content").innerHTML = doc.getElementById("content").innerHTML;
|
document.getElementById("contentwrapper").innerHTML = doc.getElementById("contentwrapper").innerHTML;
|
||||||
var evt = document.createEvent('Event');
|
var evt = document.createEvent('Event');
|
||||||
evt.initEvent('load', false, false);
|
evt.initEvent('load', false, false);
|
||||||
window.dispatchEvent(evt);
|
window.dispatchEvent(evt);
|
||||||
|
@ -31,5 +37,7 @@ var DynLoad = (function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
// Is active
|
||||||
|
DynLoad.active = false;
|
||||||
return DynLoad;
|
return DynLoad;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -3,8 +3,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class DynLoad {
|
class DynLoad {
|
||||||
|
// Is active
|
||||||
|
public static active: boolean = false;
|
||||||
|
|
||||||
// Add the hooks
|
// Add the hooks
|
||||||
public static init(): void {
|
public static init(): void {
|
||||||
|
if (this.active) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
this.active = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Add an event listener to the document
|
// Add an event listener to the document
|
||||||
document.addEventListener("click", (e) => {
|
document.addEventListener("click", (e) => {
|
||||||
// Check if a href attribute is set
|
// Check if a href attribute is set
|
||||||
|
@ -23,7 +32,7 @@ class DynLoad {
|
||||||
var doc = (new DOMParser()).parseFromString(loader.response(), "text/html");
|
var doc = (new DOMParser()).parseFromString(loader.response(), "text/html");
|
||||||
history.pushState(null, null, e.target['href']);
|
history.pushState(null, null, e.target['href']);
|
||||||
document.head.innerHTML = doc.head.innerHTML;
|
document.head.innerHTML = doc.head.innerHTML;
|
||||||
document.getElementById("content").innerHTML = doc.getElementById("content").innerHTML;
|
document.getElementById("contentwrapper").innerHTML = doc.getElementById("contentwrapper").innerHTML;
|
||||||
var evt = document.createEvent('Event');
|
var evt = document.createEvent('Event');
|
||||||
evt.initEvent('load', false, false);
|
evt.initEvent('load', false, false);
|
||||||
window.dispatchEvent(evt);
|
window.dispatchEvent(evt);
|
||||||
|
|
19
public/router.php
Normal file
19
public/router.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Sakura Router
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Declare Namespace
|
||||||
|
namespace Sakura;
|
||||||
|
|
||||||
|
// Include components
|
||||||
|
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
||||||
|
|
||||||
|
if (!Config::local('dev', 'show_changelog') || !Config::local('dev', 'show_errors')) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
Router::setBasePath('/router.php');
|
||||||
|
|
||||||
|
// Handle requests
|
||||||
|
echo Router::handle($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
|
7
routes.php
Normal file
7
routes.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Router paths
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Define namespace
|
||||||
|
namespace Sakura;
|
10
sakura.php
10
sakura.php
|
@ -8,7 +8,7 @@
|
||||||
namespace Sakura;
|
namespace Sakura;
|
||||||
|
|
||||||
// Define Sakura version
|
// Define Sakura version
|
||||||
define('SAKURA_VERSION', '20160126');
|
define('SAKURA_VERSION', '20160130');
|
||||||
define('SAKURA_VLABEL', 'Amethyst');
|
define('SAKURA_VLABEL', 'Amethyst');
|
||||||
define('SAKURA_COLOUR', '#9966CC');
|
define('SAKURA_COLOUR', '#9966CC');
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ require_once ROOT . 'libraries/News.php';
|
||||||
require_once ROOT . 'libraries/Payments.php';
|
require_once ROOT . 'libraries/Payments.php';
|
||||||
require_once ROOT . 'libraries/Perms.php';
|
require_once ROOT . 'libraries/Perms.php';
|
||||||
require_once ROOT . 'libraries/Rank.php';
|
require_once ROOT . 'libraries/Rank.php';
|
||||||
|
require_once ROOT . 'libraries/Router.php';
|
||||||
require_once ROOT . 'libraries/Session.php';
|
require_once ROOT . 'libraries/Session.php';
|
||||||
require_once ROOT . 'libraries/Template.php';
|
require_once ROOT . 'libraries/Template.php';
|
||||||
require_once ROOT . 'libraries/Trick.php';
|
require_once ROOT . 'libraries/Trick.php';
|
||||||
|
@ -60,6 +61,7 @@ require_once ROOT . 'libraries/Users.php';
|
||||||
require_once ROOT . 'libraries/Utils.php';
|
require_once ROOT . 'libraries/Utils.php';
|
||||||
require_once ROOT . 'libraries/Whois.php';
|
require_once ROOT . 'libraries/Whois.php';
|
||||||
require_once ROOT . 'libraries/Console/Application.php';
|
require_once ROOT . 'libraries/Console/Application.php';
|
||||||
|
require_once ROOT . 'libraries/Controllers/Meta.php';
|
||||||
require_once ROOT . 'libraries/Forum/Forum.php';
|
require_once ROOT . 'libraries/Forum/Forum.php';
|
||||||
require_once ROOT . 'libraries/Forum/Post.php';
|
require_once ROOT . 'libraries/Forum/Post.php';
|
||||||
require_once ROOT . 'libraries/Forum/Thread.php';
|
require_once ROOT . 'libraries/Forum/Thread.php';
|
||||||
|
@ -116,6 +118,12 @@ if (Config::get('no_cron_service')) {
|
||||||
// Start output buffering
|
// Start output buffering
|
||||||
ob_start(Config::get('use_gzip') ? 'ob_gzhandler' : null);
|
ob_start(Config::get('use_gzip') ? 'ob_gzhandler' : null);
|
||||||
|
|
||||||
|
// Initialise the router
|
||||||
|
Router::init();
|
||||||
|
|
||||||
|
// Include routes file
|
||||||
|
include_once ROOT . 'routes.php';
|
||||||
|
|
||||||
// Auth check
|
// Auth check
|
||||||
$authCheck = Users::checkLogin();
|
$authCheck = Users::checkLogin();
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% set friends = profile.friends(2)|batch(12) %}
|
{% set friends = profile.friends(2)|batch(12) %}
|
||||||
|
|
||||||
{% set paginationPages = friends %}
|
{% set paginationPages = friends %}
|
||||||
{% set paginationUrl %}{{ urls.format('SETTING_MODE', ['friends', 'listing']) }}{% endset %}
|
{% set paginationUrl %}{{ urls.format('USER_FRIENDS', [profile.id]) }}{% endset %}
|
||||||
|
|
||||||
<div class="new-profile-mode-title">
|
<div class="new-profile-mode-title">
|
||||||
<h1 class="stylised">Friends</h1>
|
<h1 class="stylised">Friends</h1>
|
||||||
|
@ -16,9 +16,9 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
{% if friends|length > 1 %}
|
{% if friends|length > 1 %}
|
||||||
<div>
|
<div style="text-align: right;">
|
||||||
{% include 'elements/pagination.twig' %}
|
{% include 'elements/pagination.twig' %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
|
Reference in a new issue