Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Adding system setting for enabling/disabling keywords field and counters #80

Open
wants to merge 1 commit into
base: development
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
5 changes: 5 additions & 0 deletions _build/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
"value": "google",
"area": "general"
},{
"key": "use_keywords",
"type": "combo-boolean",
"value": "1",
"area": "general"
}, {
"key": "user_name",
"type": "textfield",
"area": "general",
Expand Down
63 changes: 38 additions & 25 deletions assets/components/seopro/js/mgr/seopro.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ Ext.extend(seoPro, Ext.Component, {
seoPro.config.siteNameShow = !MODx.isEmpty(MODx.config['seopro.usesitename']);
seoPro.config.searchEngine = MODx.isEmpty(MODx.config['seopro.searchengine']) ? 'google' : MODx.config['seopro.searchengine'];
seoPro.config.titleFormat = MODx.isEmpty(MODx.config['seopro.title_format']) ? '' : MODx.config['seopro.title_format'];
seoPro.addKeywords();

if (parseInt(MODx.config['seopro.use_keywords']) === 1) {
seoPro.addKeywords();
}

seoPro.addPanel();

Ext.each(seoPro.config.fields.split(','), function(field) {
Expand Down Expand Up @@ -47,12 +51,17 @@ Ext.extend(seoPro, Ext.Component, {
seoPro.changePrevBox(field);
});

var counterHtml = '';
if (parseInt(MODx.config['seopro.use_keywords']) === 1) {
counterHtml += '<span class="seopro-counter-wrap seopro-counter-keywords" id="seopro-counter-keywords-' + field + '" title="' + _('seopro.keywords') + '"><strong>' + _('seopro.keywords') + ':&nbsp;&nbsp;</strong><span id="seopro-counter-keywords-' + field + '-current">0</span></span>';
}
counterHtml += '<span class="seopro-counter-wrap seopro-counter-chars" id="seopro-counter-chars-' + field + '" title="' + _('seopro.characters.allowed') + '"><strong>' + _('seopro.characters') + ': </strong><span class="current" id="seopro-counter-chars-' + field + '-current">1</span>/<span class="allowed" id="seopro-counter-chars-' + field + '-allowed">' + seoPro.config.chars[field] + '</span></span>';

Ext.get('x-form-el-modx-resource-' + field).createChild({
tag: 'div',
id: 'seopro-resource-' + field,
class: 'seopro-counter',
html: '<span class="seopro-counter-wrap seopro-counter-keywords" id="seopro-counter-keywords-' + field + '" title="' + _('seopro.keywords') + '"><strong>' + _('seopro.keywords') + ':&nbsp;&nbsp;</strong><span id="seopro-counter-keywords-' + field + '-current">0</span></span>\
<span class="seopro-counter-wrap seopro-counter-chars" id="seopro-counter-chars-' + field + '" title="' + _('seopro.characters.allowed') + '"><strong>' + _('seopro.characters') + ': </strong><span class="current" id="seopro-counter-chars-' + field + '-current">1</span>/<span class="allowed" id="seopro-counter-chars-' + field + '-allowed">' + seoPro.config.chars[field] + '</span></span>'
html: counterHtml
});
seoPro.count(field);
}
Expand Down Expand Up @@ -147,33 +156,37 @@ Ext.extend(seoPro, Ext.Component, {
charCount = charCount + extra.length;
}
}
var keywordCount = 0;
Ext.each(Ext.get('seopro-keywords').getValue().split(','), function(keyword) {
keyword = keyword.replace(/^\s+/, '').toLowerCase();

if (keyword) {
var counter = Value.toLowerCase().match(new RegExp("(^|[ \s\n\r\t\.,'\(\"\+;!?:\-])" + keyword + "($|[ \s\n\r\t.,'\)\"\+!?:;\-])", 'gim'));
// var counter = Value.toLowerCase().match(new RegExp('\\b' + keyword + '\\b', 'g'));
if (counter) {
keywordCount = keywordCount + counter.length;
if (parseInt(MODx.config['seopro.use_keywords']) === 1) {
var keywordCount = 0;
Ext.each(Ext.get('seopro-keywords').getValue().split(','), function (keyword) {
keyword = keyword.replace(/^\s+/, '').toLowerCase();

if (keyword) {
var counter = Value.toLowerCase().match(new RegExp("(^|[ \s\n\r\t\.,'\(\"\+;!?:\-])" + keyword + "($|[ \s\n\r\t.,'\)\"\+!?:;\-])", 'gim'));
// var counter = Value.toLowerCase().match(new RegExp('\\b' + keyword + '\\b', 'g'));
if (counter) {
keywordCount = keywordCount + counter.length;
}
}
}
});
Ext.get('seopro-counter-chars-' + field + '-current').dom.innerHTML = charCount;
Ext.get('seopro-counter-keywords-' + field + '-current').dom.innerHTML = keywordCount;
});

var maxKeywords = MODx.isEmpty(MODx.config['seopro.max_keywords_title']) ? '4' : MODx.config['seopro.max_keywords_title'];
if (field === 'description') {
// use different limit for the description
maxKeywords = MODx.isEmpty(MODx.config['seopro.max_keywords_description']) ? '8' : MODx.config['seopro.max_keywords_description'];
}
maxKeywords = parseInt(maxKeywords);
Ext.get('seopro-counter-keywords-' + field + '-current').dom.innerHTML = keywordCount;

if (keywordCount > 0 && keywordCount <= maxKeywords) {
Ext.get('seopro-counter-keywords-' + field).removeClass('red').addClass('green');
} else {
Ext.get('seopro-counter-keywords-' + field).removeClass('green').addClass('red');
var maxKeywords = MODx.isEmpty(MODx.config['seopro.max_keywords_title']) ? '4' : MODx.config['seopro.max_keywords_title'];
if (field === 'description') {
// use different limit for the description
maxKeywords = MODx.isEmpty(MODx.config['seopro.max_keywords_description']) ? '8' : MODx.config['seopro.max_keywords_description'];
}
maxKeywords = parseInt(maxKeywords);

if (keywordCount > 0 && keywordCount <= maxKeywords) {
Ext.get('seopro-counter-keywords-' + field).removeClass('red').addClass('green');
} else {
Ext.get('seopro-counter-keywords-' + field).removeClass('green').addClass('red');
}
}
Ext.get('seopro-counter-chars-' + field + '-current').dom.innerHTML = charCount;

if (charCount > maxchars || charCount === 0) {
Ext.get('seopro-counter-chars-' + field).removeClass('green').addClass('red');
Expand Down
13 changes: 9 additions & 4 deletions core/components/seopro/elements/plugins/seopro.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,16 @@
if (in_array($template, $disabledTemplates)) {
break;
}
$seoKeywords = $modx->getObject('seoKeywords', array('resource' => $modx->resource->get('id')));
if ($seoKeywords) {
$keyWords = $seoKeywords->get('keywords');
$modx->setPlaceholder('seoPro.keywords', $keyWords);

$useKeywords = (bool) $modx->getOption('seopro.use_keywords', null, true);
if ($useKeywords) {
$seoKeywords = $modx->getObject('seoKeywords', array('resource' => $modx->resource->get('id')));
if ($seoKeywords) {
$keyWords = $seoKeywords->get('keywords');
$modx->setPlaceholder('seoPro.keywords', $keyWords);
}
}

// Render the meta title, based on system settings
$titleFormat = $modx->getOption('seopro.title_format');
if (empty($titleFormat)) {
Expand Down
4 changes: 3 additions & 1 deletion core/components/seopro/lexicon/de/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
$_lang['setting_seopro.searchengine_desc'] ='Mögliche Werte: google, yandex.';
$_lang['setting_seopro.title_format'] ='Format used for the meta title.';
$_lang['setting_seopro.title_format_desc'] ='Here you can specify the format used for the meta title used
in Google/Yandex preview. The rendered output is also available on frontend with [[+seoPro.title]].';
in Google/Yandex preview. The rendered output is also available on frontend with [[+seoPro.title]].';
$_lang['setting_seopro.use_keywords'] ='Use keywords';
$_lang['setting_seopro.use_keywords_desc'] ='Enable/disable the keywords field and keywords counters.';
2 changes: 2 additions & 0 deletions core/components/seopro/lexicon/en/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@
$_lang['setting_seopro.title_format'] ='Format used for the meta title.';
$_lang['setting_seopro.title_format_desc'] ='Here you can specify the format for the meta title used
in Google/Yandex preview. The rendered output is also available on frontend with [[+seoPro.title]].';
$_lang['setting_seopro.use_keywords'] ='Use keywords';
$_lang['setting_seopro.use_keywords_desc'] ='Enable/disable the keywords field and keywords counters.';
2 changes: 2 additions & 0 deletions core/components/seopro/lexicon/fr/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@

$_lang['setting_seopro.delimiter'] = 'Séparateur dans Google/Yandex preview.';
$_lang['setting_seopro.delimiter_desc'] = 'Séparateur de titre et de nom de site';
$_lang['setting_seopro.use_keywords'] ='Use keywords';
$_lang['setting_seopro.use_keywords_desc'] ='Enable/disable the keywords field and keywords counters.';
2 changes: 2 additions & 0 deletions core/components/seopro/lexicon/it/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
$_lang['seopro.prevbox_yandex'] = 'Come verrà visualizzato in Yandex?';
$_lang['seopro.emptymetadescription']='<i>Please enter a description</i>';
$_lang['seopro.branding_text']='This site is optimized with the Sterc seoPro plugin - https://github.com/Sterc/SEOPro.';
$_lang['setting_seopro.use_keywords'] ='Use keywords';
$_lang['setting_seopro.use_keywords_desc'] ='Enable/disable the keywords field and keywords counters.';
2 changes: 2 additions & 0 deletions core/components/seopro/lexicon/nl/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@
$_lang['setting_seopro.title_format'] ='Format used for the meta title.';
$_lang['setting_seopro.title_format_desc'] ='Here you can specify the format used for the meta title used
in Google/Yandex preview. The rendered output is also available on frontend with [[+seoPro.title]].';
$_lang['setting_seopro.use_keywords'] ='Gebruik keywords';
$_lang['setting_seopro.use_keywords_desc'] ='Zet het keywords veld inclusief de keyword counters aan/uit.';
2 changes: 2 additions & 0 deletions core/components/seopro/lexicon/pl/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
$_lang['setting_seopro.title_format'] ='Format used for the meta title.';
$_lang['setting_seopro.title_format_desc'] ='Here you can specify the format used for the meta title used
in Google/Yandex preview. The rendered output is also available on frontend with [[+seoPro.title]].';
$_lang['setting_seopro.use_keywords'] ='Use keywords';
$_lang['setting_seopro.use_keywords_desc'] ='Enable/disable the keywords field and keywords counters.';
2 changes: 2 additions & 0 deletions core/components/seopro/lexicon/ru/default.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
$_lang['setting_seopro.title_format'] ='Format used for the meta title.';
$_lang['setting_seopro.title_format_desc'] ='Here you can specify the format used for the meta title used
in Google/Yandex preview. The rendered output is also available on frontend with [[+seoPro.title]].';
$_lang['setting_seopro.use_keywords'] ='Use keywords';
$_lang['setting_seopro.use_keywords_desc'] ='Enable/disable the keywords field and keywords counters.';