diff --git a/_sakura/changelog.json b/_sakura/changelog.json index 97c0a56..1ef7e42 100644 --- a/_sakura/changelog.json +++ b/_sakura/changelog.json @@ -9,7 +9,9 @@ "builds": [ "20150508", - "20150509" + "20150509", + "20150509.1", + "20150512" ] @@ -1003,6 +1005,40 @@ "change": "Fixed avatar border being depositioned." } + ], + + "20150509.1": [ + + { + "type": "UPD", + "change": "Compactise (not a word but you get the meaning) array adding in the server-side notification system." + }, + { + "type": "FIX", + "change": "Fixed some redundancy in the news viewer." + }, + { + "type": "FIX", + "change": "Fixed CORS breaking notifications." + }, + { + "type": "FIX", + "change": "Fix a wrong way of assigning notifications to a user (Session::$userId instead of $user)." + }, + { + "type": "UPD", + "change": "Replace .cfg files and parser with the built in .ini parser." + } + + ], + + "20150512": [ + + { + "type": "FIX", + "change": "Fix {{ sakura.currentpage }} redirecting to the php file that's being used without the right attributes." + } + ] } diff --git a/_sakura/components/Configuration.php b/_sakura/components/Configuration.php index 8127359..3f676be 100644 --- a/_sakura/components/Configuration.php +++ b/_sakura/components/Configuration.php @@ -56,7 +56,7 @@ class Configuration { trigger_error('Unable to get local configuration value!', E_USER_ERROR); } - + // Dynamically set local configuration values, does not update the configuration file public static function setLocalConfig($key, $subkey, $value) { diff --git a/_sakura/components/Templates.php b/_sakura/components/Templates.php index 553b118..61456b7 100644 --- a/_sakura/components/Templates.php +++ b/_sakura/components/Templates.php @@ -19,17 +19,17 @@ class Templates { self::$_TPL = $template; // Assign config path to a variable so we don't have to type it out twice - $confPath = ROOT .'_sakura/templates/'. self::$_TPL .'/template.cfg'; + $confPath = ROOT .'_sakura/templates/'. self::$_TPL .'/template.ini'; // Check if the configuration file exists if(!file_exists($confPath)) trigger_error('Template configuration does not exist', E_USER_ERROR); // Parse and store the configuration - self::$_CFG = self::parseCfg(file_get_contents($confPath)); + self::$_CFG = parse_ini_file($confPath, true); // Make sure we're not using a manage template for the main site or the other way around - if((bool)self::$_CFG['MANAGE'] != (bool)Main::$_MANAGE_MODE) + if((bool)self::$_CFG['manage']['mode'] != (bool)Main::$_MANAGE_MODE) trigger_error('Incorrect template type', E_USER_ERROR); // Start Twig @@ -55,43 +55,6 @@ class Templates { } - // Parse .cfg files - public static function parseCfg($data) { - - // Create storage variable - $out = array(); - - // Remove comments and empty lines - $data = preg_replace('/#.*?\r\n/im', null, $data); - $data = preg_replace('/^\r\n/im', null, $data); - - // Break line breaks up into array values - $data = str_replace("\r\n", "\n", $data); - $data = str_replace("\r", "\n", $data); - $data = explode("\n", $data); - - foreach($data as $var) { - - // Make sure no whitespaces escaped the check - if(empty($var)) - continue; - - // Remove whitespace between key, equals sign and value - $var = preg_replace('/[\s+]=[\s+]/i', '=', $var); - - // Then break this up - $var = explode('=', $var); - - // And assign the value with the key to the output variable - $out[$var[0]] = $var[1]; - - } - - // Return the output variable - return $out; - - } - // Render template public static function render($file, $tags) { diff --git a/_sakura/components/Users.php b/_sakura/components/Users.php index 90ca877..78e7b90 100644 --- a/_sakura/components/Users.php +++ b/_sakura/components/Users.php @@ -991,7 +991,7 @@ class Users { // Insert it into the database Database::insert('notifications', [ - 'uid' => Session::$userId, + 'uid' => $user, 'timestamp' => $time, 'notif_read' => 0, 'notif_sound' => ($sound ? 1 : 0), @@ -1004,4 +1004,34 @@ class Users { } + // Getting a user's PMs + public static function getPrivateMessages($from = false) { + + // Get all messages from the database + $messages = Database::fetch('messages', true, [ + ($from ? 'from_user' : 'to_user') => [Session::$userId, '='] + ]); + + // Prepare a storage array + $store = array(); + + // Go over each message and check if they are for the current user + foreach($messages as $message) { + + // Store the message + $store[$message['id']] = $message; + + // Store user data as well + $store[$message['id']]['data']['from']['user'] = ($_MSG_USR = self::getUser($message['from_user'])); + $store[$message['id']]['data']['from']['rank'] = self::getRank($_MSG_USR['rank_main']); + $store[$message['id']]['data']['to']['user'] = ($_MSG_USR = self::getUser($message['to_user'])); + $store[$message['id']]['data']['to']['rank'] = self::getRank($_MSG_USR['rank_main']); + + } + + // Return store array + return $store; + + } + } diff --git a/_sakura/config/config.example.ini b/_sakura/config/config.example.ini new file mode 100644 index 0000000..e5cc81a --- /dev/null +++ b/_sakura/config/config.example.ini @@ -0,0 +1,74 @@ +; Example Sakura configuration +; Rename this file to config.ini after you're done editing. + +; Database configuration +[database] +; SQL Driver that should be used. +; This has to relate to a PHP file in the _sakura/components/database folder +; but must EXCLUDE the .php file extension. (I recommend sticking with the bundled mysql library) +driver = mysql + +; Use a Unix system socket (if the library supports it), doesn't work on Windows servers. +unix_socket = 0 + +; URI to SQL server (usually localhost or 127.0.0.1) or in the case that you're using Unix sockets +; the path to the socket. +host = localhost + +; Port for the SQL server, ignored if Unix sockets are used. Should be 3306. +port = 3306 + +; Username used to authenticate with the SQL server +username = sakura + +; Password for the same purpose +password = password + +; Database (not table) name used. +database = sakura + +; Table prefix used. +prefix = sakura_ + + +; Path configuration (DO NOT INCLUDE PROTOCOLS) +[urls] +; Main site location +main = yourdomain.com + +; API location +api = api.yourdomain.com + +; Content location +content = content.yourdomain.com + +; Management panel location +manage = manage.yourdomain.com + +; Forum location +forum = forum.yourdomain.com + +; Chat location +chat = chat.yourdomain.com + + +; Data files relative to the _sakura directory +[data] +; File containing CloudFlare CIDRs +cfhosts = config/cloudflare.hosts + +; JSON file containing WHOIS servers +whoisservers = config/whois.json + +; JSON file containing ISO 3166 country codes +iso3166 = config/iso3166.json + + +; Sock Chat extensions configuration +; These only work properly if Sock Chat uses the same database as the rest of Sakura +[sockchat] +; Set whether the Sock Chat extensions should be used or not +enabled = 1 + +; The table prefix used for Sock Chat +prefix = sock_ diff --git a/_sakura/sakura.php b/_sakura/sakura.php index a59b8f1..4085309 100644 --- a/_sakura/sakura.php +++ b/_sakura/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20150509'); +define('SAKURA_VERSION', '20150512'); define('SAKURA_VLABEL', 'Eminence'); define('SAKURA_VTYPE', 'Development'); define('SAKURA_COLOUR', '#6C3082'); @@ -64,7 +64,7 @@ $renderData = array( 'vcolour' => SAKURA_COLOUR, 'urls' => Configuration::getLocalConfig('urls'), 'charset' => Configuration::getConfig('charset'), - 'currentpage' => '//'. $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'], + 'currentpage' => '//'. $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'], 'recaptcha_public' => Configuration::getConfig('recaptcha_public'), 'recaptcha_enable' => Configuration::getConfig('recaptcha'), 'resources' => '//'. Configuration::getLocalConfig('urls')['content'] .'/data/'. strtolower(Templates::$_TPL), diff --git a/_sakura/templates/amu/template.cfg b/_sakura/templates/amu/template.cfg deleted file mode 100644 index 7721fac..0000000 --- a/_sakura/templates/amu/template.cfg +++ /dev/null @@ -1,10 +0,0 @@ -# -# Amu -# Design planned for 2016 -# - -# Sets name of this template -NAME = Amu - -# Is this style intended for manage? -MANAGE = 0 diff --git a/_sakura/templates/amu/template.ini b/_sakura/templates/amu/template.ini new file mode 100644 index 0000000..e7caeb6 --- /dev/null +++ b/_sakura/templates/amu/template.ini @@ -0,0 +1,14 @@ +; Sakura Template Configuration + +[meta] +; Display name of the style, only used in the admin section of the management panel. +name = Amu +; Author of this template. +author = Flashwave +; If you set a URL below your name becomes a clickable link in the management panel. +author_url = https://flash.moe + +[manage] +; This defines whether the template is intended for the management panel. +; When it's incorrect Sakura will halt execution of the script. +mode = 0 diff --git a/_sakura/templates/broomcloset/template.cfg b/_sakura/templates/broomcloset/template.cfg deleted file mode 100644 index 2a0e3b3..0000000 --- a/_sakura/templates/broomcloset/template.cfg +++ /dev/null @@ -1,9 +0,0 @@ -# -# Sakura Manage Panel -# - -# Sets name of this template -NAME = Broomcloset - -# Is this style intended for manage? -MANAGE = 1 diff --git a/_sakura/templates/broomcloset/template.ini b/_sakura/templates/broomcloset/template.ini new file mode 100644 index 0000000..2f27cbd --- /dev/null +++ b/_sakura/templates/broomcloset/template.ini @@ -0,0 +1,14 @@ +; Sakura Template Configuration + +[meta] +; Display name of the style, only used in the admin section of the management panel. +name = Broom Closet +; Author of this template. +author = Flashwave +; If you set a URL below your name becomes a clickable link in the management panel. +author_url = https://flash.moe + +[manage] +; This defines whether the template is intended for the management panel. +; When it's incorrect Sakura will halt execution of the script. +mode = 1 diff --git a/_sakura/templates/mio/template.cfg b/_sakura/templates/mio/template.cfg deleted file mode 100644 index 8a6dc2c..0000000 --- a/_sakura/templates/mio/template.cfg +++ /dev/null @@ -1,10 +0,0 @@ -# -# Mio -# 2014 Flashii Design -# - -# Sets name of this template -NAME = Mio - -# Is this style intended for manage? -MANAGE = 0 diff --git a/_sakura/templates/mio/template.ini b/_sakura/templates/mio/template.ini new file mode 100644 index 0000000..20259ea --- /dev/null +++ b/_sakura/templates/mio/template.ini @@ -0,0 +1,14 @@ +; Sakura Template Configuration + +[meta] +; Display name of the style, only used in the admin section of the management panel. +name = Mio +; Author of this template. +author = Flashwave +; If you set a URL below your name becomes a clickable link in the management panel. +author_url = https://flash.moe + +[manage] +; This defines whether the template is intended for the management panel. +; When it's incorrect Sakura will halt execution of the script. +mode = 0 diff --git a/_sakura/templates/yuuno/elements/newsPost.tpl b/_sakura/templates/yuuno/elements/newsPost.tpl index 3638170..ba63179 100644 --- a/_sakura/templates/yuuno/elements/newsPost.tpl +++ b/_sakura/templates/yuuno/elements/newsPost.tpl @@ -1,4 +1,4 @@ -{% if page.articleCount > 1 %}{{ newsPost.title }}{% endif %} +{% if newsPosts|length > 1 %}{{ newsPost.title }}{% endif %}
@@ -12,5 +12,5 @@
- Posted on {{ newsPost.date|date("D Y-m-d H:i:s T") }}{% if page.articleCount > 1 %} View comments{% endif %} + Posted on {{ newsPost.date|date("D Y-m-d H:i:s T") }}{% if newsPosts|length > 1 %} View comments{% endif %}
diff --git a/_sakura/templates/yuuno/elements/restricted.tpl b/_sakura/templates/yuuno/elements/restricted.tpl new file mode 100644 index 0000000..ab9aa63 --- /dev/null +++ b/_sakura/templates/yuuno/elements/restricted.tpl @@ -0,0 +1,5 @@ +
+

