Version Description
(Jun 23, 2015) = * Added donation link * Made the sitemaps compatible down to ie7 * Minor changes in php, css and js
Download this release
Release Info
Developer | Webbjocke |
Plugin | Simple Wp Sitemap |
Version | 1.0.9 |
Comparing to | |
See all releases |
Code changes from version 1.0.8 to 1.0.9
- css/html.css +35 -23
- css/simple-wp-sitemap-admin.css +30 -0
- js/simple-wp-sitemap-admin.js +9 -8
- readme.txt +9 -3
- sign.png +0 -0
- simple-wp-sitemap.php +57 -50
- simpleWpMapBuilder.php +41 -64
- simpleWpMapOptions.php +15 -16
css/html.css
CHANGED
@@ -7,26 +7,33 @@ body{
|
|
7 |
font-size: 13px;
|
8 |
background: #fff;
|
9 |
}
|
|
|
|
|
|
|
|
|
|
|
10 |
h1{
|
11 |
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
|
12 |
margin: 0 0.1% 25px 0.1%;
|
13 |
word-wrap: break-word;
|
14 |
}
|
15 |
a{
|
16 |
-
|
17 |
-
|
18 |
-
transition: all 0.3s;
|
19 |
display: inline-block;
|
20 |
word-wrap: break-word;
|
21 |
vertical-align: top;
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
}
|
24 |
-
a:hover{
|
25 |
-
background: #
|
26 |
-
text-decoration: underline;
|
27 |
}
|
28 |
-
a:active
|
29 |
-
color: #
|
30 |
}
|
31 |
ul{
|
32 |
list-style-type: none;
|
@@ -35,19 +42,15 @@ ul{
|
|
35 |
li:nth-child(2n){
|
36 |
background: #f8f8f8;
|
37 |
}
|
38 |
-
#wrapper{
|
39 |
-
max-width: 1080px;
|
40 |
-
padding: 15px 2% 40px 2%;
|
41 |
-
margin: 20px auto;
|
42 |
-
}
|
43 |
-
ul a, .date{
|
44 |
-
padding: 4px 0.1%;
|
45 |
-
}
|
46 |
-
.date, .header-date{
|
47 |
-
float: right;
|
48 |
-
}
|
49 |
.date{
|
50 |
display: inline-block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
.header{
|
53 |
overflow: auto;
|
@@ -60,14 +63,21 @@ ul a, .date{
|
|
60 |
.header-txt{
|
61 |
float: left;
|
62 |
}
|
|
|
|
|
|
|
63 |
#attr{
|
64 |
width: 100%;
|
65 |
-
|
66 |
-
font-size: 0.8em;
|
67 |
margin-top: 25px;
|
68 |
padding-right: 0.1%;
|
69 |
box-sizing: border-box;
|
70 |
}
|
|
|
|
|
|
|
|
|
|
|
71 |
@media screen and (max-width: 960px){
|
72 |
body{
|
73 |
font-size: 12px;
|
@@ -80,11 +90,13 @@ ul a, .date{
|
|
80 |
padding-left: 7px;
|
81 |
padding-right: 7px;
|
82 |
}
|
83 |
-
ul
|
|
|
84 |
max-width: 100%;
|
85 |
width: 100%;
|
86 |
padding: 4px 7px 2px 7px;
|
87 |
box-sizing: border-box;
|
|
|
88 |
}
|
89 |
.date{
|
90 |
float: none;
|
7 |
font-size: 13px;
|
8 |
background: #fff;
|
9 |
}
|
10 |
+
#wrapper{
|
11 |
+
max-width: 1080px;
|
12 |
+
padding: 15px 2% 40px 2%;
|
13 |
+
margin: 20px auto;
|
14 |
+
}
|
15 |
h1{
|
16 |
font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
|
17 |
margin: 0 0.1% 25px 0.1%;
|
18 |
word-wrap: break-word;
|
19 |
}
|
20 |
a{
|
21 |
+
width: 100%;
|
22 |
+
display: block;
|
|
|
23 |
display: inline-block;
|
24 |
word-wrap: break-word;
|
25 |
vertical-align: top;
|
26 |
+
text-decoration: none;
|
27 |
+
color: #000;
|
28 |
+
border: 1px solid transparent;
|
29 |
+
box-sizing: border-box;
|
30 |
+
transition: all 0.3s;
|
31 |
}
|
32 |
+
a:hover, a:focus{
|
33 |
+
background: #f0f0f0;
|
|
|
34 |
}
|
35 |
+
a:active{
|
36 |
+
border-color: #c8c8c8;
|
37 |
}
|
38 |
ul{
|
39 |
list-style-type: none;
|
42 |
li:nth-child(2n){
|
43 |
background: #f8f8f8;
|
44 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
.date{
|
46 |
display: inline-block;
|
47 |
+
float: right;
|
48 |
+
padding: 3px 0.1%;
|
49 |
+
}
|
50 |
+
.link{
|
51 |
+
float: left;
|
52 |
+
max-width: 75%;
|
53 |
+
padding: 3px 0.1%;
|
54 |
}
|
55 |
.header{
|
56 |
overflow: auto;
|
63 |
.header-txt{
|
64 |
float: left;
|
65 |
}
|
66 |
+
.header-date{
|
67 |
+
float: right;
|
68 |
+
}
|
69 |
#attr{
|
70 |
width: 100%;
|
71 |
+
font-size: 0.85em;
|
|
|
72 |
margin-top: 25px;
|
73 |
padding-right: 0.1%;
|
74 |
box-sizing: border-box;
|
75 |
}
|
76 |
+
#attr-a{
|
77 |
+
float: right;
|
78 |
+
width: auto;
|
79 |
+
padding: 7px;
|
80 |
+
}
|
81 |
@media screen and (max-width: 960px){
|
82 |
body{
|
83 |
font-size: 12px;
|
90 |
padding-left: 7px;
|
91 |
padding-right: 7px;
|
92 |
}
|
93 |
+
ul .link{
|
94 |
+
display: block;
|
95 |
max-width: 100%;
|
96 |
width: 100%;
|
97 |
padding: 4px 7px 2px 7px;
|
98 |
box-sizing: border-box;
|
99 |
+
float: none;
|
100 |
}
|
101 |
.date{
|
102 |
float: none;
|
css/simple-wp-sitemap-admin.css
CHANGED
@@ -29,6 +29,36 @@
|
|
29 |
#sitemap-table-show, .sitemap-shown{
|
30 |
display: block;
|
31 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
#sitemap-defaults{
|
33 |
text-decoration: underline;
|
34 |
float: left;
|
29 |
#sitemap-table-show, .sitemap-shown{
|
30 |
display: block;
|
31 |
}
|
32 |
+
#simple-wp-sitemap-donate{
|
33 |
+
position: relative,
|
34 |
+
}
|
35 |
+
#simple-wp-sitemap-donate img{
|
36 |
+
position: absolute;
|
37 |
+
margin: -1px 0 0 7px;
|
38 |
+
transition: all 0.3s;
|
39 |
+
}
|
40 |
+
#simple-wp-sitemap-donate img:hover{
|
41 |
+
opacity: 0.8;
|
42 |
+
}
|
43 |
+
#simple-wp-sitemap-h2{
|
44 |
+
float: left;
|
45 |
+
width: 100%;
|
46 |
+
margin-bottom: 10px;
|
47 |
+
}
|
48 |
+
#simple-wp-sitemap-h2 img{
|
49 |
+
float: left;
|
50 |
+
}
|
51 |
+
#simple-wp-sitemap-h2 span{
|
52 |
+
float: left;
|
53 |
+
padding: 5px 0 0 10px;
|
54 |
+
}
|
55 |
+
@media screen and (max-width: 500px){
|
56 |
+
#simple-wp-sitemap-donate img{
|
57 |
+
position: static;
|
58 |
+
display: block;
|
59 |
+
margin: 10px 0 0 0;
|
60 |
+
}
|
61 |
+
}
|
62 |
#sitemap-defaults{
|
63 |
text-decoration: underline;
|
64 |
float: left;
|
js/simple-wp-sitemap-admin.js
CHANGED
@@ -9,7 +9,7 @@
|
|
9 |
this.c.advanced.on('click', function () { that.changeState($(this), that.c.normal, that.c.tableAdvanced, that.c.tableNormal); });
|
10 |
this.c.ul.on('click', function (e) { that.changeOrder($(e.target)); });
|
11 |
this.c.defaults.on('click', function () { that.restoreDefaults(); });
|
12 |
-
this.c.form.on('submit', function (
|
13 |
};
|
14 |
|
15 |
this.changeState = function (btn, otherBtn, table, otherTable) {
|
@@ -30,9 +30,9 @@
|
|
30 |
li.next().after(li.clone());
|
31 |
li.remove();
|
32 |
}
|
33 |
-
}
|
34 |
|
35 |
-
this.submitForm = function (
|
36 |
var inputs = this.c.ul.find('input');
|
37 |
|
38 |
$.each(inputs, function (i) {
|
@@ -41,13 +41,14 @@
|
|
41 |
};
|
42 |
|
43 |
this.restoreDefaults = function () {
|
44 |
-
var sections = ['Home', 'Posts', 'Pages', 'Other', 'Categories', 'Tags', 'Authors']
|
|
|
45 |
|
46 |
-
|
|
|
|
|
47 |
|
48 |
-
|
49 |
-
this.c.ul.append('<li>' + sections[i] + '<span class="sitemap-down" title="move down"></span><span class="sitemap-up" title="move up"></span><input type="hidden" name="simple_wp_' + sections[i].toLowerCase() + '_n" value="' + (i + 1) + '"></li>');
|
50 |
-
}
|
51 |
};
|
52 |
};
|
53 |
|
9 |
this.c.advanced.on('click', function () { that.changeState($(this), that.c.normal, that.c.tableAdvanced, that.c.tableNormal); });
|
10 |
this.c.ul.on('click', function (e) { that.changeOrder($(e.target)); });
|
11 |
this.c.defaults.on('click', function () { that.restoreDefaults(); });
|
12 |
+
this.c.form.on('submit', function () { that.submitForm(); });
|
13 |
};
|
14 |
|
15 |
this.changeState = function (btn, otherBtn, table, otherTable) {
|
30 |
li.next().after(li.clone());
|
31 |
li.remove();
|
32 |
}
|
33 |
+
};
|
34 |
|
35 |
+
this.submitForm = function () {
|
36 |
var inputs = this.c.ul.find('input');
|
37 |
|
38 |
$.each(inputs, function (i) {
|
41 |
};
|
42 |
|
43 |
this.restoreDefaults = function () {
|
44 |
+
var sections = ['Home', 'Posts', 'Pages', 'Other', 'Categories', 'Tags', 'Authors'],
|
45 |
+
html = '';
|
46 |
|
47 |
+
$.each(sections, function (i) {
|
48 |
+
html += '<li>' + sections[i] + '<span class="sitemap-down" title="move down"></span><span class="sitemap-up" title="move up"></span><input type="hidden" name="simple_wp_' + sections[i].toLowerCase() + '_n" value="' + (i + 1) + '"></li>';
|
49 |
+
});
|
50 |
|
51 |
+
this.c.ul.empty().append(html);
|
|
|
|
|
52 |
};
|
53 |
};
|
54 |
|
readme.txt
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
=== Simple Wp Sitemap ===
|
2 |
Contributors: Webbjocke
|
|
|
3 |
License: GPLv3
|
4 |
License URI: http://www.gnu.org/licenses/gpl.html
|
5 |
Tags: sitemap, google sitemap, xml, simple sitemap, html, xml sitemap, html sitemap, seo, seo sitemap
|
6 |
Requires at least: 4.0
|
7 |
-
Tested up to: 4.
|
8 |
-
Stable tag: 1.0.
|
9 |
|
10 |
An easy, fast and secure plugin that adds both an xml and an html sitemap to your site, which updates and maintains themselves so you dont have to!
|
11 |
|
@@ -27,7 +28,7 @@ And yes, of course the sitemaps are mobile friendly. They also work well with ca
|
|
27 |
2. Either search for "simple-wp-sitemap" and click install, or hit "upload plugin" and upload the zip file.
|
28 |
3. Another way is by just uploading the "simple-wp-sitemap" folder via ftp to the /wp-content/plugins/ directory.
|
29 |
|
30 |
-
2. Activate the plugin and
|
31 |
|
32 |
3. Customize the plugin and add/block pages by hitting the "Simple Wp Sitemap" option in the settings menu.
|
33 |
|
@@ -73,6 +74,11 @@ When you deactivate the plugin they get removed automatically.
|
|
73 |
|
74 |
== Changelog ==
|
75 |
|
|
|
|
|
|
|
|
|
|
|
76 |
= 1.0.8 (April 29, 2015) =
|
77 |
* Now generates dynamic sitemaps instead of static files
|
78 |
* Tested with caching plugins (the popular ones) and works
|
1 |
=== Simple Wp Sitemap ===
|
2 |
Contributors: Webbjocke
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UH6ANJA7M8DNS
|
4 |
License: GPLv3
|
5 |
License URI: http://www.gnu.org/licenses/gpl.html
|
6 |
Tags: sitemap, google sitemap, xml, simple sitemap, html, xml sitemap, html sitemap, seo, seo sitemap
|
7 |
Requires at least: 4.0
|
8 |
+
Tested up to: 4.3
|
9 |
+
Stable tag: 1.0.9
|
10 |
|
11 |
An easy, fast and secure plugin that adds both an xml and an html sitemap to your site, which updates and maintains themselves so you dont have to!
|
12 |
|
28 |
2. Either search for "simple-wp-sitemap" and click install, or hit "upload plugin" and upload the zip file.
|
29 |
3. Another way is by just uploading the "simple-wp-sitemap" folder via ftp to the /wp-content/plugins/ directory.
|
30 |
|
31 |
+
2. Activate the plugin and that's it, done. The two sitemaps will be generated when visited, and can be found at like yourpage.com/sitemap.xml and yourpage.com/sitemap.html.
|
32 |
|
33 |
3. Customize the plugin and add/block pages by hitting the "Simple Wp Sitemap" option in the settings menu.
|
34 |
|
74 |
|
75 |
== Changelog ==
|
76 |
|
77 |
+
= 1.0.9 (Jun 23, 2015) =
|
78 |
+
* Added donation link
|
79 |
+
* Made the sitemaps compatible down to ie7
|
80 |
+
* Minor changes in php, css and js
|
81 |
+
|
82 |
= 1.0.8 (April 29, 2015) =
|
83 |
* Now generates dynamic sitemaps instead of static files
|
84 |
* Tested with caching plugins (the popular ones) and works
|
sign.png
ADDED
Binary file
|
simple-wp-sitemap.php
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
<?php if (!defined( 'ABSPATH' )){ die(); }
|
2 |
|
3 |
/*
|
4 |
* Plugin Name: Simple Wp Sitemap
|
5 |
* Plugin URI: http://www.webbjocke.com/simple-wp-sitemap/
|
6 |
* Description: An easy, fast and secure plugin that adds both an xml and an html sitemap to your site, which updates and maintains themselves so you dont have to!
|
7 |
-
* Version: 1.0.
|
8 |
* Author: Webbjocke
|
9 |
* Author URI: http://www.webbjocke.com/
|
10 |
* License: GPLv3
|
@@ -13,10 +13,10 @@
|
|
13 |
// Main class
|
14 |
|
15 |
class SimpleWpSitemap {
|
16 |
-
private static $version = 8;
|
17 |
|
18 |
-
//
|
19 |
-
public static function activateSitemaps() {
|
20 |
self::rewriteRules();
|
21 |
flush_rewrite_rules();
|
22 |
|
@@ -24,16 +24,16 @@ class SimpleWpSitemap {
|
|
24 |
|
25 |
// deletes files sitemap.xml and .html from old versions of the plugin
|
26 |
require_once('simpleWpMapBuilder.php');
|
27 |
-
|
28 |
}
|
29 |
|
30 |
-
//
|
31 |
-
public static function deactivateSitemaps() {
|
32 |
flush_rewrite_rules();
|
33 |
}
|
34 |
|
35 |
-
// Updates the plugin (calls activateSitemaps)
|
36 |
-
public static function updateCheck() {
|
37 |
$current = get_option('simple_wp_sitemap_version');
|
38 |
|
39 |
if (!$current || $current < self::$version) {
|
@@ -41,45 +41,57 @@ class SimpleWpSitemap {
|
|
41 |
}
|
42 |
}
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
// Adds a link to settings from the plugins page
|
45 |
-
public static function pluginSettingsLink($links) {
|
46 |
$theLink = array(sprintf('<a href="%s">%s</a>', esc_url(admin_url('options-general.php?page=simpleWpSitemapSettings')), __('Settings')));
|
47 |
return array_merge($links, $theLink);
|
48 |
}
|
49 |
|
50 |
-
// Sets the menu
|
51 |
-
public static function sitemapAdminSetup() {
|
52 |
-
add_options_page('Simple Wp Sitemap', 'Simple Wp Sitemap', 'administrator', 'simpleWpSitemapSettings', array(
|
53 |
-
add_action('admin_enqueue_scripts', array(
|
54 |
-
add_action('admin_init', array(
|
55 |
}
|
56 |
|
57 |
// Register settings on admin_init
|
58 |
-
public static function sitemapAdminInit() {
|
59 |
-
|
60 |
-
register_setting(
|
61 |
-
register_setting(
|
62 |
-
register_setting(
|
63 |
-
register_setting(
|
64 |
-
register_setting(
|
65 |
-
register_setting(
|
|
|
66 |
self::updateCheck();
|
67 |
}
|
68 |
|
69 |
// Rewrite rules for sitemaps
|
70 |
-
public static function rewriteRules() {
|
71 |
add_rewrite_rule('sitemap\.xml$', 'index.php?thesimplewpsitemap=xml', 'top');
|
72 |
add_rewrite_rule('sitemap\.html$', 'index.php?thesimplewpsitemap=html', 'top');
|
73 |
}
|
74 |
|
75 |
// Add custom query
|
76 |
-
public static function addSitemapQuery($vars) {
|
77 |
$vars[] = 'thesimplewpsitemap';
|
78 |
return $vars;
|
79 |
}
|
80 |
|
81 |
// Generates the content
|
82 |
-
public static function generateSitemapContent() {
|
83 |
global $wp_query;
|
84 |
|
85 |
if (isset($wp_query->query_vars['thesimplewpsitemap'])) {
|
@@ -87,32 +99,29 @@ class SimpleWpSitemap {
|
|
87 |
|
88 |
if (!empty($q) && ($q === 'xml' || $q === 'html')) {
|
89 |
$wp_query->is_404 = false;
|
|
|
90 |
require_once('simpleWpMapBuilder.php');
|
|
|
91 |
|
92 |
if ($q === 'xml') {
|
93 |
-
$builder = new SimpleWpMapBuilder('xml');
|
94 |
header('Content-type: application/xml; charset=utf-8');
|
95 |
}
|
96 |
-
|
97 |
-
$builder = new SimpleWpMapBuilder('html');
|
98 |
-
}
|
99 |
-
echo $builder->getContent();
|
100 |
exit;
|
101 |
}
|
102 |
}
|
103 |
}
|
104 |
|
105 |
// Add custom scripts and styles to the plugins customization page in admin area
|
106 |
-
public static function sitemapScriptsAndStyles($page) {
|
107 |
-
if ($page
|
108 |
-
|
|
|
109 |
}
|
110 |
-
wp_enqueue_style('simple-wp-sitemap-admin-css', plugin_dir_url( __FILE__ ) . '/css/simple-wp-sitemap-admin.css');
|
111 |
-
wp_enqueue_script('simple-wp-sitemap-admin-js', plugin_dir_url( __FILE__ ) . '/js/simple-wp-sitemap-admin.js', array('jquery'), false, true);
|
112 |
}
|
113 |
|
114 |
// Interface for settings page, also handles initial post request when settings are changed
|
115 |
-
public static function sitemapAdminArea() {
|
116 |
require_once('simpleWpMapOptions.php');
|
117 |
$options = new SimpleWpMapOptions();
|
118 |
|
@@ -123,7 +132,10 @@ class SimpleWpSitemap {
|
|
123 |
|
124 |
<div class="wrap">
|
125 |
|
126 |
-
<h2
|
|
|
|
|
|
|
127 |
|
128 |
<p>Your two sitemaps are active! Here you can change and customize them.</p>
|
129 |
|
@@ -162,8 +174,9 @@ class SimpleWpSitemap {
|
|
162 |
<tr><td><input type="checkbox" name="simple_wp_disp_authors" id="simple_wp_authors" <?php echo $options->getOptions('simple_wp_disp_authors'); ?>><label for="simple_wp_authors"> Include authors</label></td></tr>
|
163 |
|
164 |
<tr><td><strong>Like the plugin?</strong></td></tr>
|
165 |
-
<tr><td>Show your support by rating the plugin at wordpress.org, or
|
166 |
<tr><td><input type="checkbox" name="simple_wp_attr_link" id="simple_wp_check" <?php echo $options->getOptions('simple_wp_attr_link'); ?>><label for="simple_wp_check"> Add "Generated by Simple Wp Sitemap" link at bottom of sitemap.html.</label></td></tr>
|
|
|
167 |
|
168 |
</table>
|
169 |
|
@@ -180,10 +193,10 @@ class SimpleWpSitemap {
|
|
180 |
if (!($orderArray = $options->getOptions('simple_wp_disp_sitemap_order'))) {
|
181 |
$orderArray = array('Home' => null, 'Posts' => null, 'Pages' => null, 'Other' => null, 'Categories' => null, 'Tags' => null, 'Authors' => null);
|
182 |
}
|
183 |
-
$count =
|
184 |
|
185 |
foreach ($orderArray as $title => $val) {
|
186 |
-
printf('<li>%s<span class="sitemap-down" title="move down"></span><span class="sitemap-up" title="move up"></span><input type="hidden" name="simple_wp_%s_n" value="%d"></li>', $title, lcfirst($title), (
|
187 |
}
|
188 |
|
189 |
?>
|
@@ -201,14 +214,8 @@ class SimpleWpSitemap {
|
|
201 |
<p>(If you have a caching plugin, you might have to clear cache before changes will be shown in the sitemaps)</p>
|
202 |
|
203 |
</form>
|
204 |
-
|
205 |
</div>
|
206 |
<?php }
|
207 |
}
|
208 |
-
|
209 |
-
register_deactivation_hook(__FILE__, array('SimpleWpSitemap', 'deactivateSitemaps'));
|
210 |
-
add_action('admin_menu', array('SimpleWpSitemap', 'sitemapAdminSetup'));
|
211 |
-
add_action('init', array('SimpleWpSitemap', 'rewriteRules'), 1);
|
212 |
-
add_filter('query_vars', array('SimpleWpSitemap', 'addSitemapQuery'), 1);
|
213 |
-
add_filter('template_redirect', array('SimpleWpSitemap', 'generateSitemapContent'), 1);
|
214 |
-
add_filter("plugin_action_links_" . plugin_basename(__FILE__), array('SimpleWpSitemap', 'pluginSettingsLink'));
|
1 |
+
<?php if (!defined( 'ABSPATH' )) { die(); }
|
2 |
|
3 |
/*
|
4 |
* Plugin Name: Simple Wp Sitemap
|
5 |
* Plugin URI: http://www.webbjocke.com/simple-wp-sitemap/
|
6 |
* Description: An easy, fast and secure plugin that adds both an xml and an html sitemap to your site, which updates and maintains themselves so you dont have to!
|
7 |
+
* Version: 1.0.9
|
8 |
* Author: Webbjocke
|
9 |
* Author URI: http://www.webbjocke.com/
|
10 |
* License: GPLv3
|
13 |
// Main class
|
14 |
|
15 |
class SimpleWpSitemap {
|
16 |
+
private static $version = 8; // only changes when needed
|
17 |
|
18 |
+
// Runs on plugin activation
|
19 |
+
public static function activateSitemaps () {
|
20 |
self::rewriteRules();
|
21 |
flush_rewrite_rules();
|
22 |
|
24 |
|
25 |
// deletes files sitemap.xml and .html from old versions of the plugin
|
26 |
require_once('simpleWpMapBuilder.php');
|
27 |
+
SimpleWpMapBuilder::deleteFiles();
|
28 |
}
|
29 |
|
30 |
+
// Runs on plugin deactivation
|
31 |
+
public static function deactivateSitemaps () {
|
32 |
flush_rewrite_rules();
|
33 |
}
|
34 |
|
35 |
+
// Updates the plugin if needed (calls activateSitemaps)
|
36 |
+
public static function updateCheck () {
|
37 |
$current = get_option('simple_wp_sitemap_version');
|
38 |
|
39 |
if (!$current || $current < self::$version) {
|
41 |
}
|
42 |
}
|
43 |
|
44 |
+
// Registers most hooks
|
45 |
+
public static function registerHooks () {
|
46 |
+
register_activation_hook(__FILE__, array(__CLASS__, 'activateSitemaps'));
|
47 |
+
register_deactivation_hook(__FILE__, array(__CLASS__, 'deactivateSitemaps'));
|
48 |
+
add_action('admin_menu', array(__CLASS__, 'sitemapAdminSetup'));
|
49 |
+
add_action('init', array(__CLASS__, 'rewriteRules'), 1);
|
50 |
+
add_filter('query_vars', array(__CLASS__, 'addSitemapQuery'), 1);
|
51 |
+
add_filter('template_redirect', array(__CLASS__, 'generateSitemapContent'), 1);
|
52 |
+
add_filter("plugin_action_links_" . plugin_basename(__FILE__), array(__CLASS__, 'pluginSettingsLink'));
|
53 |
+
}
|
54 |
+
|
55 |
// Adds a link to settings from the plugins page
|
56 |
+
public static function pluginSettingsLink ($links) {
|
57 |
$theLink = array(sprintf('<a href="%s">%s</a>', esc_url(admin_url('options-general.php?page=simpleWpSitemapSettings')), __('Settings')));
|
58 |
return array_merge($links, $theLink);
|
59 |
}
|
60 |
|
61 |
+
// Sets the option menu for admins and enqueues scripts n styles
|
62 |
+
public static function sitemapAdminSetup () {
|
63 |
+
add_options_page('Simple Wp Sitemap', 'Simple Wp Sitemap', 'administrator', 'simpleWpSitemapSettings', array(__CLASS__, 'sitemapAdminArea'));
|
64 |
+
add_action('admin_enqueue_scripts', array(__CLASS__, 'sitemapScriptsAndStyles'));
|
65 |
+
add_action('admin_init', array(__CLASS__, 'sitemapAdminInit'));
|
66 |
}
|
67 |
|
68 |
// Register settings on admin_init
|
69 |
+
public static function sitemapAdminInit () {
|
70 |
+
$group = 'simple_wp-sitemap-group';
|
71 |
+
register_setting($group, 'simple_wp_other_urls');
|
72 |
+
register_setting($group, 'simple_wp_block_urls');
|
73 |
+
register_setting($group, 'simple_wp_attr_link');
|
74 |
+
register_setting($group, 'simple_wp_disp_categories');
|
75 |
+
register_setting($group, 'simple_wp_disp_tags');
|
76 |
+
register_setting($group, 'simple_wp_disp_authors');
|
77 |
+
register_setting($group, 'simple_wp_disp_sitemap_order');
|
78 |
self::updateCheck();
|
79 |
}
|
80 |
|
81 |
// Rewrite rules for sitemaps
|
82 |
+
public static function rewriteRules () {
|
83 |
add_rewrite_rule('sitemap\.xml$', 'index.php?thesimplewpsitemap=xml', 'top');
|
84 |
add_rewrite_rule('sitemap\.html$', 'index.php?thesimplewpsitemap=html', 'top');
|
85 |
}
|
86 |
|
87 |
// Add custom query
|
88 |
+
public static function addSitemapQuery ($vars) {
|
89 |
$vars[] = 'thesimplewpsitemap';
|
90 |
return $vars;
|
91 |
}
|
92 |
|
93 |
// Generates the content
|
94 |
+
public static function generateSitemapContent () {
|
95 |
global $wp_query;
|
96 |
|
97 |
if (isset($wp_query->query_vars['thesimplewpsitemap'])) {
|
99 |
|
100 |
if (!empty($q) && ($q === 'xml' || $q === 'html')) {
|
101 |
$wp_query->is_404 = false;
|
102 |
+
|
103 |
require_once('simpleWpMapBuilder.php');
|
104 |
+
$sitemap = new SimpleWpMapBuilder();
|
105 |
|
106 |
if ($q === 'xml') {
|
|
|
107 |
header('Content-type: application/xml; charset=utf-8');
|
108 |
}
|
109 |
+
$sitemap->getContent($q);
|
|
|
|
|
|
|
110 |
exit;
|
111 |
}
|
112 |
}
|
113 |
}
|
114 |
|
115 |
// Add custom scripts and styles to the plugins customization page in admin area
|
116 |
+
public static function sitemapScriptsAndStyles ($page) {
|
117 |
+
if ($page === 'settings_page_simpleWpSitemapSettings') {
|
118 |
+
wp_enqueue_style('simple-wp-sitemap-admin-css', plugin_dir_url( __FILE__ ) . '/css/simple-wp-sitemap-admin.css');
|
119 |
+
wp_enqueue_script('simple-wp-sitemap-admin-js', plugin_dir_url( __FILE__ ) . '/js/simple-wp-sitemap-admin.js', array('jquery'), false, true);
|
120 |
}
|
|
|
|
|
121 |
}
|
122 |
|
123 |
// Interface for settings page, also handles initial post request when settings are changed
|
124 |
+
public static function sitemapAdminArea () {
|
125 |
require_once('simpleWpMapOptions.php');
|
126 |
$options = new SimpleWpMapOptions();
|
127 |
|
132 |
|
133 |
<div class="wrap">
|
134 |
|
135 |
+
<h2 id="simple-wp-sitemap-h2">
|
136 |
+
<img src="<?php echo plugins_url() . '/simple-wp-sitemap/sign.png'; ?>" alt="logo" width="40" height="40">
|
137 |
+
<span>Simple Wp Sitemap settings</span>
|
138 |
+
</h2>
|
139 |
|
140 |
<p>Your two sitemaps are active! Here you can change and customize them.</p>
|
141 |
|
174 |
<tr><td><input type="checkbox" name="simple_wp_disp_authors" id="simple_wp_authors" <?php echo $options->getOptions('simple_wp_disp_authors'); ?>><label for="simple_wp_authors"> Include authors</label></td></tr>
|
175 |
|
176 |
<tr><td><strong>Like the plugin?</strong></td></tr>
|
177 |
+
<tr><td>Show your support by rating the plugin at wordpress.org, and/or by adding an attribution link to the sitemap.html file :)</td></tr>
|
178 |
<tr><td><input type="checkbox" name="simple_wp_attr_link" id="simple_wp_check" <?php echo $options->getOptions('simple_wp_attr_link'); ?>><label for="simple_wp_check"> Add "Generated by Simple Wp Sitemap" link at bottom of sitemap.html.</label></td></tr>
|
179 |
+
<tr><td>A donation is also always welcome! <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UH6ANJA7M8DNS" id="simple-wp-sitemap-donate" target="_blank"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="PayPal - The safer, easier way to pay online!"></a></td></tr>
|
180 |
|
181 |
</table>
|
182 |
|
193 |
if (!($orderArray = $options->getOptions('simple_wp_disp_sitemap_order'))) {
|
194 |
$orderArray = array('Home' => null, 'Posts' => null, 'Pages' => null, 'Other' => null, 'Categories' => null, 'Tags' => null, 'Authors' => null);
|
195 |
}
|
196 |
+
$count = 1;
|
197 |
|
198 |
foreach ($orderArray as $title => $val) {
|
199 |
+
printf('<li>%s<span class="sitemap-down" title="move down"></span><span class="sitemap-up" title="move up"></span><input type="hidden" name="simple_wp_%s_n" value="%d"></li>', $title, lcfirst($title), ($count++));
|
200 |
}
|
201 |
|
202 |
?>
|
214 |
<p>(If you have a caching plugin, you might have to clear cache before changes will be shown in the sitemaps)</p>
|
215 |
|
216 |
</form>
|
217 |
+
|
218 |
</div>
|
219 |
<?php }
|
220 |
}
|
221 |
+
SimpleWpSitemap::registerHooks();
|
|
|
|
|
|
|
|
|
|
|
|
simpleWpMapBuilder.php
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
<?php if (!defined( 'ABSPATH' )){ die(); }
|
2 |
|
3 |
/*
|
4 |
* The sitemap creating class
|
@@ -9,52 +9,34 @@ class SimpleWpMapBuilder {
|
|
9 |
private $html = false;
|
10 |
private $posts = '';
|
11 |
private $pages = '';
|
12 |
-
private $content = '';
|
13 |
private $url;
|
14 |
private $tags;
|
15 |
-
private $order;
|
16 |
private $homeUrl;
|
17 |
private $authors;
|
18 |
private $categories;
|
19 |
private $blockedUrls;
|
20 |
|
21 |
// Constructor
|
22 |
-
public function __construct(
|
23 |
$this->url = esc_url(plugins_url() . '/simple-wp-sitemap');
|
24 |
$this->homeUrl = esc_url(get_home_url() . (substr(get_home_url(), -1) === '/' ? '' : '/'));
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
$this->xml = true;
|
29 |
-
$this->generateSitemaps();
|
30 |
-
break;
|
31 |
-
case 'html':
|
32 |
-
$this->html = true;
|
33 |
-
$this->generateSitemaps();
|
34 |
-
break;
|
35 |
-
case 'delete':
|
36 |
-
$this->deleteFiles();
|
37 |
-
}
|
38 |
-
}
|
39 |
-
|
40 |
-
// Get method for content
|
41 |
-
public function getContent() {
|
42 |
-
return $this->content;
|
43 |
}
|
44 |
|
45 |
-
// Generates the
|
46 |
-
|
47 |
-
$
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
$this->generateContent();
|
54 |
}
|
55 |
|
56 |
// Returns other urls user has submitted
|
57 |
-
private function getOtherPages() {
|
58 |
$xml = '';
|
59 |
|
60 |
if ($options = get_option('simple_wp_other_urls')) {
|
@@ -68,11 +50,11 @@ class SimpleWpMapBuilder {
|
|
68 |
}
|
69 |
|
70 |
// Sets up blocked urls into an array
|
71 |
-
private function setUpBlockedUrls() {
|
72 |
$blocked = get_option('simple_wp_block_urls');
|
|
|
73 |
if ($blocked && is_array($blocked)) {
|
74 |
-
$this->blockedUrls = array();
|
75 |
-
|
76 |
foreach ($blocked as $block) {
|
77 |
$this->blockedUrls[$block['url']] = 'blocked';
|
78 |
}
|
@@ -89,12 +71,12 @@ class SimpleWpMapBuilder {
|
|
89 |
|
90 |
|
91 |
// Returns an xml or html string
|
92 |
-
private function getXml($link, $date) {
|
93 |
if ($this->xml) {
|
94 |
return "<url>\n\t<loc>$link</loc>\n\t<lastmod>$date</lastmod>\n</url>\n";
|
95 |
}
|
96 |
-
else{
|
97 |
-
return "<li><a title=\"$link\" href=\"$link\">$link</
|
98 |
}
|
99 |
}
|
100 |
|
@@ -103,10 +85,10 @@ class SimpleWpMapBuilder {
|
|
103 |
return '<div class="header"><p class="header-txt">' . $name . ':</p><p class="header-date">Last modified:</p></div>';
|
104 |
}
|
105 |
|
106 |
-
//
|
107 |
-
private function generateContent() {
|
108 |
-
$q = new WP_Query(array('post_type' => 'any', 'post_status' => 'publish', 'posts_per_page' =>
|
109 |
-
|
110 |
global $post;
|
111 |
$localPost = $post;
|
112 |
|
@@ -132,15 +114,12 @@ class SimpleWpMapBuilder {
|
|
132 |
}
|
133 |
}
|
134 |
}
|
135 |
-
|
136 |
-
$this->mergeArraysAndGetOtherPages();
|
137 |
wp_reset_postdata();
|
138 |
-
|
139 |
$post = $localPost; // reset global post to its value before the loop
|
140 |
}
|
141 |
|
142 |
// Gets a posts categories, tags and author, and compares for last modified date
|
143 |
-
private function getCategoriesTagsAndAuthor($date) {
|
144 |
if ($this->categories && ($postCats = get_the_category())) {
|
145 |
foreach ($postCats as $category) {
|
146 |
$id = $category->term_id;
|
@@ -165,14 +144,14 @@ class SimpleWpMapBuilder {
|
|
165 |
}
|
166 |
|
167 |
// Merges the arrays with post data into strings and gets user submitted pages, categories, tags and author pages
|
168 |
-
private function
|
169 |
$xml = '';
|
170 |
$name = get_bloginfo('name');
|
171 |
$sections = $this->getSortedArray();
|
172 |
|
173 |
foreach ($sections as $title => $content) {
|
174 |
if ($content) {
|
175 |
-
if (
|
176 |
$content = $this->stringifyCatsTagsAuths($title, $content);
|
177 |
if ($title === 'Authors' && count($this->authors) <= 2) { // only one author
|
178 |
$title = 'Author';
|
@@ -184,26 +163,25 @@ class SimpleWpMapBuilder {
|
|
184 |
}
|
185 |
}
|
186 |
}
|
187 |
-
|
188 |
if ($this->xml) {
|
189 |
-
|
190 |
}
|
191 |
else {
|
192 |
-
|
193 |
}
|
194 |
}
|
195 |
|
196 |
// Displays attribution link if admin has checked the checkbox
|
197 |
-
private function attributionLink() {
|
198 |
if (get_option('simple_wp_attr_link')) {
|
199 |
-
return '<p id="attr"
|
200 |
}
|
201 |
return '';
|
202 |
}
|
203 |
|
204 |
// Gets sorted array according to specified order
|
205 |
-
private function getSortedArray() {
|
206 |
-
if (!($arr =
|
207 |
$arr = array('Home' => null, 'Posts' => null, 'Pages' => null, 'Other' => null, 'Categories' => null, 'Tags' => null, 'Authors' => null);
|
208 |
}
|
209 |
|
@@ -225,7 +203,7 @@ class SimpleWpMapBuilder {
|
|
225 |
}
|
226 |
|
227 |
// Returns category, tag and author links as ready xml and html strings
|
228 |
-
private function stringifyCatsTagsAuths($type, $content) {
|
229 |
$xml = '';
|
230 |
|
231 |
foreach ($content as $id => $date) {
|
@@ -240,7 +218,7 @@ class SimpleWpMapBuilder {
|
|
240 |
}
|
241 |
|
242 |
// Returns either a category, tag or an author link
|
243 |
-
private function getLink($id, $type) {
|
244 |
switch ($type) {
|
245 |
case 'Tags': return get_tag_link($id);
|
246 |
case 'Categories': return get_category_link($id);
|
@@ -249,15 +227,14 @@ class SimpleWpMapBuilder {
|
|
249 |
}
|
250 |
|
251 |
// Deletes the sitemap files from old versions of the plugin
|
252 |
-
|
253 |
if (function_exists('get_home_path')) {
|
254 |
-
$path = sprintf('%s%ssitemap', get_home_path(), (substr(get_home_path(), -1) === '/' ? '' : '/'));
|
255 |
try {
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
unlink($path . '.html');
|
261 |
}
|
262 |
}
|
263 |
catch (Exception $ex) {
|
1 |
+
<?php if (!defined( 'ABSPATH' )) { die(); }
|
2 |
|
3 |
/*
|
4 |
* The sitemap creating class
|
9 |
private $html = false;
|
10 |
private $posts = '';
|
11 |
private $pages = '';
|
|
|
12 |
private $url;
|
13 |
private $tags;
|
|
|
14 |
private $homeUrl;
|
15 |
private $authors;
|
16 |
private $categories;
|
17 |
private $blockedUrls;
|
18 |
|
19 |
// Constructor
|
20 |
+
public function __construct () {
|
21 |
$this->url = esc_url(plugins_url() . '/simple-wp-sitemap');
|
22 |
$this->homeUrl = esc_url(get_home_url() . (substr(get_home_url(), -1) === '/' ? '' : '/'));
|
23 |
+
$this->categories = get_option('simple_wp_disp_categories') ? array(0 => 0) : false;
|
24 |
+
$this->tags = get_option('simple_wp_disp_tags') ? array(0 => 0) : false;
|
25 |
+
$this->authors = get_option('simple_wp_disp_authors') ? array(0 => 0) : false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
}
|
27 |
|
28 |
+
// Generates the sitemaps and returns the content
|
29 |
+
public function getContent ($type) {
|
30 |
+
if ($type === 'xml' || $type === 'html') {
|
31 |
+
$this->$type = true;
|
32 |
+
$this->setUpBlockedUrls();
|
33 |
+
$this->generateContent();
|
34 |
+
$this->mergeAndPrint();
|
35 |
+
}
|
|
|
36 |
}
|
37 |
|
38 |
// Returns other urls user has submitted
|
39 |
+
private function getOtherPages () {
|
40 |
$xml = '';
|
41 |
|
42 |
if ($options = get_option('simple_wp_other_urls')) {
|
50 |
}
|
51 |
|
52 |
// Sets up blocked urls into an array
|
53 |
+
private function setUpBlockedUrls () {
|
54 |
$blocked = get_option('simple_wp_block_urls');
|
55 |
+
|
56 |
if ($blocked && is_array($blocked)) {
|
57 |
+
$this->blockedUrls = array();
|
|
|
58 |
foreach ($blocked as $block) {
|
59 |
$this->blockedUrls[$block['url']] = 'blocked';
|
60 |
}
|
71 |
|
72 |
|
73 |
// Returns an xml or html string
|
74 |
+
private function getXml ($link, $date) {
|
75 |
if ($this->xml) {
|
76 |
return "<url>\n\t<loc>$link</loc>\n\t<lastmod>$date</lastmod>\n</url>\n";
|
77 |
}
|
78 |
+
else { // html
|
79 |
+
return "<li><a title=\"$link\" href=\"$link\"><span class=\"link\">$link</span><span class=\"date\">$date</span></a></li>";
|
80 |
}
|
81 |
}
|
82 |
|
85 |
return '<div class="header"><p class="header-txt">' . $name . ':</p><p class="header-date">Last modified:</p></div>';
|
86 |
}
|
87 |
|
88 |
+
// Querys the database and gets the actual sitemaps content
|
89 |
+
private function generateContent () {
|
90 |
+
$q = new WP_Query(array('post_type' => 'any', 'post_status' => 'publish', 'posts_per_page' => 50000, 'has_password' => false));
|
91 |
+
|
92 |
global $post;
|
93 |
$localPost = $post;
|
94 |
|
114 |
}
|
115 |
}
|
116 |
}
|
|
|
|
|
117 |
wp_reset_postdata();
|
|
|
118 |
$post = $localPost; // reset global post to its value before the loop
|
119 |
}
|
120 |
|
121 |
// Gets a posts categories, tags and author, and compares for last modified date
|
122 |
+
private function getCategoriesTagsAndAuthor ($date) {
|
123 |
if ($this->categories && ($postCats = get_the_category())) {
|
124 |
foreach ($postCats as $category) {
|
125 |
$id = $category->term_id;
|
144 |
}
|
145 |
|
146 |
// Merges the arrays with post data into strings and gets user submitted pages, categories, tags and author pages
|
147 |
+
private function mergeAndPrint () {
|
148 |
$xml = '';
|
149 |
$name = get_bloginfo('name');
|
150 |
$sections = $this->getSortedArray();
|
151 |
|
152 |
foreach ($sections as $title => $content) {
|
153 |
if ($content) {
|
154 |
+
if (preg_match("/^(Categories|Tags|Authors)$/", $title)) {
|
155 |
$content = $this->stringifyCatsTagsAuths($title, $content);
|
156 |
if ($title === 'Authors' && count($this->authors) <= 2) { // only one author
|
157 |
$title = 'Author';
|
163 |
}
|
164 |
}
|
165 |
}
|
|
|
166 |
if ($this->xml) {
|
167 |
+
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/css\" href=\"{$this->url}/css/xml.css\"?>\n<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n\thttp://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n$xml</urlset>\n<!-- Sitemap content by Simple Wp Sitemap -->";
|
168 |
}
|
169 |
else {
|
170 |
+
echo '<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>' . $name . ' Html Sitemap</title><link rel="stylesheet" href="' . $this->url . '/css/html.css"></head><body><div id="wrapper"><h1>' . $name . ' Html Sitemap</h1>' . $xml . $this->attributionLink() . "</div></body></html>\n<!-- Sitemap content by Simple Wp Sitemap -->";
|
171 |
}
|
172 |
}
|
173 |
|
174 |
// Displays attribution link if admin has checked the checkbox
|
175 |
+
private function attributionLink () {
|
176 |
if (get_option('simple_wp_attr_link')) {
|
177 |
+
return '<p id="attr"><a id="attr-a" href="http://www.webbjocke.com/simple-wp-sitemap/" title="http://www.webbjocke.com/simple-wp-sitemap/">Generated by: Simple Wp Sitemap</a></p>';
|
178 |
}
|
179 |
return '';
|
180 |
}
|
181 |
|
182 |
// Gets sorted array according to specified order
|
183 |
+
private function getSortedArray () {
|
184 |
+
if (!($arr = get_option('simple_wp_disp_sitemap_order'))) {
|
185 |
$arr = array('Home' => null, 'Posts' => null, 'Pages' => null, 'Other' => null, 'Categories' => null, 'Tags' => null, 'Authors' => null);
|
186 |
}
|
187 |
|
203 |
}
|
204 |
|
205 |
// Returns category, tag and author links as ready xml and html strings
|
206 |
+
private function stringifyCatsTagsAuths ($type, $content) {
|
207 |
$xml = '';
|
208 |
|
209 |
foreach ($content as $id => $date) {
|
218 |
}
|
219 |
|
220 |
// Returns either a category, tag or an author link
|
221 |
+
private function getLink ($id, $type) {
|
222 |
switch ($type) {
|
223 |
case 'Tags': return get_tag_link($id);
|
224 |
case 'Categories': return get_category_link($id);
|
227 |
}
|
228 |
|
229 |
// Deletes the sitemap files from old versions of the plugin
|
230 |
+
public static function deleteFiles () {
|
231 |
if (function_exists('get_home_path')) {
|
232 |
+
$path = sprintf('%s%ssitemap.', get_home_path(), (substr(get_home_path(), -1) === '/' ? '' : '/'));
|
233 |
try {
|
234 |
+
foreach (array('xml', 'html') as $file) {
|
235 |
+
if (file_exists($path . $file)) {
|
236 |
+
unlink($path . $file);
|
237 |
+
}
|
|
|
238 |
}
|
239 |
}
|
240 |
catch (Exception $ex) {
|
simpleWpMapOptions.php
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
<?php if (!defined( 'ABSPATH' )){ die(); }
|
2 |
|
3 |
/*
|
4 |
* Class that handles all admin settings
|
@@ -6,18 +6,18 @@
|
|
6 |
class SimpleWpMapOptions {
|
7 |
private $homeUrl;
|
8 |
|
9 |
-
// sets homeUrl with trailing slash
|
10 |
-
public function __construct() {
|
11 |
$this->homeUrl = esc_url(get_home_url() . (substr(get_home_url(), -1) === '/' ? '' : '/'));
|
12 |
}
|
13 |
|
14 |
// Returns a sitemap url
|
15 |
-
public function sitemapUrl($format) {
|
16 |
return sprintf('%ssitemap.%s', $this->homeUrl, $format);
|
17 |
}
|
18 |
|
19 |
// Updates the settings/options
|
20 |
-
public function setOptions($otherUrls, $blockUrls, $attrLink, $categories, $tags, $authors, $orderArray) {
|
21 |
@date_default_timezone_set(get_option('timezone_string'));
|
22 |
update_option('simple_wp_other_urls', $this->addUrls($otherUrls, get_option('simple_wp_other_urls')));
|
23 |
update_option('simple_wp_block_urls', $this->addUrls($blockUrls));
|
@@ -33,11 +33,11 @@ class SimpleWpMapOptions {
|
|
33 |
}
|
34 |
|
35 |
// Returns the options as strings to be displayed in textareas, checkbox values and orderarray (to do: refactor this messy function)
|
36 |
-
public function getOptions($val) {
|
37 |
-
if (
|
38 |
$val = get_option($val);
|
39 |
}
|
40 |
-
elseif (
|
41 |
return get_option($val) ? 'checked' : ''; // return checkbox checked values right here and dont bother with the loop below
|
42 |
}
|
43 |
elseif ($val === 'simple_wp_disp_sitemap_order' && ($orderArray = get_option($val))) {
|
@@ -47,18 +47,17 @@ class SimpleWpMapOptions {
|
|
47 |
$val = null;
|
48 |
}
|
49 |
|
|
|
50 |
if (!$this->isNullOrWhiteSpace($val)) {
|
51 |
-
$str = '';
|
52 |
foreach ($val as $sArr) {
|
53 |
$str .= $this->sanitizeUrl($sArr['url']) . "\n";
|
54 |
-
}
|
55 |
-
return trim($str);
|
56 |
}
|
57 |
-
return
|
58 |
}
|
59 |
|
60 |
// Checks if string/array is empty
|
61 |
-
private function isNullOrWhiteSpace($word) {
|
62 |
if (is_array($word)) {
|
63 |
return false;
|
64 |
}
|
@@ -66,12 +65,12 @@ class SimpleWpMapOptions {
|
|
66 |
}
|
67 |
|
68 |
// Sanitizes urls with esc_url and trim
|
69 |
-
private function sanitizeUrl($url) {
|
70 |
return esc_url(trim($url));
|
71 |
}
|
72 |
|
73 |
// Checks if orderArray has valid numbers (from 1 to 7)
|
74 |
-
private function checkOrder($numbers) {
|
75 |
if (is_array($numbers)) {
|
76 |
foreach ($numbers as $key => $num) {
|
77 |
if (!preg_match("/^[1-7]{1}$/", $num)) {
|
@@ -84,7 +83,7 @@ class SimpleWpMapOptions {
|
|
84 |
}
|
85 |
|
86 |
// Adds new urls to the sitemaps
|
87 |
-
private function addUrls($urls, $oldUrls=null) {
|
88 |
$arr = array();
|
89 |
|
90 |
if (!$this->isNullOrWhiteSpace($urls)) {
|
1 |
+
<?php if (!defined( 'ABSPATH' )) { die(); }
|
2 |
|
3 |
/*
|
4 |
* Class that handles all admin settings
|
6 |
class SimpleWpMapOptions {
|
7 |
private $homeUrl;
|
8 |
|
9 |
+
// Constructor: sets homeUrl with trailing slash
|
10 |
+
public function __construct () {
|
11 |
$this->homeUrl = esc_url(get_home_url() . (substr(get_home_url(), -1) === '/' ? '' : '/'));
|
12 |
}
|
13 |
|
14 |
// Returns a sitemap url
|
15 |
+
public function sitemapUrl ($format) {
|
16 |
return sprintf('%ssitemap.%s', $this->homeUrl, $format);
|
17 |
}
|
18 |
|
19 |
// Updates the settings/options
|
20 |
+
public function setOptions ($otherUrls, $blockUrls, $attrLink, $categories, $tags, $authors, $orderArray) {
|
21 |
@date_default_timezone_set(get_option('timezone_string'));
|
22 |
update_option('simple_wp_other_urls', $this->addUrls($otherUrls, get_option('simple_wp_other_urls')));
|
23 |
update_option('simple_wp_block_urls', $this->addUrls($blockUrls));
|
33 |
}
|
34 |
|
35 |
// Returns the options as strings to be displayed in textareas, checkbox values and orderarray (to do: refactor this messy function)
|
36 |
+
public function getOptions ($val) {
|
37 |
+
if (preg_match("/^simple_wp_(other_urls|block_urls)$/", $val)) {
|
38 |
$val = get_option($val);
|
39 |
}
|
40 |
+
elseif (preg_match("/^simple_wp_(attr_link|disp_categories|disp_tags|disp_authors)$/", $val)) {
|
41 |
return get_option($val) ? 'checked' : ''; // return checkbox checked values right here and dont bother with the loop below
|
42 |
}
|
43 |
elseif ($val === 'simple_wp_disp_sitemap_order' && ($orderArray = get_option($val))) {
|
47 |
$val = null;
|
48 |
}
|
49 |
|
50 |
+
$str = '';
|
51 |
if (!$this->isNullOrWhiteSpace($val)) {
|
|
|
52 |
foreach ($val as $sArr) {
|
53 |
$str .= $this->sanitizeUrl($sArr['url']) . "\n";
|
54 |
+
}
|
|
|
55 |
}
|
56 |
+
return trim($str);
|
57 |
}
|
58 |
|
59 |
// Checks if string/array is empty
|
60 |
+
private function isNullOrWhiteSpace ($word) {
|
61 |
if (is_array($word)) {
|
62 |
return false;
|
63 |
}
|
65 |
}
|
66 |
|
67 |
// Sanitizes urls with esc_url and trim
|
68 |
+
private function sanitizeUrl ($url) {
|
69 |
return esc_url(trim($url));
|
70 |
}
|
71 |
|
72 |
// Checks if orderArray has valid numbers (from 1 to 7)
|
73 |
+
private function checkOrder ($numbers) {
|
74 |
if (is_array($numbers)) {
|
75 |
foreach ($numbers as $key => $num) {
|
76 |
if (!preg_match("/^[1-7]{1}$/", $num)) {
|
83 |
}
|
84 |
|
85 |
// Adds new urls to the sitemaps
|
86 |
+
private function addUrls ($urls, $oldUrls=null) {
|
87 |
$arr = array();
|
88 |
|
89 |
if (!$this->isNullOrWhiteSpace($urls)) {
|