From 866d7aa89f29b2a9f17704b4f6fd4341a6b3db94 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 3 Jul 2015 19:33:02 +0200 Subject: [PATCH] API shit --- _sakura/changelog.json | 26 +++++++++++- _sakura/components/Forum.php | 25 ++++++++--- _sakura/components/Main.php | 2 +- _sakura/sakura.php | 2 +- _sakura/templates/yuuno/main/support.tpl | 2 +- api/api.php | 53 +++++++++++++++++++++++- content/data/yuuno/css/yuuno.css | 28 +++++++++---- main/support.php | 2 +- 8 files changed, 120 insertions(+), 20 deletions(-) diff --git a/_sakura/changelog.json b/_sakura/changelog.json index 0466374..e4966dc 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -27,7 +27,9 @@ "20150628", "20150629", "20150630", - "20150701" + "20150701", + "20150702", + "20150703" ] @@ -1407,6 +1409,28 @@ "change": "Added basic API handler." } + ], + + "20150702": [ + + { + "type": "FIX", + "change": "Fixed a mistake in the stylesheet causing the support page to deform when resized." + }, + { + "type": "FIX", + "change": "Made the sitename config variable shown on the title of the suport page instead of just Flashii" + } + + ], + + "20150703": [ + + { + "type": "ADD", + "change": "Add basic example of the version 1 API framework." + } + ] } diff --git a/_sakura/components/Forum.php b/_sakura/components/Forum.php index 90a351e..35b5e94 100644 --- a/_sakura/components/Forum.php +++ b/_sakura/components/Forum.php @@ -16,9 +16,7 @@ class Forum { 'forum_category' => 0, 'forum_type' => 1, 'forum_posts' => 0, - 'forum_topics' => 0, - 'forum_last_post_id' => 0, - 'forum_last_poster_id' => 0 + 'forum_topics' => 0 ]; // Getting the forum list @@ -48,9 +46,14 @@ class Forum { // For link and reg. forum add it to the category $return[$forum['forum_category']]['forums'][$forum['forum_id']] = $forum; + // Get last post in forum + $lastPost = Database::fetch('posts', false, [ + 'forum_id' => [$forum['forum_id'], '='] + ], ['post_id', true]); + // Add last poster data and the details about the post as well $return[$forum['forum_category']]['forums'][$forum['forum_id']]['last_poster'] = [ - 'user' => ($_LAST_POSTER = Users::getUser($forum['forum_last_poster_id'])), + 'user' => ($_LAST_POSTER = Users::getUser($lastPost['poster_id'])), 'rank' => Users::getRank($_LAST_POSTER['rank_main']) ]; @@ -105,8 +108,13 @@ class Forum { // Get the userdata related to last posts foreach($forum['forums'] as $key => $sub) { + // Get last post in forum + $lastPost = Database::fetch('posts', false, [ + 'forum_id' => [$sub['forum_id'], '='] + ], ['post_id', true]); + $forum['forums'][$key]['last_poster'] = [ - 'user' => ($_LAST_POSTER = Users::getUser($sub['forum_last_poster_id'])), + 'user' => ($_LAST_POSTER = Users::getUser($lastPost['poster_id'])), 'rank' => Users::getRank($_LAST_POSTER['rank_main']) ]; @@ -120,8 +128,13 @@ class Forum { // Get the userdata related to first and last posts foreach($forum['topics'] as $key => $topic) { + // Get last post in forum + $firstPost = Database::fetch('posts', false, [ + 'topic_id' => [$topic['topic_id'], '='] + ]); + $forum['topics'][$key]['first_poster'] = [ - 'user' => ($_FIRST_POSTER = Users::getUser($topic['topic_first_poster_id'])), + 'user' => ($_FIRST_POSTER = Users::getUser($firstPost['topic_first_poster_id'])), 'rank' => Users::getRank($_FIRST_POSTER['rank_main']) ]; diff --git a/_sakura/components/Main.php b/_sakura/components/Main.php index 2e4e424..7c66198 100644 --- a/_sakura/components/Main.php +++ b/_sakura/components/Main.php @@ -584,7 +584,7 @@ class Main { } // Indent JSON - public static function jsonIndent($json) { + public static function jsonPretty($json) { // Defines $tab = ' '; diff --git a/_sakura/sakura.php b/_sakura/sakura.php index f41ef20..02be734 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20150701'); +define('SAKURA_VERSION', '20150703'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_STABLE', false); define('SAKURA_COLOUR', '#6C3082'); diff --git a/_sakura/templates/yuuno/main/support.tpl b/_sakura/templates/yuuno/main/support.tpl index 40446be..07656ec 100644 --- a/_sakura/templates/yuuno/main/support.tpl +++ b/_sakura/templates/yuuno/main/support.tpl @@ -6,7 +6,7 @@ {% endif %}
-
Support Flashii
+
Support {{ sakura.sitename }}

