Skip to content

Commit 22d8d29

Browse files
committed
[ADD] Manage robots.txt file via Admin Panel.
1 parent ccbbfda commit 22d8d29

File tree

11 files changed

+199
-74
lines changed

11 files changed

+199
-74
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,26 @@ this plugin provides the tools you need for a competitive edge in the digital la
2121

2222
## Features
2323

24+
- [x] Custom SEO Title and Description.
25+
- [x] Canonical URL Implementation.
2426
- [x] Automatic META Tags Generation.
2527
- [x] XML Sitemap Generation.
2628
- [x] Include or exclude documents from xml sitemap (via Searchable).
27-
- [x] On page Robots index/follow settings.
28-
- [x] Custom SEO Title and Description.
29-
- [x] Canonical URL Implementation.
29+
- [ ] On page Robots index/follow settings.
3030
- [x] Noindex for Pagination and Custom $_GET Parameters.
31+
- [x] 30x Redirects for Resolving 404 Errors.
3132
- [x] HTTP(S) and WWW Redirects.
33+
- [x] Manage robots.txt file via Admin Panel.
3234
- [ ] Open Graph Protocol Integration.
33-
- [x] 30x Redirects for Resolving 404 Errors.
3435
- [ ] SEO Dashboard and Reporting.
3536
- [ ] Social Media Integration Metrics.
3637
- [ ] AI-Powered SEO Recommendations.
3738
- [ ] Featured Snippets Optimization.
3839
- [ ] Local Business Schema Markup.
40+
- [ ] SEO Health Check
41+
- [ ] Rich Snippets (Schema Markup) Support
42+
- [ ] Performance Optimization Recommendations
43+
- [ ] Real-time SEO Analytics
3944

4045
## Install by artisan package installer
4146

composer.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
"license": "GPL-3.0",
44
"type": "EvolutionCMS-Plugin",
55
"description": "Evocms package for collection of SEO Tools for Evolution CMS.",
6-
"keywords": ["evocms", "evolution-cms", "seo"],
6+
"keywords": ["evocms", "evolution-cms", "seo", "evolution-cms-seo", "seo-tools", "cms-seo", "evolution-cms-plugin"],
77
"authors": [
88
{
99
"name": "Serhii Korneliuk",
1010
"email": "info@seigerit.com"
1111
}
1212
],
1313
"require": {
14-
"php": "^8.1"
14+
"php": ">=8.2"
1515
},
1616
"autoload": {
1717
"psr-4": {
@@ -28,7 +28,12 @@
2828
}
2929
}
3030
},
31+
"config": {
32+
"exclude-files": [
33+
"docs/*"
34+
]
35+
},
3136
"scripts": {
3237
"post-autoload-dump": []
3338
}
34-
}
39+
}

docs/pages/index.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,26 @@ this plugin provides the tools you need for a competitive edge in the digital la
2828

2929
## Features
3030

31+
- [x] Custom SEO Title and Description.
32+
- [x] Canonical URL Implementation.
3133
- [x] Automatic META Tags Generation.
3234
- [x] XML Sitemap Generation.
3335
- [x] Include or exclude documents from xml sitemap (via Searchable).
34-
- [x] On page Robots index/follow settings.
35-
- [x] Custom SEO Title and Description.
36-
- [x] Canonical URL Implementation.
36+
- [ ] On page Robots index/follow settings.
3737
- [x] Noindex for Pagination and Custom $_GET Parameters.
38+
- [x] 30x Redirects for Resolving 404 Errors.
3839
- [x] HTTP(S) and WWW Redirects.
40+
- [x] Manage robots.txt file via Admin Panel.
3941
- [ ] Open Graph Protocol Integration.
40-
- [ ] 301 Redirects for Resolving 404 Errors.
4142
- [ ] SEO Dashboard and Reporting.
4243
- [ ] Social Media Integration Metrics.
4344
- [ ] AI-Powered SEO Recommendations.
4445
- [ ] Featured Snippets Optimization.
4546
- [ ] Local Business Schema Markup.
47+
- [ ] SEO Health Check
48+
- [ ] Rich Snippets (Schema Markup) Support
49+
- [ ] Performance Optimization Recommendations
50+
- [ ] Real-time SEO Analytics
4651