Login to view this page!

+ If you actually are logged in something went wrong and you should report this to the administrator.
+ If you aren't logged in please log in or create an account if you don't have one. +
diff --git a/_sakura/templates/yuuno/elements/settingsNav.tpl b/_sakura/templates/yuuno/elements/settingsNav.tpl new file mode 100644 index 0000000..1c41c26 --- /dev/null +++ b/_sakura/templates/yuuno/elements/settingsNav.tpl @@ -0,0 +1,28 @@ +
+ Navigation +
+
+
General
+ Home + Edit Profile +
Messages
+ Inbox + Sent + Compose +
Notifications
+ History +
Aesthetics
+ Avatar + Background + Profile Page +
Account
+ E-Mail Address + Username + User Title + Password + Ranks +
Danger zone
+ Sessions + Registration Keys + Deactivate Account +
diff --git a/_sakura/templates/yuuno/main/memberlist.tpl b/_sakura/templates/yuuno/main/memberlist.tpl index 7440bfa..9dac97e 100644 --- a/_sakura/templates/yuuno/main/memberlist.tpl +++ b/_sakura/templates/yuuno/main/memberlist.tpl @@ -92,10 +92,6 @@ {% endif %}
{% else %} -
-

Login to view this page!

- If you actually are logged in something went wrong and you should report this to the administrator.
- If you aren't logged in please log in or create an account if you don't have one. -
+ {% include 'elements/restricted.tpl' %} {% endif %} {% include 'global/footer.tpl' %} diff --git a/_sakura/templates/yuuno/main/messages.tpl b/_sakura/templates/yuuno/main/messages.tpl new file mode 100644 index 0000000..a3de6c3 --- /dev/null +++ b/_sakura/templates/yuuno/main/messages.tpl @@ -0,0 +1,36 @@ +{% include 'global/header.tpl' %} +
+
+ {% include 'elements/settingsNav.tpl' %} +
+
+
+ Messages / Inbox +
+ {% if messages|length %} + + + + + + + + + + {% for message in messages %} + + + + + + {% endfor %} + +
FromSubjectSent on
{{ message.data.from.user.username }}{{ message.subject }}{{ message.time|date("l Y-m-d H:i T") }}
+ {% else %} +