In order to keep the site, its services and improvements on it going I need money but I'm not that big of a fan of asking for money without giving anything special in return thus Tenshi exists. Tenshi is the name for our supporter rank which gives you access to an extra set of features (which are listed further down on this page). With your help we can keep adding new stuff, get new hardware and keep the site awesome!

diff --git a/api/api.php b/api/api.php index 1b9c891..23d0576 100644 --- a/api/api.php +++ b/api/api.php @@ -9,6 +9,9 @@ namespace Sakura; // Include components require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) .'_sakura/sakura.php'; +// Change to content type to text/plain and set the charset to UTF-8 +header('Content-Type: text/plain; charset=utf-8'); + // Trim leading slashes $path = ltrim($_SERVER['REQUEST_URI'], '/'); @@ -24,6 +27,54 @@ if($elems[0] == explode('/', ltrim($_SERVER['PHP_SELF'], '/'))[0]) { // Resort the array $elems = array_values($elems); + // Make sure there's at least one entry (even if empty) + if(!isset($elems[0])) + $elems[] = ""; + } -print_r($elems); +// Make sure the GET requests aren't present in the last entry +if(strpos($elems[max(array_keys($elems))], '?')) { + + // If there are cut them all + $elems[max(array_keys($elems))] = strstr($elems[max(array_keys($elems))], '?', true); + +} + +// Predefine the return variable +$return = []; + +// Select API version +switch(isset($elems[0]) ? $elems[0] : false) { + + // API Version 1 + case 'v1': + switch(isset($elems[1]) ? $elems[1] : false) { + + // Authentication + case 'authenticate': + switch(isset($elems[2]) ? $elems[2] : false) { + + case 'login': + $return = ['success' => 'LOGIN_PROCESS_HERE']; + break; + + default: + $return = ['error' => ['NO_DATA_REQ']]; + + } + break; + + default: + $return = ['error' => ['NO_DATA_REQ']]; + + } + break; + + // Default fallback + default: + $return = ['error' => ['NO_API_VERSION']]; + +} + +echo isset($_GET['pretty']) ? Main::jsonPretty(json_encode([$return])) : json_encode([$return]); diff --git a/content/data/yuuno/css/yuuno.css b/content/data/yuuno/css/yuuno.css index e3cbf04..700acef 100644 --- a/content/data/yuuno/css/yuuno.css +++ b/content/data/yuuno/css/yuuno.css @@ -1382,12 +1382,28 @@ a.gotop.exit { color: #503170; } -.support .featureBox.final { - width: 818px; +@media (min-width: 840px) { + + .support .featureBox.final { + width: 818px; + } + + .support .featureBox.final .featureBoxDesc { + font-size: 1.3em; + } + } -.support .featureBox.final .featureBoxDesc { - font-size: 1.3em; +@media (max-width: 840px) { + + .support .featureBox.final .featureBoxDesc { + line-height: 25px; + } + +} + +.support .featureBoxIcon.right { + float: right; } .support .featureBox:hover { @@ -1403,10 +1419,6 @@ a.gotop.exit { font-size: 2.8em; } -.support .featureBoxIcon.right { - float: right; -} - .support .featureBoxDesc { display: block; line-height: 50px; diff --git a/main/support.php b/main/support.php index 8d051d6..ecda02a 100644 --- a/main/support.php +++ b/main/support.php @@ -125,7 +125,7 @@ if(isset($_REQUEST['mode']) && Users::checkLogin() && Permissions::check('SITE', // Set default variables $renderData['page'] = [ - 'title' => 'Support Flashii', + 'title' => 'Support '. Configuration::getConfig('sitename'), 'fail' => isset($_GET['fail']), 'price' => Configuration::getConfig('premium_price_per_month'), 'current' => Users::checkUserPremium(Session::$userId),