4752
## Support
4853

lang/en/global.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'noindex_get' => 'Do not index $_GET',
2323
'noindex_get_help' => 'Specify the list of $_GET parameters separated by commas. Pages with these options will be banned from indexing.',
2424
'not_writable' => 'The file ../core/custom/config/seiger/settings/sSeo.php is not writable.',
25+
'not_writable_robots' => 'The file ../robots.txt is not writable.',
2526
'old_url' => 'Old URL',
2627
'paginates_get' => 'Pagination pages',
2728
'paginates_get_help' => 'A parameter indicating that this page is a pagination page. Default page.',
@@ -33,8 +34,12 @@
3334
'redirects_enabled_help' => 'Allows or disables the use of SEO redirects on the site.',
3435
'redirects_help' => 'Setting up SEO site redirects.',
3536
'redirects_icon' => 'fa fa-retweet',
37+
'robots' => 'Robots',
38+
'robots_help' => 'Configuring the robots.txt file.',
39+
'robots_icon' => 'fa fas fa-robot',
40+
'robots_text_empty' => 'The text for the robots.txt file cannot be empty.',
3641
'site_key' => 'Site Key',
37-
'success_updated' => 'Redirects successfully updated!',
42+
'success_updated' => 'Data successfully updated!',
3843
'title' => 'SEO',
3944
'using_www' => 'Using WWW',
4045
'without_www' => 'Without WWW',

lang/ru/global.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
'ignore' => 'Не враховувати',
1414
'manage_www' => 'Керування WWW',
1515
'message_for_large_number_redirects' => 'Занадто велика кількість редіректів може негативно вплинути на швидкість роботи сайту. <br>Зверніть увагу: вказані редіректи застосовуються лише у випадку, якщо сторінку не знайдено (404).',
16-
'meta_description' => 'Метаопис',
16+
'meta_description' => 'SEO Опис',
1717
'meta_description_help' => 'Метаопис безпосередньо не впливає на рейтинг веб-сторінки в результатах пошуку, але може впливати на кількість кліків, які отримує сторінка, що може опосередковано впливати на її рейтинг. Намагайтеся отримати метаопис довжиною близько 155 символів.',
18-
'meta_title' => 'Мета тайтл',
18+
'meta_title' => 'SEO Заголовок',
1919
'meta_title_help' => 'Хороший мета-заголовок має бути коротким і точним описом вмісту сторінки. Прагніть до 50-60 символів, включаючи пробіли.',
2020
'new_url' => 'Нова URL-адреса',
2121
'no_redirects_provided' => 'Редіректи не були надані. Будь ласка, додайте хоча б один редірект перед збереженням.',
2222
'noindex_get' => 'Не індексувати $_GET',
2323
'noindex_get_help' => 'Вкажіть список $_GET параметрів через кому. Сторінки з цими параметрами будуть заборонені для індексації.',
2424
'not_writable' => 'Файл ../core/custom/config/seiger/settings/sSeo.php не доступний для запису.',
25+
'not_writable_robots' => 'Файл ../robots.txt не доступний для запису.',
2526
'old_url' => 'Стара URL-адреса',
2627
'paginates_get' => 'Сторінки пагінації',
2728
'paginates_get_help' => 'Параметр, що вказує на те, що дана сторінка є сторінкою пагінації. Типово page.',
@@ -33,8 +34,12 @@
3334
'redirects_enabled_help' => 'Дозволяє або забороняє використання SEO редіректів на сайті.',
3435
'redirects_help' => 'Налаштування SEO редіректів сайта.',
3536
'redirects_icon' => 'fa fa-retweet',
37+
'robots' => 'Роботс',
38+
'robots_help' => 'Налаштування файлу robots.txt.',
39+
'robots_icon' => 'fa fas fa-robot',
40+
'robots_text_empty' => 'Текст для файлу robots.txt не може бути порожнім.',
3641
'site_key' => 'Ключ сайту',
37-
'success_updated' => 'Редіректи успішно оновлено!',
42+
'success_updated' => 'Дані успішно оновлено!',
3843
'title' => 'SEO',
3944
'using_www' => 'З WWW',
4045
'without_www' => 'Без WWW',

