Merge branch 'master' of C:\Users\Sergio\Documents\GitHub\XBackBone with conflicts.

This commit is contained in:
Sergio Brighenti 2018-11-25 16:16:43 +01:00
parent 1d345cf61e
commit 8bb89ecb62
7 changed files with 46 additions and 142 deletions

View file

@ -73,6 +73,7 @@ module.exports = function (grunt) {
'resources/lang/**/*', 'resources/lang/**/*',
'resources/templates/**/*', 'resources/templates/**/*',
'resources/schemas/**/*', 'resources/schemas/**/*',
'resources/lang/**/*',
'static/**/*', 'static/**/*',
'vendor/**/*', 'vendor/**/*',
'.htaccess', '.htaccess',

View file

@ -1,46 +1,34 @@
<?php <?php
namespace App\Web; namespace App;
class Lang class Lang
{ {
const DEFAULT_LANG = 'en'; const DEFAULT_LANG = 'en';
const LANG_PATH = __DIR__ . '/../../resources/lang/'; const LANG_PATH = __DIR__ . '../../resources/lang/';
/** @var array */
protected $cache = [];
/** @var string */ /** @var string */
protected $path; protected static $langPath = self::LANG_PATH;
/** @var string */ /** @var string */
protected $lang; protected static $lang;
/** @var Lang */ /** @var Lang */
protected static $instance; protected static $instance;
/** /** @var array */
* Lang constructor. protected $cache = [];
* @param $lang
* @param $path
*/
public function __construct($lang, $path)
{
$this->lang = $lang;
$this->path = $path;
}
/** /**
* @return Lang * @return Lang
*/ */
public static function getInstance() public static function getInstance(): Lang
{ {
if (self::$instance === null) { if (self::$instance === null) {
self::$instance = self::build(); self::$instance = new self();
} }
return self::$instance; return self::$instance;
@ -48,22 +36,24 @@ class Lang
/** /**
* @param string $lang * @param string $lang
* @param string $path * @param string $langPath
* @return Lang * @return Lang
*/ */
public static function build($lang = self::DEFAULT_LANG, $path = null) public static function build($lang = self::DEFAULT_LANG, $langPath = null): Lang
{ {
if (strlen($lang) !== 2) { if (strlen($lang) !== 2) {
$lang = strtolower(substr($lang, 0, 2)); self::$lang = strtolower(substr($lang, 0, 2));
} else {
self::$lang = $lang;
} }
if (file_exists(($path ? $path : self::LANG_PATH) . $lang . '.lang.php')) { if ($langPath !== null) {
self::$instance = new self($lang, $path); self::$langPath = $langPath;
} else {
self::$instance = new self(self::DEFAULT_LANG, $path);
} }
self::$instance = new self();
return self::$instance; return self::$instance;
} }
@ -73,9 +63,9 @@ class Lang
* @param array $args * @param array $args
* @return string * @return string
*/ */
public function get($key, $args = []) public function get($key, $args = []): string
{ {
return $this->getString($key, $this->lang, $args); return $this->getString($key, self::$lang, $args);
} }
/** /**
@ -84,13 +74,13 @@ class Lang
* @param $args * @param $args
* @return string * @return string
*/ */
private function getString($key, $lang, $args) private function getString($key, $lang, $args): string
{ {
if (array_key_exists($lang, $this->cache)) { if (array_key_exists($lang, $this->cache)) {
$transDict = $this->cache[$lang]; $transDict = $this->cache[$lang];
} else if (file_exists($this->path . $lang . '.lang.php')) { } elseif (file_exists(self::$langPath . $lang . '.lang.php')) {
$transDict = include $this->path . $lang . '.lang.php'; $transDict = include self::$langPath . $lang . '.lang.php';
$this->cache[$lang] = $transDict; $this->cache[$lang] = $transDict;
} else { } else {
$transDict = []; $transDict = [];
@ -106,12 +96,4 @@ class Lang
return $key; return $key;
} }
/**
* @return string
*/
public function getLang(): string
{
return $this->lang;
}
} }

View file

@ -16,7 +16,8 @@ class Session
if (session_status() === PHP_SESSION_NONE) { if (session_status() === PHP_SESSION_NONE) {
session_start([ session_start([
'name' => $name, 'name' => $name,
'save_path' => $path 'save_path' => $path,
'cookie_httponly' => true
]); ]);
} }
} }

View file

@ -2,86 +2,4 @@
return [ return [
'lang' => 'English',
'yes' => 'Yes',
'no' => 'No',
'send' => 'Send',
'no_media' => 'No media found.',
'login.username' => 'Username or E-Mail',
'password' => 'Password',
'login' => 'Login',
'username' => 'Username',
'home' => 'Home',
'users' => 'Users',
'system' => 'System',
'profile' => 'Profile',
'logout' => 'Logout',
'pager.next' => 'Next',
'pager.previous' => 'Previous',
'copy_link' => 'Copy link',
'public.telegram' => 'Share on Telegram',
'public.delete_text' => 'Are you sure you want to delete this item? It will be gone forever!',
'preview' => 'Preview',
'filename' => 'Filename',
'size' => 'Size',
'public' => 'Public',
'owner' => 'Owner',
'date' => 'Date',
'raw' => 'Show raw',
'download' => 'Download',
'delete' => 'Delete',
'publish' => 'Publish',
'hide' => 'Hide',
'files' => 'Files',
'orphaned_files' => 'Orphaned Files',
'theme' => 'Theme',
'click_to_load' => 'Click to load...',
'apply' => 'Apply',
'save' => 'Save',
'used' => 'Used',
'system_info' => 'System Information',
'user.create' => 'Create User',
'user.edit' => 'Edit User',
'is_active' => 'Is active',
'is_admin' => 'Is administrator',
'your_profile' => 'Your Profile',
'token' => 'Token',
'copy' => 'Copy',
'update' => 'Update',
'edit' => 'Edit',
'client_config' => 'Client Configuration',
'user_code' => 'User Code',
'active' => 'Active',
'admin' => 'Admin',
'reg_date' => 'Registration Date',
'none' => 'None',
'open' => 'Open',
'confirm' => 'Confirmation',
'confirm_string' => 'Are you sure?',
'installed' => 'Installation completed successfully!',
'bad_login' => 'Wrong credentials.',
'account_disabled' => 'Your account is disabled.',
'welcome' => 'Welcome, %s!',
'goodbye' => 'Goodbye!',
'token_not_found' => 'Token specified not found.',
'email_required' => 'The email is required.',
'email_taken' => 'The email is already taken.',
'username_required' => 'The username is required.',
'username_taken' => 'The username is already taken.',
'password_required' => 'The password is required.',
'user_created' => 'User "%s" created!',
'user_updated' => 'User "%s" updated!',
'profile_updated' => 'Profile updated successfully!',
'user_deleted' => 'User deleted.',
'cannot_delete' => 'You cannot delete yourself.',
'cannot_demote' => 'You cannot demote yourself',
]; ];

View file

@ -1,2 +1,2 @@
CREATE UNIQUE INDEX IF NOT EXISTS `username_email` CREATE UNIQUE INDEX IF NOT EXISTS `email_index`
ON `users` (`email`); ON `users` (`email`);

View file

@ -1,5 +1,5 @@
<footer class="footer"> <footer class="footer">
<div class="container-fluid"> <div class="container-fluid">
<div class="text-muted">Proudly powered by <a href="https://github.com/SergiX44/XBackBone">XBackBone{% if session.logged %} v{{ PLATFORM_VERSION }}{% endif %}</a></div> <div class="text-muted">Proudly powered by <a href="https://github.com/SergiX44/XBackBone" target="_blank">XBackBone{% if session.logged %} v{{ PLATFORM_VERSION }}{% endif %}</a></div>
</div> </div>
</footer> </footer>

View file

@ -1,6 +1,6 @@
{% extends 'base.twig' %} {% extends 'base.twig' %}
{% block title %}{{ lang('home') }}{% endblock %} {% block title %}Home{% endblock %}
{% block content %} {% block content %}
{% include 'comp/navbar.twig' %} {% include 'comp/navbar.twig' %}
@ -13,40 +13,42 @@
<div class="col-md-4" id="media_{{ media.id }}"> <div class="col-md-4" id="media_{{ media.id }}">
<div class="card mb-4 box-shadow"> <div class="card mb-4 box-shadow">
{% if media.mimetype starts with 'image' %} {% if media.mimetype starts with 'image' %}
<img class="card-img" src="{{ urlFor('/' ~ media.user_code ~ '/' ~ media.code ~ '.' ~ media.extension ~ '/raw?width=286&height=219') }}" alt="Card image"> <a href="{{ config.base_url }}/{{ media.user_code }}/{{ media.code }}.{{ media.extension }}" target="_blank">
<img class="card-img-top user-img" src="{{ config.base_url }}/{{ media.user_code }}/{{ media.code }}.{{ media.extension }}/raw?width=348&height=192" alt="{{ media.filename }}">
</a>
{% else %} {% else %}
<div class="text-center" style="font-size: 178px;"><i class="far {{ mime2font(media.mimetype) }} mb-4 mt-4"></i></div> <a href="{{ config.base_url }}/{{ media.user_code }}/{{ media.code }}.{{ media.extension }}" target="_blank">
<div class="card-header text-center"><i class="far fa-file fa-10x"></i></div>
</a>
{% endif %} {% endif %}
<div class="card-img-overlay" title="{{ media.filename }}"> <div class="card-body">
<div class="user-img-buttons"> <p class="card-text">{{ media.filename }}
<span class="badge badge-dark box-shadow-strong">{{ media.size }}</span> <small class="float-right">{{ media.size }}</small>
<div class="btn-group box-shadow-strong float-right"> </p>
<a class="btn btn-sm btn-light" href="{{ urlFor('/' ~ media.user_code ~ '/' ~ media.code ~ '.' ~ media.extension) }}" data-toggle="tooltip" title="{{ lang('open') }}" target="_blank"><i class="fas fa-external-link-alt"></i></a> <div class="d-flex justify-content-between align-items-center">
<button type="button" class="btn btn-sm btn-success btn-clipboard" data-toggle="tooltip" title="{{ lang('copy_link') }}" data-clipboard-text="{{ urlFor('/' ~ media.user_code ~ '/' ~ media.code ~ '.' ~ media.extension) }}"> <div class="btn-group">
<button type="button" class="btn btn-sm btn-outline-success btn-clipboard" data-toggle="tooltip" title="Copy link" data-clipboard-text="{{ config.base_url }}/{{ media.user_code }}/{{ media.code }}.{{ media.extension }}">
<i class="fas fa-link"></i> <i class="fas fa-link"></i>
</button> </button>
{% if media.published %} {% if media.published %}
<a href="javascript:void(0)" class="btn btn-sm btn-warning publish-toggle" data-toggle="tooltip" title="{{ lang('hide') }}" data-id="{{ media.id }}" data-published="{{ media.published }}"><i class="fas fa-times-circle"></i></a> <a href="javascript:void(0)" class="btn btn-sm btn-outline-warning publish-toggle" data-toggle="tooltip" title="Unpublish" data-id="{{ media.id }}" data-published="{{ media.published }}"><i class="fas fa-times-circle"></i></a>
{% else %} {% else %}
<a href="javascript:void(0)" class="btn btn-sm btn-info publish-toggle" data-toggle="tooltip" title="{{ lang('publish') }}" data-id="{{ media.id }}" data-published="{{ media.published }}"><i class="fas fa-check-circle"></i></a> <a href="javascript:void(0)" class="btn btn-sm btn-outline-info publish-toggle" data-toggle="tooltip" title="Publish" data-id="{{ media.id }}" data-published="{{ media.published }}"><i class="fas fa-check-circle"></i></a>
{% endif %} {% endif %}
<button type="button" class="btn btn-sm btn-danger media-delete" data-link="{{ route('upload.delete', {'id': media.id}) }}" data-id="{{ media.id }}" data-toggle="tooltip" title="{{ lang('delete') }}"> <button type="button" class="btn btn-sm btn-outline-danger media-delete" data-link="{{ config.base_url }}/upload/{{ media.id }}/delete" data-id="{{ media.id }}" data-toggle="tooltip" title="Delete">
<i class="fas fa-trash"></i> <i class="fas fa-trash"></i>
</button> </button>
</div> </div>
<small class="text-muted">{{ media.timestamp|date("d/m/Y H:i:s") }}</small>
</div> </div>
</div> </div>
<div class="card-footer d-flex justify-content-between">
<span class="user-title">{{ media.filename }}</span>
<small>{{ media.timestamp|date("d/m/Y H:i") }}</small>
</div>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% include 'comp/pager.twig' with {'path': 'home'} %} {% include 'comp/pager.twig' with {'path': 'home'} %}
{% else %} {% else %}
<div class="text-center text-muted"><i>{{ lang('no_media') }}</i></div> <div class="text-center text-muted"><i>No medias found.</i></div>
{% endif %} {% endif %}
</div> </div>
{% include 'comp/footer.twig' %} {% include 'comp/footer.twig' %}