Skip to content

Commit 88de39b

Browse files
authored
Merge pull request #576 from mahmoudmagdy1-1/component_rel
Add follow/nofollow attribute control for web links plus test
2 parents c7b5a09 + 76683d4 commit 88de39b

File tree

6 files changed

+52
-6
lines changed

6 files changed

+52
-6
lines changed

jorobo.dist.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ source = src
44
target = package
55

66
; Create a pre-release of the extension on GitHub
7-
; Add your personal GitHub access tocken
7+
; Add your personal GitHub access token
88
; and add Release to the target (separated by space) above
99
[github]
1010
remote = origin

src/administrator/components/com_weblinks/forms/weblink.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,16 @@
234234
name="jbasic"
235235
label="COM_WEBLINKS_FIELDSET_OPTIONS"
236236
>
237+
<field
238+
name="follow"
239+
type="list"
240+
label="COM_WEBLINKS_FIELD_FOLLOW_LABEL"
241+
default="nofollow"
242+
>
243+
<option value="follow">COM_WEBLINKS_FIELD_VALUE_FOLLOW</option>
244+
<option value="nofollow">COM_WEBLINKS_FIELD_VALUE_NOFOLLOW</option>
245+
</field>
246+
237247
<field
238248
name="target"
239249
type="list"

src/administrator/language/en-GB/com_weblinks.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ COM_WEBLINKS_FIELD_SHOW_CAT_TAGS_LABEL="Category Tags"
4848
COM_WEBLINKS_FIELD_SHOW_TAGS_LABEL="Tags"
4949
COM_WEBLINKS_FIELD_TARGET_DESC="Target browser window when the link is selected."
5050
COM_WEBLINKS_FIELD_TARGET_LABEL="Target"
51+
COM_WEBLINKS_FIELD_FOLLOW_LABEL="Follow/No Follow"
52+
COM_WEBLINKS_FIELD_VALUE_FOLLOW="Follow"
53+
COM_WEBLINKS_FIELD_VALUE_NOFOLLOW="No Follow"
5154
COM_WEBLINKS_FIELD_URL_LABEL="URL"
5255
COM_WEBLINKS_FIELD_VALUE_REPORTED="Reported"
5356
COM_WEBLINKS_FIELD_VERSION_LABEL="Revision"

src/components/com_weblinks/tmpl/category/default_items.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@
129129
switch ($item->params->get('target', $this->params->get('target'))) {
130130
case 1:
131131
// Open in a new window
132-
echo '<a href="' . $link . '" target="_blank" class="' . $menuclass . '" rel="nofollow">' .
133-
$this->escape($item->title) . '</a>';
132+
echo '<a href="' . $link . '" target="_blank" class="' . $menuclass . '"
133+
rel="' . $item->params->get('follow', 'nofollow') . '">'
134+
. $this->escape($item->title) . '</a>';
134135

135136
break;
136137
case 2:
@@ -157,8 +158,9 @@
157158
break;
158159
default:
159160
// Open in parent window
160-
echo '<a href="' . $link . '" class="' . $menuclass . '" rel="nofollow">' .
161-
$this->escape($item->title) . ' </a>';
161+
echo '<a href="' . $link . '" target="_blank" class="' . $menuclass . '"
162+
rel="' . $item->params->get('follow', 'nofollow') . '">'
163+
. $this->escape($item->title) . '</a>';
162164

163165
break;
164166
}

src/components/com_weblinks/tmpl/weblink/default.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
<div itemprop="articleBody">
5353
<div class="p-3">
54-
<a href="<?php echo $weblinkUrl; ?>" target="_blank" itemprop="url">
54+
<a href="<?php echo $weblinkUrl; ?>" target="_blank" rel="<?php echo $this->params->get('follow', 'nofollow'); ?>" itemprop="url">
5555
<?php echo $weblinkUrl; ?>
5656
</a>
5757
</div>

tests/cypress/integration/site/components/com_weblinks/Weblinks.cy.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,36 @@ describe('Test in frontend that the weblinks', () => {
9797
});
9898
});
9999
});
100+
it('should show correct rel attribute for follow', () => {
101+
// Set follow parameter to 'follow'
102+
cy.db_updateExtensionParameter('follow', 'follow', 'com_weblinks');
103+
// Create test weblink with title and URL
104+
cy.db_createWeblink({
105+
title: 'Follow Test',
106+
url: 'https://follow.example',
107+
}).then((weblink) => {
108+
// Visit weblink category page
109+
cy.visit(`/index.php?option=com_weblinks&view=category&id=${weblink.catid}`);
110+
// Verify rel attribute is 'follow'
111+
cy.contains('a', 'Follow Test')
112+
.should('have.attr', 'rel', 'follow');
113+
});
114+
});
115+
116+
it('should show correct rel attribute for nofollow', () => {
117+
// Set follow parameter to 'nofollow'
118+
cy.db_updateExtensionParameter('follow', 'nofollow', 'com_weblinks');
119+
// Create test weblink with title and URL
120+
cy.db_createWeblink({
121+
title: 'Nofollow Test',
122+
url: 'https://nofollow.example',
123+
}).then((weblink) => {
124+
// Visit weblink category page
125+
cy.visit(`/index.php?option=com_weblinks&view=category&id=${weblink.catid}`);
126+
// Verify rel attribute is 'nofollow'
127+
cy.contains('a', 'Nofollow Test')
128+
.should('have.attr', 'rel', 'nofollow');
129+
});
130+
});
100131
});
101132

0 commit comments

Comments
 (0)