Skip to content
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "smartling/wordpress-connector",
"license": "GPL-2.0-or-later",
"version": "5.7.0",
"version": "5.7.3",
"description": "",
"type": "wordpress-plugin",
"repositories": [
Expand Down
58 changes: 33 additions & 25 deletions inc/Smartling/Helpers/WordpressContentTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
use Smartling\Exception\SmartlingDirectRunRuntimeException;
use Smartling\Submissions\SubmissionEntity;

/**
* Class WordpressContentTypeHelper
* @package Smartling\Helpers
*/
class WordpressContentTypeHelper
{
/**
Expand Down Expand Up @@ -144,39 +140,51 @@ public static function getBaseTypeByContentType($contentType)
return $ctHandler->getBaseType();
}

public static function getEditUrl(SubmissionEntity $submission)
public static function getTargetEditUrl(SubmissionEntity $submission)
{
/**
* @var ContentTypeAbstract $ctHandler
*/
$ctHandler = static::getContentTypeManager()->getHandler($submission->getContentType());
return static::buildEditUrl($submission, $submission->getTargetBlogId(), $submission->getTargetId());
}

public static function getSourceEditUrl(SubmissionEntity $submission): string
{
return static::buildEditUrl($submission, $submission->getSourceBlogId(), $submission->getSourceId());
}

private static function buildEditUrl(SubmissionEntity $submission, int $blogId, int $contentId): string
{
try {
$ctHandler = static::getContentTypeManager()->getHandler($submission->getContentType());
} catch (\Exception $e) {
Bootstrap::getLogger()->warning(sprintf('%s (submissionId=%d)', $e->getMessage(), $submission->getId()));

return '';
}

if ($ctHandler instanceof ContentTypeAbstract) {
$tail = '';
switch ($ctHandler->getBaseType()) {
case 'post':
$tail = vsprintf('/post.php?post=%s&action=edit', [$submission->getTargetId()]);
$tail = sprintf('/post.php?post=%s&action=edit', $contentId);
break;
case 'taxonomy':
$tail = sprintf('/term.php?taxonomy=%s&tag_ID=%s', $submission->getContentType(), $submission->getTargetId());
$tail = sprintf('/term.php?taxonomy=%s&tag_ID=%s', $submission->getContentType(), $contentId);
break;
default:
return '';
}

return get_admin_url($submission->getTargetBlogId(), $tail);
} else {
Bootstrap::getLogger()->warning(
vsprintf(
'Requested edit URI for unknown content-type \'%s\'',
[
$submission->getContentType(),
]
)
);

return '';
return get_admin_url($blogId, $tail);
}

Bootstrap::getLogger()->warning(
vsprintf(
'Requested edit URI for unknown content-type \'%s\'',
[
$submission->getContentType(),
]
)
);

return '';

}
}
}
41 changes: 28 additions & 13 deletions inc/Smartling/WP/Controller/ConfigurationProfileFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,23 @@ public function save(): void
$profile->setSourceLocale($locale);
}

$sourceBlogId = $profile->getSourceLocale()->getBlogId();

