Skip to content

Commit

Permalink
Merge pull request #3 from berkanumutlu/feature-2024-03-23
Browse files Browse the repository at this point in the history
Feature #2
  • Loading branch information
berkanumutlu committed Apr 1, 2024
2 parents 0bf516c + 652c3d5 commit ddf79ee
Show file tree
Hide file tree
Showing 10 changed files with 567 additions and 78 deletions.
106 changes: 100 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@

# PHP Sitemap Generator

This project can be used to generate sitemaps. It can build a sitemap file from a list of URLs. The URLs may have attached the last modification date, change frequency, priority and image properties.
This project can be used to generate sitemaps. It can build a sitemap file from a list of URLs. The URLs may have attached the last modification date, change frequency, priority and image properties. URL limits can be added to sitemap files, gzip compression can be done, and the content of the robots.txt file can be updated automatically and the sitemap file can submit to search engines.

Sitemap format: http://www.sitemaps.org/protocol.html

## Sitemap file

After creating your sitemap.xml file, you should add the XML file to your `robots.txt`.
~~After creating your sitemap.xml file, you should add the XML file to your `robots.txt`.~~

Line for the robots.txt:
~~Line for the robots.txt:~~

```
Sitemap: http://example.com/sitemap/sitemap.xml
```
~~Sitemap: http://example.com/sitemap/sitemap.xml~~

Now you can create or update your robots.txt automatically.

## Output

Expand Down Expand Up @@ -86,6 +86,100 @@ Example output when generating a sitemap
</urlset>
```

Example output when generating sitemap with gzip

```XML
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<!--Created with PHP Sitemap Generator by Berkan Ümütlü (https://github.com/berkanumutlu/php-sitemap-generator)-->
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-1.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-10.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-11.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-12.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-13.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-14.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-15.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-16.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-17.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-2.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-3.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-4.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-5.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-6.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-7.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-8.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
<sitemap>
<loc>http://example.com/sitemap/index/sitemap-9.xml</loc>
<lastmod>2024-03-29</lastmod>
<priority>0.5</priority>
</sitemap>
</sitemapindex>
```

## Screenshots

![screenshot01](screenshots/screenshot01.png)
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"require": {
"ext-json": "*",
"ext-pdo": "*",
"ext-mbstring": "*"
"ext-mbstring": "*",
"ext-curl": "*",
"ext-zlib": "*"
}
}
Binary file modified screenshots/screenshot01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/screenshot02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion src/ajax.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
define('BASE_PATH', __DIR__.'/');
const BASE_PATH = __DIR__.'/';
require_once '../vendor/autoload.php';
require_once 'config/db.php';

Expand Down Expand Up @@ -53,6 +53,12 @@
if (!empty($_POST['url_limit'])) {
$sitemap_generator->setUrlLimit(trim($_POST['url_limit']));
}
if (!empty($_POST['create_gzip_file'])) {
$sitemap_generator->setCreateGzipFile(trim($_POST['create_gzip_file']));
}
if (!empty($_POST['create_robots_txt'])) {
$sitemap_generator->setCreateRobotsTxt(trim($_POST['create_robots_txt']));
}
/*
* Adding base url
*/
Expand Down Expand Up @@ -108,4 +114,16 @@
}
echo $response->toJson();
return true;
}
if (!empty($_POST['submit_sitemap'])) {
$response = new \App\Library\Response();
if (empty($_POST['sitemap_url'])) {
$response->setMessage('Sitemap not found.');
echo $response->toJson();
exit();
}
$sitemap_generator = new SitemapGenerator();
$response = $sitemap_generator->submit_sitemap($_POST['sitemap_url']);
echo $response->toJson();
return true;
}
56 changes: 54 additions & 2 deletions src/assets/web/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ jQuery(function ($) {
input_domain.val(input_domain_val);
}
});
$("form").submit(function (event) {
$("form.sitemap-generator").submit(function (event) {
event.preventDefault();
let submit_sitemap_button = $('.sitemap-submit-button');
submit_sitemap_button.hide();
let alert_submit_button = $('.alert-message.alert-sitemap-submit-button');
alert_submit_button.hide();
var url = $(this).attr('action');
var method = $(this).attr('method');
var formData = $(this).serializeArray();
Expand All @@ -55,7 +59,7 @@ jQuery(function ($) {
data: formData,
dataType: "JSON"
}).done(function (response) {
let alert = $('.alert-message');
let alert = $('.alert-message.alert-sitemap');
let alertIcon = alert.find('.alert .alert-icon');
let alertText = alert.find('.alert .text');
alert.hide();
Expand All @@ -65,6 +69,54 @@ jQuery(function ($) {
alertText.html(response.message);
alert.show();
}
if (response.hasOwnProperty('status')) {
if (response.status) {
alert.find('.alert').removeClass('alert-danger').addClass('alert-success');
alertIcon.closest('.alert-success').show();
alertIcon.closest('.alert-danger').hide();
submit_sitemap_button.show();
} else {
alert.find('.alert').removeClass('alert-success').addClass('alert-danger');
alertIcon.closest('.alert-danger').show();
alertIcon.closest('.alert-success').hide();
}
}
if (response.data.hasOwnProperty('file_url')) {
submit_sitemap_button.attr('data-sitemap-url', response.data.file_url)
}
});
});
$(".sitemap-submit-button").on("click", function (event) {
event.preventDefault();
var url = $(this).attr('href');
var sitemap_url = $(this).data('sitemap-url');
$.ajax({
url: url,
type: "POST",
data: {'submit_sitemap': 1, 'sitemap_url': sitemap_url},
dataType: "JSON"
}).done(function (response) {
let alert = $('.alert-message.alert-sitemap-submit-button');
let alertIcon = alert.find('.alert .alert-icon');
let alertText = alert.find('.alert .text');
alert.hide();
alertIcon.hide();
alertText.text();
if (response.hasOwnProperty('message')) {
alertText.html(response.message);
alert.show();
}
if (response.hasOwnProperty('data')) {
if ($.isArray(response.data)) {
var list_html = '<ul class="list-group list-unstyled mt-3">';
$.each(response.data, function (key, value) {
list_html += '<li class="mb-3"><div><strong>URL</strong>: ' + value.url + '</div><div><strong>Response</strong>: ' + value.response + '</div></li>';
});
list_html += '</ul>';
alertText.append(list_html);
}
alert.show();
}
if (response.hasOwnProperty('status')) {
if (response.status) {
alert.find('.alert').removeClass('alert-danger').addClass('alert-success');
Expand Down
Loading

0 comments on commit ddf79ee

Please sign in to comment.