mirror of
https://github.com/flextype/flextype.git
synced 2025-08-17 10:30:46 +02:00
@@ -22,6 +22,7 @@ use Slim\Flash\Messages;
|
||||
use League\Glide\ServerFactory;
|
||||
use League\Glide\Responses\SlimResponseFactory;
|
||||
use League\Event\Emitter;
|
||||
use Cocur\Slugify\Slugify;
|
||||
|
||||
/**
|
||||
* The version of Flextype
|
||||
@@ -96,6 +97,13 @@ $flextype['emitter'] = function ($container) {
|
||||
return new Emitter();
|
||||
};
|
||||
|
||||
/**
|
||||
* Add slugify service to Flextype container
|
||||
*/
|
||||
$flextype['slugify'] = function ($container) {
|
||||
return new Slugify(['separator' => '-', 'lowercase' => true, 'trim' => true]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Add flash service to Flextype container
|
||||
*/
|
||||
|
@@ -23,6 +23,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
* @property Flash $flash
|
||||
* @property Csrf $csrf
|
||||
* @property Themes $themes
|
||||
* @property Slugify $slugify
|
||||
*/
|
||||
class EntriesController extends Controller
|
||||
{
|
||||
@@ -161,7 +162,7 @@ class EntriesController extends Controller
|
||||
}
|
||||
|
||||
// Set new Entry ID
|
||||
$id = $parent_entry_id . '/' . Text::safeString($data['id'], '-', true);
|
||||
$id = $parent_entry_id . '/' . $this->slugify->slugify($data['id']);
|
||||
|
||||
// Check if entry exists then try to create
|
||||
if (!$this->entries->has($id)) {
|
||||
@@ -381,7 +382,7 @@ class EntriesController extends Controller
|
||||
if (!$this->entries->has($data['parent_entry'] . '/' . $data['name_current'])) {
|
||||
if ($this->entries->rename(
|
||||
$data['entry_path_current'],
|
||||
$data['parent_entry'] . '/' . Text::safeString($data['name_current'], '-', true)
|
||||
$data['parent_entry'] . '/' . $this->slugify->slugify($data['name_current'])
|
||||
)) {
|
||||
$this->flash->addMessage('success', __('admin_message_entry_moved'));
|
||||
} else {
|
||||
@@ -440,7 +441,7 @@ class EntriesController extends Controller
|
||||
|
||||
if ($this->entries->rename(
|
||||
$data['entry_path_current'],
|
||||
$data['entry_parent'] . '/' . Text::safeString($data['name'], '-', true)
|
||||
$data['entry_parent'] . '/' . $this->slugify->slugify($data['name'])
|
||||
)) {
|
||||
$this->flash->addMessage('success', __('admin_message_entry_renamed'));
|
||||
} else {
|
||||
@@ -1013,7 +1014,7 @@ class EntriesController extends Controller
|
||||
}
|
||||
if ($remove_spaces === true) {
|
||||
// Remove spaces from the filename
|
||||
$filename = Text::safeString(pathinfo($filename)['filename'], '-', true) . '.' . pathinfo($filename)['extension'];
|
||||
$filename = $this->slugify->slugify(pathinfo($filename)['filename']) . '.' . pathinfo($filename)['extension'];
|
||||
}
|
||||
if (!is_dir($upload_directory) or !is_writable(realpath($upload_directory))) {
|
||||
throw new \RuntimeException("Directory {$upload_directory} must be writable");
|
||||
|
@@ -67,7 +67,7 @@ class FieldsetsController extends Controller
|
||||
Arr::delete($data, 'csrf_name');
|
||||
Arr::delete($data, 'csrf_value');
|
||||
|
||||
$id = Text::safeString($data['id'], '-', true);
|
||||
$id = $this->slugify->slugify($data['id']);
|
||||
$data = ['title' => $data['title']];
|
||||
|
||||
if ($this->fieldsets->create($id, $data)) {
|
||||
|
@@ -12,6 +12,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
* @property View $view
|
||||
* @property Router $router
|
||||
* @property Snippets $snippets
|
||||
* @property Slugify $slugify
|
||||
*/
|
||||
class SnippetsController extends Controller
|
||||
{
|
||||
@@ -85,7 +86,7 @@ class SnippetsController extends Controller
|
||||
*/
|
||||
public function addProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
$id = Text::safeString($request->getParsedBody()['id'], '-', true);
|
||||
$id = $this->slugify->slugify($request->getParsedBody()['id']);
|
||||
|
||||
if ($this->snippets->create($id, "")) {
|
||||
$this->flash->addMessage('success', __('admin_message_snippet_created'));
|
||||
@@ -193,7 +194,7 @@ class SnippetsController extends Controller
|
||||
*/
|
||||
public function renameProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
$id = Text::safeString($request->getParsedBody()['id'], '-', true);
|
||||
$id = $this->slugify->slugify($request->getParsedBody()['id']);
|
||||
$id_current = $request->getParsedBody()['id_current'];
|
||||
|
||||
if ($this->snippets->rename(
|
||||
@@ -219,7 +220,7 @@ class SnippetsController extends Controller
|
||||
*/
|
||||
public function deleteProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
$id = Text::safeString($request->getParsedBody()['snippet-id'], '-', true);
|
||||
$id = $this->slugify->slugify($request->getParsedBody()['snippet-id']);
|
||||
|
||||
if ($this->snippets->delete($id)) {
|
||||
$this->flash->addMessage('success', __('admin_message_snippet_deleted'));
|
||||
@@ -240,7 +241,7 @@ class SnippetsController extends Controller
|
||||
*/
|
||||
public function duplicateProcess(Request $request, Response $response) : Response
|
||||
{
|
||||
$id = Text::safeString($request->getParsedBody()['snippet-id'], '-', true);
|
||||
$id = $this->slugify->slugify($request->getParsedBody()['snippet-id']);
|
||||
|
||||
if ($this->snippets->copy($id, $id . '-duplicate-' . date("Ymd_His"))) {
|
||||
$this->flash->addMessage('success', __('admin_message_snippet_duplicated'));
|
||||
|
@@ -13,6 +13,7 @@ use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
* @property Router $router
|
||||
* @property Cache $cache
|
||||
* @property Themes $themes
|
||||
* @property Slugify $slugify
|
||||
*/
|
||||
class TemplatesController extends Controller
|
||||
{
|
||||
@@ -89,7 +90,7 @@ class TemplatesController extends Controller
|
||||
{
|
||||
$type = $request->getParsedBody()['type'];
|
||||
|
||||
$id = Text::safeString($request->getParsedBody()['id'], '-', true) . '.html';
|
||||
$id = $this->slugify->slugify($request->getParsedBody()['id']) . '.html';
|
||||
|
||||
$file = PATH['themes'] . '/' . $this->registry->get('settings.theme') . '/' . $this->_type_location($type) . $id;
|
||||
|
||||
|
@@ -69,11 +69,11 @@ class UsersController extends Controller
|
||||
// Get POST data
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
if (!Filesystem::has($_user_file = PATH['site'] . '/accounts/' . Text::safeString($data['username']) . '.json')) {
|
||||
if (!Filesystem::has($_user_file = PATH['site'] . '/accounts/' . $this->slugify->slugify($data['username']) . '.json')) {
|
||||
Filesystem::createDir(PATH['site'] . '/accounts/');
|
||||
if (Filesystem::write(
|
||||
PATH['site'] . '/accounts/' . $data['username'] . '.json',
|
||||
JsonParser::encode(['username' => Text::safeString($data['username']),
|
||||
JsonParser::encode(['username' => $this->slugify->slugify($data['username']),
|
||||
'hashed_password' => password_hash($data['password'], PASSWORD_BCRYPT),
|
||||
'email' => $data['email'],
|
||||
'role' => 'admin',
|
||||
|
Reference in New Issue
Block a user