$usedTargetLocales = [];
if (array_key_exists('targetLocales', $settings)) {
$locales = [];

foreach ($settings['targetLocales'] as $blogId => $settings) {
foreach ($settings['targetLocales'] as $blogId => $targetLocaleSettings) {
if ((int)$blogId === $sourceBlogId) {
continue;
}
try {
$tLocale = new TargetLocale();
$tLocale->setBlogId($blogId);
$tLocale->setLabel($this->siteHelper->getBlogLabelById($this->localizationPluginProxy, $blogId));
$enabled = 'on' === $settings['enabled'];
$tLocale->setEnabled(array_key_exists('enabled', $settings) && $enabled);
$smartlingLocale = array_key_exists('target', $settings) ? $settings['target'] : -1;
$enabled = 'on' === $targetLocaleSettings['enabled'];
$tLocale->setEnabled(array_key_exists('enabled', $targetLocaleSettings) && $enabled);
$smartlingLocale = array_key_exists('target', $targetLocaleSettings) ? $targetLocaleSettings['target'] : -1;
$tLocale->setSmartlingLocale($smartlingLocale);
if ($smartlingLocale !== -1 && $enabled) {
$usedTargetLocales[] = $smartlingLocale;
Expand Down Expand Up @@ -269,7 +274,8 @@ protected function renderLocales(
string $displayName,
int $blogId,
string $smartlingName,
bool $enabled,
bool $checked,
bool $disabled,
): string {
$parts = [];

Expand All @@ -279,34 +285,43 @@ protected function renderLocales(
'name' => sprintf('smartling_settings[targetLocales][%s][enabled]', $blogId),
];

if (true === $enabled) {
if (true === $checked) {
$checkboxProperties['checked'] = 'checked';
}

if (true === $disabled) {
$checkboxProperties['disabled'] = 'disabled';
}

$parts[] = HtmlTagGeneratorHelper::tag('input', '', $checkboxProperties);
$parts[] = HtmlTagGeneratorHelper::tag('span', htmlspecialchars($displayName));
$parts = [
HtmlTagGeneratorHelper::tag('label', implode('', $parts), ['class' => 'radio-label']),
];

$targetLocaleProperties = [
'name' => sprintf('smartling_settings[targetLocales][%s][target]', $blogId),
];

if (true === $disabled) {
$targetLocaleProperties['disabled'] = 'disabled';
}

if (0 === count($locales)) {
$sLocale = HtmlTagGeneratorHelper::tag(
'input',
'',
[
'name' => sprintf('smartling_settings[targetLocales][%s][target]', $blogId),
'type' => 'text',
]);
$targetLocaleProperties + ['type' => 'text'],
);
} else {
$sLocale = HtmlTagGeneratorHelper::tag(
'select',
HtmlTagGeneratorHelper::renderSelectOptions(
$smartlingName,
$locales
),
[
'name' => sprintf('smartling_settings[targetLocales][%s][target]', $blogId),
]);
$targetLocaleProperties,
);
}

$parts = [
Expand Down
28 changes: 26 additions & 2 deletions inc/Smartling/WP/Table/SubmissionTableWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ public function column_cb($item): string
);
}

public static function buildSourceTitleCell(string $escapedTitle, string $sourceEditUrl): string
{
if ($sourceEditUrl === '') {
return $escapedTitle;
}

return HtmlTagGeneratorHelper::tag('a', $escapedTitle, ['href' => $sourceEditUrl]);
}

public static function buildTargetLocaleCell(string $blogLabel, string $targetEditUrl): string
{
if ($targetEditUrl === '') {
return $blogLabel;
}

return HtmlTagGeneratorHelper::tag('a', $blogLabel, ['href' => $targetEditUrl]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestion: $blogLabel is interpolated unescaped into the <a> tag here, unlike buildSourceTitleCell above, whose caller pre-escapes the title with htmlentities(). Pre-existing gap, but this exact line is already being touched - cheap to close now, e.g. htmlentities($blogLabel) at the call site (line 432) or inside this method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed - now escaping $blogLabel with htmlentities() at the call site, matching how buildSourceTitleCell's caller pre-escapes the title.

}

public function get_columns(): array
{
$columns = $this->submissionManager->getColumnsLabels();
Expand Down Expand Up @@ -398,7 +416,10 @@ public function prepare_items(): void

$fileName = htmlentities($row[SubmissionEntity::FIELD_FILE_URI]);
$row[SubmissionEntity::FIELD_FILE_URI] = $fileName;
$row[SubmissionEntity::FIELD_SOURCE_TITLE] = htmlentities($row[SubmissionEntity::FIELD_SOURCE_TITLE]);
$row[SubmissionEntity::FIELD_SOURCE_TITLE] = static::buildSourceTitleCell(
htmlentities($row[SubmissionEntity::FIELD_SOURCE_TITLE]),
0 !== $element->getSourceId() ? WordpressContentTypeHelper::getSourceEditUrl($element) : ''
);
$row[SubmissionEntity::FIELD_CONTENT_TYPE] = WordpressContentTypeHelper::getLocalizedContentType($row[SubmissionEntity::FIELD_CONTENT_TYPE]);
$row[SubmissionEntity::FIELD_SUBMISSION_DATE] = $this->sqlToReadableDate($row[SubmissionEntity::FIELD_SUBMISSION_DATE]);
$row[SubmissionEntity::FIELD_APPLIED_DATE] = $this->sqlToReadableDate($row[SubmissionEntity::FIELD_APPLIED_DATE]);
Expand All @@ -407,7 +428,10 @@ public function prepare_items(): void
} catch (BlogNotFoundException $e) {
$blogLabel = "*blog id {$row[SubmissionEntity::FIELD_TARGET_BLOG_ID]} not found*";
}
$row[SubmissionEntity::FIELD_TARGET_LOCALE] = $blogLabel;
$row[SubmissionEntity::FIELD_TARGET_LOCALE] = static::buildTargetLocaleCell(
htmlentities($blogLabel),
0 !== $element->getTargetId() ? WordpressContentTypeHelper::getTargetEditUrl($element) : ''
);
$row[SubmissionEntity::VIRTUAL_FIELD_JOB_LINK] = $jobInfo->getJobName() === '' ? '' : "<a href=\"https://dashboard.smartling.com/app/projects/{$jobInfo->getProjectUid()}/account-jobs/?filename=$fileName\">" . esc_html($jobInfo->getJobName()) . '</a>';

$flagBlockParts = [];
Expand Down
13 changes: 5 additions & 8 deletions inc/Smartling/WP/View/ConfigurationProfileForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,8 @@
<?php
$targetLocales = $profile->getTargetLocales();
$supportedLocales = $this->api->getSupportedLocales($profile);
$currentSourceBlogId = $profile->getSourceLocale()->getBlogId();
foreach ($locales as $blogId => $label) {
if ($blogId === $profile->getSourceLocale()
->getBlogId()
) {
continue;
}

$smartlingLocale = '';
$enabled = false;

Expand All @@ -490,10 +485,12 @@
break;
}
}

$isSourceLocaleRow = $blogId === $currentSourceBlogId;
?>

<tr>
<?= $this->renderLocales($supportedLocales, $label, $blogId, $smartlingLocale, $enabled) ?>
<tr class="target-locale-row<?= $isSourceLocaleRow ? ' hidden' : '' ?>" data-blog-id="<?= $blogId ?>">
<?= $this->renderLocales($supportedLocales, $label, $blogId, $smartlingLocale, $enabled, $isSourceLocaleRow) ?>
</tr>
<?php
}
Expand Down
2 changes: 1 addition & 1 deletion inc/Smartling/WP/View/post-based-content-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
$enabled = !(1 === $item->getIsCloned() || 1 === $item->hasLocks());

if (0 !== (int) $item->getTargetId()) {
$editUrl = WordpressContentTypeHelper::getEditUrl($item);
$editUrl = WordpressContentTypeHelper::getTargetEditUrl($item);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion inc/Smartling/WP/View/taxonomy-based-content-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
$percent = $item->getCompletionPercentage();
$status = $item->getStatusColor();
$statusFlags = $item->getStatusFlags();
$editUrl = WordpressContentTypeHelper::getEditUrl($item);
if (0 !== $item->getTargetId()) {
$editUrl = WordpressContentTypeHelper::getTargetEditUrl($item);
}
$enabled = !(1 === $item->getIsCloned() || 1 === $item->getIsLocked());
break;
}
Expand Down
16 changes: 16 additions & 0 deletions js/configuration-profile-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
});
$('#smartling-configuration-profile-form').validate()
}