Nothing to view!

+ {% endif %} +

Click Compose in the menu on the right side to write a new message!

+
+
+
+{% include 'global/footer.tpl' %} diff --git a/_sakura/templates/yuuno/main/news.tpl b/_sakura/templates/yuuno/main/news.tpl index e6581dd..6798ff8 100644 --- a/_sakura/templates/yuuno/main/news.tpl +++ b/_sakura/templates/yuuno/main/news.tpl @@ -1,8 +1,8 @@ {% include 'global/header.tpl' %}
-
{% if page.articleCount == 1 %}{{ newsPosts[0].title }}{% elseif page.articleCount < 1 %}Post does not exist!{% else %}News {% endif %}
- {% if page.articleCount >= 1 %} +
{% if newsPosts|length == 1 %}{{ newsPosts[0].title }}{% elseif newsPosts|length < 1 %}Post does not exist!{% else %}News {% endif %}
+ {% if newsPosts|length >= 1 %} {% for newsPost in newsPosts %} {% include 'elements/newsPost.tpl' %} {% endfor %} @@ -17,7 +17,7 @@
{% endif %}
- {% if page.articleCount > 1 %} + {% if newsPosts|length > 1 %} - {% elseif page.articleCount == 1 %} + {% elseif newsPosts|length == 1 %}