Commit 642007d5 authored by Tino Goratsch's avatar Tino Goratsch

Merge branch 'feature/slugify' into develop

parents 7254579f 3d89ab71
......@@ -71,7 +71,7 @@ class ServiceContainerBuilder extends ContainerBuilder
$this->setParameter('core.environment', $this->applicationMode);
$this->addCompilerPass(
new RegisterListenersPass('core.eventDispatcher', 'core.eventListener', 'core.eventSubscriber')
new RegisterListenersPass('core.event_dispatcher', 'core.eventListener', 'core.eventSubscriber')
);
$this->addCompilerPass(new RegisterSmartyPluginsPass());
$this->addCompilerPass(new RegisterColumnRendererPass());
......
......@@ -2,6 +2,7 @@
namespace ACP3\Core\Helpers;
use ACP3\Core;
use Cocur\Slugify\Slugify;
/**
* Class StringFormatter
......@@ -9,42 +10,36 @@ use ACP3\Core;
*/
class StringFormatter
{
/**
* @var Slugify
*/
protected $slugify;
/**
* StringFormatter constructor.
* @param Slugify $slugify
*/
public function __construct(Slugify $slugify)
{
$this->slugify = $slugify;
}
/**
* @param string $var
*
* @return string
*/
public static function makeStringUrlSafe($var)
public function makeStringUrlSafe($var)
{
$var = strip_tags($var);
if (!preg_match('/&([a-z]+);/', $var)) {
$var = htmlentities($var, ENT_QUOTES, 'UTF-8');
}
$search = [
'/&([a-z]{1})uml;/',
'/ß/',
'/&([a-z0-9]+);/',
'/(\s+)/',
'/-{2,}/',
'/[^a-z0-9-]/',
];
$replace = [
'${1}e',
'ss',
'',
'-',
'-',
'',
];
$var = html_entity_decode(strip_tags($var));
return preg_replace($search, $replace, strtolower($var));
return $this->slugify->slugify($var, '-');
}
/**
* Converts new lines to HTML paragraphs and/or line breaks
*
* @param string $data
* @param string $data
* @param boolean $useLineBreaks
*
* @return string
......@@ -72,10 +67,10 @@ class StringFormatter
/**
* Shortens a string to the given length
*
* @param string $data
* @param string $data
* @param integer $chars
* @param integer $offset
* @param string $append
* @param string $append
*
* @return string
*/
......
......@@ -3,6 +3,7 @@ namespace ACP3\Core\Test\Helpers\ColumnRenderer;
use ACP3\Core\Helpers\DataGrid\ColumnRenderer\Nl2pColumnRenderer;
use ACP3\Core\Helpers\StringFormatter;
use Cocur\Slugify\Slugify;
class Nl2pColumnRendererTest extends AbstractColumnRendererTest
{
......@@ -13,7 +14,7 @@ class Nl2pColumnRendererTest extends AbstractColumnRendererTest
protected function setUp()
{
$this->stringFormatter = new StringFormatter();
$this->stringFormatter = new StringFormatter(new Slugify());
$this->columnRenderer = new Nl2pColumnRenderer($this->stringFormatter);
......
......@@ -8,6 +8,7 @@ namespace ACP3\Core\Test\Helpers;
use ACP3\Core\Helpers\StringFormatter;
use Cocur\Slugify\Slugify;
class StringFormatterTest extends \PHPUnit_Framework_TestCase
{
......@@ -34,7 +35,7 @@ HTML;
protected function setUp()
{
$this->stringFormatter = new StringFormatter();
$this->stringFormatter = new StringFormatter(new Slugify());
}
public function makeStringUrlSafeDataProvider()
......@@ -43,7 +44,7 @@ HTML;
'german_umlauts' => ['äüöumß', 'aeueoeumss'],
'german_umlauts_source_entities' => ['äöß', 'aeoess'],
'complex_characters' => ['ピックアップ', ''],
'preserve_numbers' => ['ピ23ッ6ク7アップ', '2367'],
'preserve_numbers' => ['ピ23ッ6ク7アップ', '23-6-7'],
'to_lower_case' => ['ÄÜÖumß', 'aeueoeumss'],
];
}
......
......@@ -13,6 +13,6 @@ services:
smarty.filter.page_css_classes:
class: ACP3\Core\View\Renderer\Smarty\Filters\PageCssClasses
arguments: ['@core.assets.pageCssClasses', '@core.http.request']
arguments: ['@core.assets.page_css_classes', '@core.http.request']
tags:
- { name: core.view.extension }
......@@ -19,13 +19,13 @@ services:
smarty.plugin.date_ramge:
class: ACP3\Core\View\Renderer\Smarty\Functions\DateRange
arguments: ['@core.helpers.formatter.dateRange']
arguments: ['@core.helpers.formatter.date_range']
tags:
- { name: core.view.extension }
smarty.plugin.event:
class: ACP3\Core\View\Renderer\Smarty\Functions\Event
arguments: ['@core.eventDispatcher']
arguments: ['@core.event_dispatcher']
tags:
- { name: core.view.extension }
......@@ -70,7 +70,7 @@ services:
smarty.plugin.page_css_classes:
class: ACP3\Core\View\Renderer\Smarty\Functions\PageCssClasses
arguments: ['@core.assets.pageCssClasses']
arguments: ['@core.assets.page_css_classes']
tags:
- { name: core.view.extension }
......
services:
smarty.plugin.addProtocol:
smarty.plugin.add_protocol:
class: ACP3\Core\View\Renderer\Smarty\Modifiers\PrefixUri
tags:
- { name: core.view.extension }
smarty.plugin.nl2p:
class: ACP3\Core\View\Renderer\Smarty\Modifiers\Nl2p
arguments: ['@core.helpers.stringFormatter']
arguments: ['@core.helpers.string_formatter']
tags:
- { name: core.view.extension }
smarty.plugin.rewrite_uri:
class: ACP3\Core\View\Renderer\Smarty\Modifiers\RewriteUri
arguments: ['@core.helpers.formatter.rewriteInternalUri']
arguments: ['@core.helpers.formatter.rewrite_internal_uri']
tags:
- { name: core.view.extension }
......@@ -2,7 +2,7 @@ services:
core.application.controller_action_dispatcher:
class: ACP3\Core\Application\ControllerActionDispatcher
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.http.request'
- '@service_container'
- '@core.application.argument_resolver'
......
......@@ -36,7 +36,7 @@ services:
- '@core.environment.application_path'
- '@core.modules.vendors'
core.assets.pageCssClasses:
core.assets.page_css_classes:
class: ACP3\Core\Assets\PageCssClasses
arguments:
- '@core.breadcrumb'
......
......@@ -6,10 +6,10 @@ services:
- '@core.lang'
- '@core.http.request'
- '@core.router'
- '@core.eventDispatcher'
- '@core.event_dispatcher'
core.breadcrumb.title:
class: ACP3\Core\Breadcrumb\Title
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.breadcrumb'
......@@ -3,7 +3,7 @@ services:
class: ACP3\Core\Controller\Context\WidgetContext
arguments:
- '@service_container'
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.acl'
- '@users.model.user_model'
- '@core.lang'
......
......@@ -10,7 +10,7 @@ services:
class: ACP3\Core\Helpers\DataGrid\ColumnRenderer\DateColumnRenderer
arguments:
- '@core.date'
- '@core.helpers.formatter.dateRange'
- '@core.helpers.formatter.date_range'
tags:
- { name: core.helpers.data_grid.column_renderer }
......@@ -34,7 +34,7 @@ services:
core.helpers.data_grid.column_renderer.nl2p_column_renderer:
class: ACP3\Core\Helpers\DataGrid\ColumnRenderer\Nl2pColumnRenderer
arguments:
- '@core.helpers.stringFormatter'
- '@core.helpers.string_formatter'
tags:
- { name: core.helpers.data_grid.column_renderer }
......@@ -43,7 +43,7 @@ services:
arguments:
- '@core.lang'
- '@core.helpers.data_grid.column_renderer.option_column_renderer.option_renderer'
- '@core.eventDispatcher'
- '@core.event_dispatcher'
tags:
- { name: core.helpers.data_grid.column_renderer }
......
......@@ -70,10 +70,12 @@ services:
- '@core.validation.validation_rules.integer_validation_rule'
- '@core.view'
core.helpers.stringFormatter:
core.helpers.string_formatter:
class: ACP3\Core\Helpers\StringFormatter
arguments:
- '@slugify'
core.helpers.formatter.dateRange:
core.helpers.formatter.date_range:
class: ACP3\Core\Helpers\Formatter\DateRange
arguments:
- '@core.date'
......@@ -84,7 +86,7 @@ services:
arguments:
- '@core.lang'
core.helpers.formatter.rewriteInternalUri:
core.helpers.formatter.rewrite_internal_uri:
class: ACP3\Core\Helpers\Formatter\RewriteInternalUri
arguments:
- '@core.environment.application_path'
......@@ -92,3 +94,6 @@ services:
- '@core.http.request'
- '@core.router'
- '@seo.validation.validation_rules.uri_alias_validation_rule'
slugify:
class: Cocur\Slugify\Slugify
......@@ -73,7 +73,7 @@ services:
- '@core.logger'
- '@core.view'
- '@core.config'
- '@core.helpers.stringFormatter'
- '@core.helpers.string_formatter'
core.pagination:
class: ACP3\Core\Pagination
......@@ -103,7 +103,7 @@ services:
core.xml:
class: ACP3\Core\XML
core.eventDispatcher:
core.event_dispatcher:
class: Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher
arguments:
- '@service_container'
......@@ -20,7 +20,14 @@
<label for="title" class="col-sm-2 control-label required">{lang t="articles|title"}</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="title" id="title" value="{$form.title}" maxlength="120" required>
<input class="form-control"
type="text"
name="title"
id="title"
value="{$form.title}"
maxlength="120"
data-seo-slug-base="true"
required>
</div>
</div>
<div class="form-group">
......
......@@ -12,7 +12,7 @@ services:
articles.model:
class: ACP3\Modules\ACP3\Articles\Model\ArticlesModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.date'
- '@core.helpers.secure'
- '@articles.model.articlerepository'
......@@ -12,6 +12,6 @@ services:
categories.model.categories_model:
class: ACP3\Modules\ACP3\Categories\Model\CategoriesModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.helpers.secure'
- '@categories.model.categories_repository'
......@@ -12,6 +12,6 @@ services:
emoticons.model:
class: ACP3\Modules\ACP3\Emoticons\Model\EmoticonsModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.helpers.secure'
- '@emoticons.model.emoticonrepository'
......@@ -20,7 +20,14 @@
<label for="title" class="col-sm-2 control-label required">{lang t="files|title"}</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="title" id="title" value="{$form.title}" maxlength="120" required>
<input class="form-control"
type="text"
name="title"
id="title"
value="{$form.title}"
maxlength="120"
data-seo-slug-base="true"
required>
</div>
</div>
{block FILES_FILE_UPLOAD}
......
......@@ -68,7 +68,7 @@ services:
arguments:
- '@core.context.frontend'
- '@core.date'
- '@core.helpers.stringFormatter'
- '@core.helpers.string_formatter'
- '@files.model.filesrepository'
- '@files.cache'
- '@categories.model.categories_repository'
......
......@@ -4,7 +4,7 @@ services:
arguments:
- '@core.date'
- '@core.router'
- '@core.helpers.stringFormatter'
- '@core.helpers.string_formatter'
- '@files.model.filesrepository'
tags:
- { name: core.eventListener, event: feeds.events.displayFeed.files, method: onDisplayFeed }
......
......@@ -17,7 +17,14 @@
<label for="title" class="col-sm-2 control-label required">{lang t="gallery|title"}</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="title" id="title" value="{$form.title}" maxlength="120" required>
<input class="form-control"
type="text"
name="title"
id="title"
value="{$form.title}"
maxlength="120"
data-seo-slug-base="true"
required>
</div>
</div>
</div>
......
......@@ -17,7 +17,7 @@ services:
gallery.model:
class: ACP3\Modules\ACP3\Gallery\Model\GalleryModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.date'
- '@core.helpers.secure'
- '@gallery.model.galleryrepository'
......@@ -25,7 +25,7 @@ services:
gallery.model.picture_model:
class: ACP3\Modules\ACP3\Gallery\Model\PictureModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.config'
- '@core.helpers.secure'
- '@gallery.model.picturerepository'
......@@ -12,7 +12,7 @@ services:
menus.model.menus_model:
class: ACP3\Modules\ACP3\Menus\Model\MenusModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.helpers.secure'
- '@menus.model.menurepository'
- '@menus.cache'
......@@ -6,5 +6,5 @@ services:
- '@core.lang'
- '@core.http.request'
- '@core.router'
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@menus.model.menuitemrepository'
......@@ -21,7 +21,14 @@
<label for="title" class="col-sm-2 control-label required">{lang t="news|title"}</label>
<div class="col-sm-10">
<input class="form-control" type="text" name="title" id="title" value="{$form.title}" maxlength="120" required>
<input class="form-control"
type="text"
name="title"
id="title"
value="{$form.title}"
maxlength="120"
data-seo-slug-base="true"
required>
</div>
</div>
<div class="form-group">
......
......@@ -68,7 +68,7 @@ services:
arguments:
- '@core.context.frontend'
- '@core.date'
- '@core.helpers.stringFormatter'
- '@core.helpers.string_formatter'
- '@core.pagination'
- '@news.model.newsrepository'
- '@categories.helpers'
......
......@@ -4,7 +4,7 @@ services:
arguments:
- '@core.date'
- '@core.router'
- '@core.helpers.stringFormatter'
- '@core.helpers.string_formatter'
- '@news.model.newsrepository'
tags:
- { name: core.eventListener, event: feeds.events.displayFeed.news, method: onDisplayFeed }
......
......@@ -12,7 +12,7 @@ services:
news.model:
class: ACP3\Modules\ACP3\News\Model\NewsModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.config'
- '@core.date'
- '@core.helpers.secure'
......
......@@ -27,7 +27,7 @@ services:
newsletter.model:
class: ACP3\Modules\ACP3\Newsletter\Model\NewsletterModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.config'
- '@core.date'
- '@core.helpers.secure'
......
......@@ -29,7 +29,7 @@ services:
- '@core.mailer'
- '@core.http.request'
- '@core.router'
- '@core.helpers.stringFormatter'
- '@core.helpers.string_formatter'
- '@core.helpers.secure'
- '@core.config'
- '@newsletter.helper.accountstatus'
......
......@@ -27,13 +27,13 @@ services:
permissions.model.resources_model:
class: ACP3\Modules\ACP3\Permissions\Model\ResourcesModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@permissions.model.resourcerepository'
permissions.model:role_model:
class: ACP3\Modules\ACP3\Permissions\Model\RoleModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.helpers.secure'
- '@core.nested_set'
- '@permissions.model.rolerepository'
......@@ -22,7 +22,7 @@ services:
polls.model.polls_model:
class: ACP3\Modules\ACP3\Polls\Model\PollsModel
arguments:
- '@core.eventDispatcher'
- '@core.event_dispatcher'
- '@core.date'
- '@core.helpers.secure'
- '@polls.model.pollrepository'
......
......@@ -10,4 +10,4 @@ services:
- '@core.acl'
- '@core.modules'
- '@core.helpers.forms'
- '@core.eventDispatcher'
- '@core.event_dispatcher'
<?php
/**
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Seo\Controller\Admin\Index;
use ACP3\Core\Controller\AbstractAdminAction;
use ACP3\Core\Controller\Context\AdminContext;
use ACP3\Core\Helpers\StringFormatter;
use Symfony\Component\HttpFoundation\JsonResponse;
class Suggest extends AbstractAdminAction
{
/**
* @var StringFormatter
*/
protected $stringFormatter;
/**
* Suggest constructor.
* @param AdminContext $context
* @param StringFormatter $stringFormatter
*/
public function __construct(AdminContext $context, StringFormatter $stringFormatter)
{
parent::__construct($context);
$this->stringFormatter = $stringFormatter;
}
/**
* @return JsonResponse
*/
public function execute()
{
$response = [];
if ($this->request->getPost()->count() > 0) {
$formData = $this->request->getPost()->all();
if (!empty($formData['title'])) {
$alias = $this->stringFormatter->makeStringUrlSafe($formData['title']);
if (!empty($formData['prefix'])) {
$alias = $this->stringFormatter->makeStringUrlSafe($formData['prefix']) . '/' . $alias;
}
$response = ['alias' => $alias];
}
}
return new JsonResponse($response);
}
}
......@@ -12,7 +12,7 @@ class Migration implements Modules\Installer\MigrationInterface
{
/**
* @inheritdoc
*
*
* @return array
*/
public function schemaUpdates()
......@@ -33,6 +33,9 @@ class Migration implements Modules\Installer\MigrationInterface
],
6 => [
"DELETE FROM `{pre}settings` WHERE `module_id` = '{moduleId}' AND `name` = 'mod_rewrite';",
],
7 => [
"INSERT INTO `{pre}acl_resources` (`id`, `module_id`, `area`, `controller`, `page`, `params`, `privilege_id`) VALUES('', '{moduleId}', 'admin', 'index', 'suggest', '', 4);",
]
];
}
......
......@@ -33,7 +33,7 @@ class Schema implements Modules\Installer\SchemaInterface
*/
public function getSchemaVersion()
{
return 6;
return 7;
}
/**
......
/*
* Copyright (c) 2016 by the ACP3 Developers.
* See the LICENCE file at the top-level module directory for licencing details.
*/
;(function($) {
"use strict";
var pluginName = "suggestAlias",
defaults = {
prefix: '',
slugBaseElement: null,
aliasElement: null
};
function Plugin(element, options) {
this.element = element;
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.init();
}
$.extend(Plugin.prototype, {
init: function () {
var that = this;
$(this.element).on('click', function(e) {
e.preventDefault();
that.performAjaxRequest();
});
},
performAjaxRequest: function() {
var that = this;
if (that.settings.slugBaseElement !== null && that.settings.aliasElement !== null) {
$.ajax({
url: that.element.href,
type: 'post',
data: {
prefix: that.settings.prefix,
title: that.settings.slugBaseElement.val()
},
beforeSend: function() {
$(that.element).addClass('disabled');
},
success: function (responseData) {
try {
if (typeof responseData.alias !== "undefined" && responseData.alias.length > 0) {
$(that.settings.aliasElement).val(responseData.alias);
}
} catch (err) {
console.log(err.message);
} finally {
$(that.element).removeClass('disabled');
}
}
});
}
}
});
$.fn[pluginName] = function (options) {
return this.each(function () {
if (!$.data(this, "plugin_" + pluginName)) {
$.data(this, "plugin_" + pluginName, new Plugin(this, options));
}
});
};