Skip to content

Commit cac4ce2

Browse files
authored
Merge pull request #25 from catalyst/fix-ci-issues-#20
Fix CI and autoload issues
2 parents 8cd0a13 + 59ec684 commit cac4ce2

File tree

8 files changed

+94
-96
lines changed

8 files changed

+94
-96
lines changed

classes/local/hook/output/before_standard_head_html_generation.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
namespace tool_seo\local\hook\output;
1818

19+
use tool_seo\local\seo;
20+
1921
/**
2022
* Allows plugins to add any elements to the page <head> html tag
2123
*
@@ -29,15 +31,13 @@ class before_standard_head_html_generation {
2931
/**
3032
* Callback that adds a custom html header tag to each page.
3133
*
32-
* @param \core\hook\output\standard_head_html_prepend $hook
34+
* @param \core\hook\output\before_standard_head_html_generation $hook
3335
*/
3436
public static function callback(\core\hook\output\before_standard_head_html_generation $hook): void {
35-
global $PAGE, $CFG;
36-
37-
require_once($CFG->dirroot . '/admin/tool/seo/lib.php');
37+
global $PAGE;
3838

3939
// If URL should not be indexed, add the noindex meta tag to page.
40-
if (tool_seo_is_url_indexable($PAGE->url->get_path()) == false) {
40+
if (!seo::is_url_indexable($PAGE->url->get_path())) {
4141
$hook->add_html('<meta name="robots" content="noindex, nofollow" />');
4242
}
4343
}

classes/local/seo.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace tool_seo\local;
18+
19+
use dml_exception;
20+
21+
/**
22+
* SEO utils class.
23+
*
24+
* @package tool_seo
25+
* @author Andrew Madden <andrewmadden@catalyst-au.net>
26+
* @copyright 2019 Catalyst IT
27+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28+
*/
29+
class seo {
30+
/**
31+
* Checks whether the current URL is listed in the URLs to not be indexed in admin tools.
32+
*
33+
* @param string $currentpath The path component of the current URL to compare against.
34+
* @return bool Returns true if the URL should be indexable by search engines.
35+
*/
36+
public static function is_url_indexable($currentpath): bool {
37+
38+
// Get the list of URLs to be excluded from the admin settings.
39+
try {
40+
$nonindexableurlstring = get_config('tool_seo', 'nonindexable');
41+
} catch (dml_exception $e) {
42+
return true;
43+
}
44+
45+
$nonindexableurls = array_map('trim', explode(PHP_EOL, $nonindexableurlstring));
46+
47+
$currentpathliteral = preg_quote($currentpath, '/');
48+
49+
foreach ($nonindexableurls as $nonindexableurl) {
50+
// If the url is empty, ignore.
51+
if ($nonindexableurl == '') {
52+
continue;
53+
}
54+
55+
// Checks if a non-indexable url is part of the current path.
56+
if (strpos($currentpath, $nonindexableurl) !== false) {
57+
return false;
58+
}
59+
60+
// Checks if the current path is a slug of the non-indexable url.
61+
if (preg_match("/^.*$currentpathliteral$/", $nonindexableurl)) {
62+
return false;
63+
}
64+
}
65+
66+
return true;
67+
}
68+
}

classes/privacy/provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class provider implements \core_privacy\local\metadata\null_provider {
4040
*
4141
* @return string
4242
*/
43-
public static function get_reason() : string {
43+
public static function get_reason(): string {
4444
return 'privacy:metadata';
4545
}
4646
}

lang/en/tool_seo.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
2525

26-
$string['pluginname'] = 'SEO';
27-
28-
// Settings.
2926
$string['nonindexable'] = 'Include URLs not to be indexed by search engines.';
3027
$string['nonindexable_help'] = 'List of URLs that will not be indexed and profiled by search engines. Enter each URL on a new line.';
28+
$string['pluginname'] = 'SEO';
29+
$string['privacy:metadata'] = 'The SEO plugin does not store any personal data.';
3130
$string['robotstxt'] = 'robots.txt';
3231
$string['robotstxt_help'] = 'The raw robots.txt file can be entered here. For this to work you must have Moodle setup to handle error pages.';
33-
34-
// Privacy.
35-
$string['privacy:metadata'] = 'The SEO plugin does not store any personal data.';
36-

lib.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
* @copyright 2019 Andrew Madden <andrewmadden@catalyst-au.net>
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
24+
use tool_seo\local\seo;
2425

2526
defined('MOODLE_INTERNAL') || die();
2627

27-
require_once(__DIR__ . '/locallib.php');
28-
2928
/**
3029
* Callback that adds a custom html header tag to each page.
3130
*
@@ -36,7 +35,7 @@ function tool_seo_before_standard_html_head() {
3635
global $PAGE;
3736

3837
// If URL should not be indexed, add the noindex meta tag to page.
39-
if (tool_seo_is_url_indexable($PAGE->url->get_path()) == false) {
38+
if (!seo::is_url_indexable($PAGE->url->get_path())) {
4039
return '<meta name="robots" content="noindex, nofollow" />';
4140
}
4241

locallib.php

Lines changed: 0 additions & 65 deletions
This file was deleted.

tests/noindex_test.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
namespace tool_seo;
2727

28+
use tool_seo\local\seo;
29+
2830
/**
2931
* Test case class for the noindex tool.
3032
*
@@ -33,8 +35,11 @@
3335
* @copyright 2019 Catalyst IT
3436
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3537
*/
36-
class noindex_test extends \advanced_testcase {
38+
final class noindex_test extends \advanced_testcase {
3739

40+
/**
41+
* Sets up test.
42+
*/
3843
protected function setUp(): void {
3944
parent::setUp();
4045
// Set up non-indexable array in config.
@@ -53,13 +58,11 @@ protected function setUp(): void {
5358
* @dataProvider get_noindex_url_testcases
5459
* @param string $url A URL path representing a moodle page url.
5560
* @param bool $expected True if the URL should be indexable.
61+
* @covers \tool_seo\local\seo::is_url_indexable
5662
*/
57-
public function test_nonindexable_url_configuration($url, $expected) {
63+
public function test_nonindexable_url_configuration($url, $expected): void {
5864
$this->resetAfterTest(true);
59-
60-
require_once(__DIR__ . '/../locallib.php');
61-
$result = tool_seo_is_url_indexable($url);
62-
65+
$result = seo::is_url_indexable($url);
6366
$this->assertEquals($expected, $result);
6467
}
6568

@@ -69,14 +72,12 @@ public function test_nonindexable_url_configuration($url, $expected) {
6972
* @dataProvider get_noindex_url_testcases
7073
* @param string $url A URL path representing a moodle page url.
7174
* @param bool $expected True if the URL should be indexable.
75+
* @covers \tool_seo\local\seo::is_url_indexable
7276
*/
73-
public function test_empty_configuration($url, $expected) {
77+
public function test_empty_configuration($url, $expected): void {
7478
$this->resetAfterTest(true);
7579
set_config('nonindexable', "", 'tool_seo');
76-
77-
require_once(__DIR__ . '/../locallib.php');
78-
$result = tool_seo_is_url_indexable($url);
79-
80+
$result = seo::is_url_indexable($url);
8081
$this->assertTrue($result);
8182
}
8283

@@ -85,7 +86,7 @@ public function test_empty_configuration($url, $expected) {
8586
*
8687
* @return array
8788
*/
88-
public function get_noindex_url_testcases() {
89+
public static function get_noindex_url_testcases(): array {
8990
return [
9091
// Exact matches.
9192
'Login URL' => ['/login/index.php', false],

version.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626

27-
$plugin->version = 2024021902;
28-
$plugin->release = 2024021902; // Match release exactly to version.
27+
$plugin->version = 2024021903;
28+
$plugin->release = 2024021903; // Match release exactly to version.
2929
$plugin->requires = 2022112800; // Moodle 4.1.
3030
$plugin->component = 'tool_seo';
3131
$plugin->maturity = MATURITY_STABLE;
32-
$plugin->supported = [401, 403]; // Supports Moodle 4.1 or later.
32+
$plugin->supported = [401, 404]; // Supports Moodle 4.1 or later.

0 commit comments

Comments
 (0)