const syncTargetLocaleRows = function (sourceLocaleSelect) {
const sourceBlogId = String(sourceLocaleSelect.value);
$('#target-locale-block tr.target-locale-row').each(function () {
const row = $(this);
const isSource = String(row.data('blog-id')) === sourceBlogId;
row.toggleClass('hidden', isSource);
row.find('input, select').prop('disabled', isSource);
});
};

$('#default-locales, #default-locales-new').each(function () {
syncTargetLocaleRows(this);
}).on('change', function () {
syncTargetLocaleRows(this);
});
$('a.toggleExpert').on('click', function () {
$('.toggleExpert').removeClass('hidden');
$('a.toggleExpert').addClass('hidden');
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: translation, localization, multilingual, internationalization, smartling
Requires at least: 5.5
Tested up to: 7.0
Requires PHP: 8.0
Stable tag: 5.7.0
Stable tag: 5.7.3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.7.1 and 5.7.2 were development releases

License: GPLv2 or later

Translate content in WordPress quickly and seamlessly with Smartling, the industry-leading Translation Management System.
Expand Down Expand Up @@ -62,6 +62,10 @@ Additional information on the Smartling Connector for WordPress can be found [he
3. Track translation status within WordPress from the Submissions Board. View overall progress of submitted translation requests as well as resend updated content.

== Changelog ==
= 5.7.3 =
* Fixed possible misconfiguration where target locales were being saved as a duplicate of a newly changed source locale

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestion: the 5.7.3 changelog entry only documents the source/target-locale collision fix. This PR also adds Submissions Board source/target edit links and fixes a fatal error on that same board for historical unregistered content types - neither is mentioned. Consider adding a bullet for each.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added changelog bullets for both the source/target edit links and the historical-content-type fatal error fix.

* Added links to the source and target content (if available) on the Translation Progress screen

= 5.7.0 =
* Reworked upload queue, added a live-refreshing upload queue count with visual feedback on change

Expand Down
2 changes: 1 addition & 1 deletion smartling-connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Smartling Connector
* Plugin URI: https://www.smartling.com/products/automate/integrations/wordpress/
* Description: Integrate your WordPress site with Smartling to upload your content and download translations.
* Version: 5.7.0
* Version: 5.7.3
* Author: Smartling
* Author URI: https://www.smartling.com
* License: GPL-2.0+
Expand Down
Loading