From bcbb74a6801b7319aa2414dc49eb2e55d7d5645e Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Thu, 22 Feb 2018 20:07:06 +0100 Subject: [PATCH] Allow setting URL slug through admin panel. --- controllers/EditAsset.php | 5 +++-- models/Asset.php | 11 +++++++++-- templates/EditAssetForm.php | 3 +++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/controllers/EditAsset.php b/controllers/EditAsset.php index 68a79908..bf01e16a 100644 --- a/controllers/EditAsset.php +++ b/controllers/EditAsset.php @@ -33,10 +33,11 @@ class EditAsset extends HTMLController } // Key info - if (isset($_POST['title'], $_POST['date_captured'], $_POST['priority'])) + if (isset($_POST['title'], $_POST['slug'], $_POST['date_captured'], $_POST['priority'])) { $date_captured = !empty($_POST['date_captured']) ? new DateTime($_POST['date_captured']) : null; - $asset->setKeyData(htmlentities($_POST['title']), $date_captured, intval($_POST['priority'])); + $slug = strtr($_POST['slug'], [' ' => '-', '--' => '-', '&' => 'and', '=>' => '', "'" => "", ":"=> "", '\\' => '-']); + $asset->setKeyData(htmlentities($_POST['title']), $slug, $date_captured, intval($_POST['priority'])); } // Handle tags diff --git a/models/Asset.php b/models/Asset.php index 5a6565f0..6d15a094 100644 --- a/models/Asset.php +++ b/models/Asset.php @@ -314,6 +314,11 @@ class Asset return ASSETSDIR . '/' . $this->subdir . '/' . $this->filename; } + public function getSlug() + { + return $this->slug; + } + public function getSubdir() { return $this->subdir; @@ -535,11 +540,12 @@ class Asset FROM assets'); } - public function setKeyData($title, DateTime $date_captured = null, $priority) + public function setKeyData($title, $slug, DateTime $date_captured = null, $priority) { $params = [ 'id_asset' => $this->id_asset, 'title' => $title, + 'slug' => $slug, 'priority' => $priority, ]; @@ -548,7 +554,8 @@ class Asset return Registry::get('db')->query(' UPDATE assets - SET title = {string:title},' . (isset($date_captured) ? ' + SET title = {string:title}, + slug = {string:slug},' . (isset($date_captured) ? ' date_captured = {datetime:date_captured},' : '') . ' priority = {int:priority} WHERE id_asset = {int:id_asset}', diff --git a/templates/EditAssetForm.php b/templates/EditAssetForm.php index bca57e5e..14e29f8f 100644 --- a/templates/EditAssetForm.php +++ b/templates/EditAssetForm.php @@ -65,6 +65,9 @@ class EditAssetForm extends SubTemplate
Title
+
URL slug
+
+
Date captured