lang/uk/global.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@
1313
'ignore' => 'Не враховувати',
1414
'manage_www' => 'Керування WWW',
1515
'message_for_large_number_redirects' => 'Занадто велика кількість редіректів може негативно вплинути на швидкість роботи сайту. <br>Зверніть увагу: вказані редіректи застосовуються лише у випадку, якщо сторінку не знайдено (404).',
16-
'meta_description' => 'Метаопис',
16+
'meta_description' => 'SEO Опис',
1717
'meta_description_help' => 'Метаопис безпосередньо не впливає на рейтинг веб-сторінки в результатах пошуку, але може впливати на кількість кліків, які отримує сторінка, що може опосередковано впливати на її рейтинг. Намагайтеся отримати метаопис довжиною близько 155 символів.',
18-
'meta_title' => 'Мета тайтл',
18+
'meta_title' => 'SEO Заголовок',
1919
'meta_title_help' => 'Хороший мета-заголовок має бути коротким і точним описом вмісту сторінки. Прагніть до 50-60 символів, включаючи пробіли.',
2020
'new_url' => 'Нова URL-адреса',
2121
'no_redirects_provided' => 'Редіректи не були надані. Будь ласка, додайте хоча б один редірект перед збереженням.',
2222
'noindex_get' => 'Не індексувати $_GET',
2323
'noindex_get_help' => 'Вкажіть список $_GET параметрів через кому. Сторінки з цими параметрами будуть заборонені для індексації.',
2424
'not_writable' => 'Файл ../core/custom/config/seiger/settings/sSeo.php не доступний для запису.',
25+
'not_writable_robots' => 'Файл ../robots.txt не доступний для запису.',
2526
'old_url' => 'Стара URL-адреса',
2627
'paginates_get' => 'Сторінки пагінації',
2728
'paginates_get_help' => 'Параметр, що вказує на те, що дана сторінка є сторінкою пагінації. Типово page.',
@@ -33,8 +34,12 @@
3334
'redirects_enabled_help' => 'Дозволяє або забороняє використання SEO редіректів на сайті.',
3435
'redirects_help' => 'Налаштування SEO редіректів сайта.',
3536
'redirects_icon' => 'fa fa-retweet',
37+
'robots' => 'Роботс',
38+
'robots_help' => 'Налаштування файлу robots.txt.',
39+
'robots_icon' => 'fa fas fa-robot',
40+
'robots_text_empty' => 'Текст для файлу robots.txt не може бути порожнім.',
3641
'site_key' => 'Ключ сайту',
37-
'success_updated' => 'Редіректи успішно оновлено!',
42+
'success_updated' => 'Дані успішно оновлено!',
3843
'title' => 'SEO',
3944
'using_www' => 'З WWW',
4045
'without_www' => 'Без WWW',

plugins/sSeoPlugin.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,18 @@
9494
/**
9595
* Redirects
9696
*/
97-
Event::listen('evolution.OnPageNotFound', function ($params) {
98-
$requestUri = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
99-
$siteKey = evo()->getConfig('check_sMultisite', false) ? evo()->getConfig('site_key', 'default') : 'default';
100-
$redirect = sRedirect::where('site_key', $siteKey)->where('old_url', $requestUri)->first();
101-
102-
if ($redirect) {
103-
evo()->sendRedirect($redirect->new_url, 0, '', $redirect->type);
104-
exit;
105-
}
106-
});
97+
if (config('seiger.settings.sSeo.redirects_enabled', 0) == 1) {
98+
Event::listen('evolution.OnPageNotFound', function ($params) {
99+
$requestUri = trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/');
100+
$siteKey = evo()->getConfig('check_sMultisite', false) ? evo()->getConfig('site_key', 'default') : 'default';
101+
$redirect = sRedirect::where('site_key', $siteKey)->where('old_url', $requestUri)->first();
102+
103+
if ($redirect) {
104+
evo()->sendRedirect($redirect->new_url, 0, '', $redirect->type);
105+
exit;
106+
}
107+
});
108+
}
107109

