Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NodeBundle] Show url slug in wysiwyg #1938

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions src/Kunstmaan/AdminBundle/Resources/ui/js/_rich-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,24 +252,8 @@ kunstmaanbundles.richEditor = (function (window, undefined) {

url.onKeyUp = function () {
this.allowOnChange = !1;
var a = this.getDialog().getContentElement("info", "protocol"), b = this.getValue(), k = /^((javascript:)|[#\/\.\?])/i, c = /^(http|https|ftp|news):\/\/(?=.)/i.exec(b);
c ? (this.setValue(b.substr(c[0].length)), a.setValue(c[0].toLowerCase())) : k.test(b) && a.setValue("");

var nodeTranslationPtrn = new RegExp(/\[(([a-z_A-Z]+):)?NT([0-9]+)\]/g);
while (match = nodeTranslationPtrn.exec(b)) {
// Node translation found, so set protocol to other.
if (match[3]) {
a.setValue("");
}
}

var mediaPtrn = new RegExp(/\[(([a-z_A-Z]+):)?M([0-9]+)\]/g);
while (match = mediaPtrn.exec(b)) {
// Media found, so set protocol to other.
if (match[3]) {
a.setValue("");
}
}
var a = this.getDialog().getContentElement("info", "protocol"), b = this.getValue(), c = /^(http|https|ftp|news):\/\/(?=.)/i.exec(b);
c ? (this.setValue(b.substr(c[0].length)), a.setValue(c[0].toLowerCase())) : a.setValue("");

this.allowOnChange = !0
};
Expand Down
4 changes: 2 additions & 2 deletions src/Kunstmaan/NodeBundle/Controller/WidgetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ protected function nodesToArray($locale, $rootNodes, $depth = 2)
foreach ($rootNodes as $rootNode) {
if ($nodeTranslation = $rootNode->getNodeTranslation($locale, true)) {
if ($isMultiDomain && !$switched) {
$slug = sprintf('[%s:%s]', $switchedHost['id'], 'NT'.$nodeTranslation->getId());
$slug = sprintf('link://%s:%s/%s', $switchedHost, $nodeTranslation->getId(), $nodeTranslation->getSlug());
} else {
$slug = sprintf('[%s]', 'NT'.$nodeTranslation->getId());
$slug = sprintf('link://%s/%s', $nodeTranslation->getId(), $nodeTranslation->getSlug());
}

switch (true) {
Expand Down
7 changes: 4 additions & 3 deletions src/Kunstmaan/NodeBundle/Helper/URLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,19 @@ public function replaceUrl($text)
}

if ($this->isInternalLink($text)) {
preg_match_all("/\[(([a-z_A-Z\.]+):)?NT([0-9]+)\]/", $text, $matches, PREG_SET_ORDER);
preg_match_all("/\[(([a-z_A-Z]+):)?NT([0-9]+)\]|(link:\/\/([a-z_A-Z]*):?([0-9]+)([\w\-._~!?$&%'()*+,;=:@\/]+))/", $text, $matches, PREG_SET_ORDER);

if (\count($matches) > 0) {
foreach ($matches as $match) {
$fullTag = $match[0];
$hostId = $match[2];
$isSchemaLink = empty($match[3]);
$hostId = $isSchemaLink ? $match[5] : $match[2];
$nodeTranslationId = $isSchemaLink ? $match[6] : $match[3];

$hostConfig = !empty($hostId) ? $this->domainConfiguration->getFullHostById($hostId) : null;
$host = null !== $hostConfig && array_key_exists('host', $hostConfig) ? $hostConfig['host'] : null;
$hostBaseUrl = $this->domainConfiguration->getHostBaseUrl($host);

$nodeTranslationId = $match[3];
$nodeTranslation = $this->getNodeTranslation($nodeTranslationId);

if ($nodeTranslation) {
Expand Down
2 changes: 1 addition & 1 deletion src/Kunstmaan/NodeBundle/Validation/URLValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function isEmailAddress($link)
*/
public function isInternalLink($link)
{
preg_match_all("/\[(([a-z_A-Z\.]+):)?NT(\d+)\]/", $link, $matches, PREG_SET_ORDER);
preg_match_all("/\[(([a-z_A-Z]+):)?NT([0-9]+)\]|(link:\/\/[0-9]+)/", $link, $matches, PREG_SET_ORDER);

return \count($matches) > 0;
}
Expand Down