108110
Event::listen('evolution.OnHeadWebDocumentRender', function($params) {
109111
// Meta Canonical
@@ -121,10 +123,6 @@
121123
return view('sSeo::partials.headWebDocument', compact('canonical', 'robots', 'title', 'description'))->render();
122124
});
123125

124-
Event::listen('evolution.OnDocFormSave', function($params) {
125-
sSeo::generateSitemap();
126-
});
127-
128126
/**
129127
* Add Menu item
130128
*/
@@ -133,7 +131,7 @@
133131
'sseo',
134132
'tools',
135133
'<i class="'.__('sSeo::global.icon').'"></i><span class="menu-item-text">'.__('sSeo::global.title').'</span>',
136-
sSeo::route('sSeo.redirects'),
134+
config('seiger.settings.sSeo.redirects_enabled', 0) == 1 ? sSeo::route('sSeo.redirects') : sSeo::route('sSeo.configure'),
137135
__('sSeo::global.title'),
138136
"",
139137
"",
@@ -173,6 +171,7 @@
173171
$data = array_merge(['resource_id' => $params['id'], 'resource_type' => 'document'], request()->input('sseo', []));
174172
sSeo::updateSeoFields($data);
175173
}
174+
sSeo::generateSitemap();
176175
});
177176
Event::listen('evolution.sCommerceAfterProductContentSave', function($params) {
178177
if (isset($params['product']) && $params['product']->id) {

src/Controllers/sSeoController.php

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@
1515
*/
1616
class sSeoController
1717
{
18-
/**
19-
* Returns the view for the index page.
20-
*
21-
* @return mixed The view for the index page.
22-
*/
23-
public function index()
24-
{
25-
$GLOBALS['SystemAlertMsgQueque'] = &$_SESSION['SystemAlertMsgQueque'];
26-
return $this->view('index');
27-
}
28-
2918
/**
3019
* Returns the view for the redirects page.
3120
*
@@ -45,35 +34,26 @@ public function redirects()
4534
}
4635

4736
/**
48-
* Updates the configure file with the new values.
37+
* Returns the view for the index page.
4938
*
50-
* @return \Illuminate\Http\RedirectResponse The redirect response to the previous page.
39+
* @return mixed The view for the index page.
5140
*/
52-
public function updateConfigure()
41+
public function robots()
5342
{
54-
$string = '<?php return [' . "\n";
55-
56-
$string .= "\t" . '"manage_www" => ' . (int)request()->get('manage_www', 0) . ',' . "\n";
57-
$string .= "\t" . '"paginates_get" => "' . request()->get('paginates_get', 'page') . '",' . "\n";
58-
59-
$noindex_get = explode(',', request()->get('noindex_get', ''));
60-
$string .= "\t" . '"noindex_get" => [' . "\n";
61-
foreach ($noindex_get as $item) {
62-
$string .= "\t\t" . '"' . trim($item) . '",' . "\n";
63-
}
64-
$string .= "\t" . '],' . "\n";
65-
66-
$string .= "\t" . '"redirects_enabled" => ' . (int)request()->get('redirects_enabled', 0) . ',' . "\n";
67-
68-
$string .= '];';
69-
70-
// Save config
71-
$handle = fopen(EVO_CORE_PATH . 'custom/config/seiger/settings/sSeo.php', "w");
72-
fwrite($handle, $string);
73-
fclose($handle);
43+
$GLOBALS['SystemAlertMsgQueque'] = &$_SESSION['SystemAlertMsgQueque'];
44+
$robots = file_get_contents(MODX_BASE_PATH . 'robots.txt') ?: '';
45+
return $this->view('index', compact('robots'));
46+
}
7447

75-
evo()->clearCache('full');
76-
return redirect()->back();
48+
/**
49+
* Returns the view for the index page.
50+
*
51+
* @return mixed The view for the index page.
52+
*/
53+
public function configure()
54+
{
55+
$GLOBALS['SystemAlertMsgQueque'] = &$_SESSION['SystemAlertMsgQueque'];
56+
return $this->view('index');
7757
}
7858

7959
/**
@@ -171,6 +151,63 @@ public function updateRedirects()
171151
return redirect()->back()->with('success', trans('sSeo::global.success_updated'));
172152
}
173153

154+
155+
/**
156+
* Update the content of the robots.txt file.
157+
*
158+
* This method handles the update of the robots.txt file by taking the
159+
* content passed from the request, validating that it is not empty,
160+
* and then writing it to the `robots.txt` file. If the input is empty,
161+
* it redirects the user back with an error message. Otherwise, it writes
162+
* the content to the file and returns a success message.
163+
*
164+
* @return \Illuminate\Http\RedirectResponse
165+
*/
166+
public function updateRobots()
167+
{
168+
$robots = request()->input('robots', []);
169+
170+
if (empty($robots)) {
171+
return redirect()->back()->with('error', trans('sSeo::global.robots_text_empty'));
172+
}
173+
174+
file_put_contents(MODX_BASE_PATH . 'robots.txt', $robots);
175+
176+
return redirect()->back()->with('success', trans('sSeo::global.success_updated'));
177+
}
178+
179+
/**
180+
* Updates the configure file with the new values.
181+
*
182+
* @return \Illuminate\Http\RedirectResponse The redirect response to the previous page.
183+
*/
184+
public function updateConfigure()
185+
{
186+
$string = '<?php return [' . "\n";
187+
188+
$string .= "\t" . '"manage_www" => ' . (int)request()->get('manage_www', 0) . ',' . "\n";
189+
$string .= "\t" . '"paginates_get" => "' . request()->get('paginates_get', 'page') . '",' . "\n";
190+
191+
$noindex_get = explode(',', request()->get('noindex_get', ''));
192+
$string .= "\t" . '"noindex_get" => [' . "\n";
193+
foreach ($noindex_get as $item) {
194+
$string .= "\t\t" . '"' . trim($item) . '",' . "\n";
195+
}
196+
$string .= "\t" . '],' . "\n";
197+
198+
$string .= "\t" . '"redirects_enabled" => ' . (int)request()->get('redirects_enabled', 0) . ',' . "\n";
199+
200+
$string .= '];';
201+
202+
// Save config
203+
$handle = fopen(EVO_CORE_PATH . 'custom/config/seiger/settings/sSeo.php', "w");
204+
fwrite($handle, $string);
205+
fclose($handle);
206+
207+
evo()->clearCache('full');
208+
return redirect()->back();
209+
}
210+
174211
/**
175212
* Returns the view for the specified template.
176213
*

src/Http/routes.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
use Seiger\sSeo\Controllers\sSeoController;
55

66
Route::middleware('mgr')->prefix('sseo')->name('sSeo.')->group(function () {
7-
Route::get('/', [sSeoController::class, 'redirects'])->name('redirects');
8-
Route::get('/configure', [sSeoController::class, 'index'])->name('index');
7+
Route::get('/redirects', [sSeoController::class, 'redirects'])->name('redirects');
8+
Route::get('/robots', [sSeoController::class, 'robots'])->name('robots');
9+
Route::get('/configure', [sSeoController::class, 'configure'])->name('configure');
910
Route::post('/redirects', [sSeoController::class, 'updateRedirects'])->name('update-redirects');
11+
Route::post('/robots', [sSeoController::class, 'updateRobots'])->name('update-robots');
1012
Route::post('/configure', [sSeoController::class, 'updateConfigure'])->name('update-configure');
1113
});

0 commit comments

Comments
 (0)