Simple Wp Sitemap - Version 1.1.6

Version Description

(Sep 27, 2016) = * 404 fix for disabled html sitemap * Couple bugfixes and some code cleanup

Download this release

Release Info

Developer Webbjocke
Plugin Icon 128x128 Simple Wp Sitemap
Version 1.1.6
Comparing to
See all releases

Code changes from version 1.1.5 to 1.1.6

css/simple-wp-sitemap-admin.css CHANGED
@@ -118,44 +118,16 @@
118
  left: 275px;
119
  top: 4px;
120
  }
121
- .simple-wp-s-image{
122
- width: 500px;
123
- max-width: 55%;
124
- border: 1px solid gray;
125
- box-shadow: 1px 1px 5px rgba(0,0,0,0.5);
126
- float: left;
127
- }
128
- .simple-wp-s-p{
129
- float: left;
130
- width: 39%;
131
- padding-right: 1%;
132
- }
133
- .simple-wp-right{
134
- text-align: right;
135
- }
136
- .simple-wp-also{
137
- float: left;
138
- width: 100%;
139
- list-style-type: square;
140
- padding-left: 25px;
141
- box-sizing: border-box;
142
- }
143
  .simple-wp-sitemap-includes{
144
  padding: 0 20px;
145
  margin: 0;
146
  list-style-type: disc;
147
  }
148
- @media screen and (max-width: 800px){
149
- .simple-wp-s-image{
150
- max-width: 100%;
151
- margin-top: 20px;
152
- }
153
- .simple-wp-s-p{
154
- width: 100%;
155
- }
156
- .simple-wp-right{
157
- text-align: left;
158
- }
159
  }
160
  @media screen and (max-width: 500px){
161
  #simple-wp-sitemap-donate img{
@@ -163,10 +135,6 @@
163
  display: block;
164
  margin: 10px 0 0 0;
165
  }
166
- .simple-wp-s-p{
167
- width: 100%;
168
- padding-right: 0;
169
- }
170
  #sitemap-settings{
171
  width: 100%;
172
  margin-bottom: 10px;
118
  left: 275px;
119
  top: 4px;
120
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  .simple-wp-sitemap-includes{
122
  padding: 0 20px;
123
  margin: 0;
124
  list-style-type: disc;
125
  }
126
+ #swpErrorText{
127
+ color: red;
128
+ }
129
+ #swpErrorText:hover{
130
+ cursor: pointer;
 
 
 
 
 
 
131
  }
132
  @media screen and (max-width: 500px){
133
  #simple-wp-sitemap-donate img{
135
  display: block;
136
  margin: 10px 0 0 0;
137
  }
 
 
 
 
138
  #sitemap-settings{
139
  width: 100%;
140
  margin-bottom: 10px;
js/simple-wp-sitemap-admin.js CHANGED
@@ -1,50 +1,84 @@
1
  (function ($) {
2
  var Sitemap = {
 
 
3
  run: function (config) {
4
  var self = this;
5
  this.c = config;
6
 
7
- this.c.btns.on('click', function () { self.changeState($(this)); });
8
- this.c.ul.on('click', function (e) { self.makeChange($(e.target)); });
9
- this.c.defaults.on('click', function () { self.restoreDefaults(); });
10
- this.c.form.on('submit', function (e) { e.preventDefault(); self.submitForm(); });
11
- this.c.theBtn.on('click', function () { self.upgrade(self.c.theField); });
12
- this.c.theField.on('keypress', function (e) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  if (e.which === 13) {
14
  e.preventDefault();
15
- self.upgrade(self.c.theField);
16
- }
17
- }).on('click', function () {
18
- if (self.c.error.text()) {
19
- self.c.error.text('');
20
  }
21
  });
22
 
23
- this.c.btns.each(function (i, btn) {
24
- if (self.c.activeP.val() === $(btn).attr('id')) {
25
- self.c.btns.eq(i).click();
26
  }
27
  });
28
-
29
- if (!this.c.textarea.val()) {
30
- this.c.textarea.attr('placeholder', 'http://www.example.com/a-page/\nhttp://www.example.com/fruits/apples.html');
31
- }
32
  },
33
 
34
- changeState: function (btn) {
35
- this.c.btns.attr('class', '');
 
36
  btn.attr('class', 'sitemap-active');
37
- this.c.tables.attr('id', '').parent().find('table[data-id="' + btn.attr('id') + '"]').attr('id', 'sitemap-table-show');
38
- this.c.activeP.val(btn.attr('id'));
 
 
 
 
 
39
  },
40
 
41
- makeChange: function (node) {
 
42
  var li = node.parent(), elem;
43
 
44
  if (node.attr('class') === 'sitemap-up' && li.prev()[0]) {
45
  li.prev().before(li);
 
46
  } else if (node.attr('class') === 'sitemap-down' && li.next()[0]) {
47
  li.next().after(li);
 
48
  } else if (node.hasClass('sitemap-change-btn')) {
49
  elem = li.find('.swp-name');
50
 
@@ -58,9 +92,10 @@
58
  }
59
  },
60
 
 
61
  submitForm: function () {
62
- var inputs = this.c.ul.find('input[type=hidden]'),
63
- titles = this.c.ul.find('[data-name]'),
64
  self = this;
65
 
66
  $.each(inputs, function (i, node) {
@@ -69,25 +104,31 @@
69
  this.c.form[0].submit();
70
  },
71
 
72
- upgrade: function (input) {
73
- var form = $('#simpleWpHiddenForm');
74
-
75
- form.find('input[type=hidden]').attr({name: 'upgrade_to_premium', value: this.esc(input.val())});
76
- form.submit();
 
 
77
  },
78
 
79
- restoreDefaults: function () {
 
80
  var sections = ['Home', 'Posts', 'Pages', 'Other', 'Categories', 'Tags', 'Authors'],
81
  html = '';
82
 
83
  $.each(sections, function (i) {
84
- html += '<li><span class="swp-name" data-name="' + sections[i].toLowerCase() + '">' + sections[i] + '</span><span class="sitemap-down" title="move down"></span><span class="sitemap-up" title="move up"></span>' +
85
- '<input type="hidden" name="simple_wp_' + sections[i].toLowerCase() + '_n" value="' + (i + 1) + '"><input type="button" value="Change" class="button-secondary sitemap-change-btn"></li>';
 
 
86
  });
87
- this.c.ul.html(html);
88
- this.c.updated.val('');
89
  },
90
 
 
91
  esc: function (str) {
92
  return str.replace(/[<"'>]/g, function (ch) {
93
  return {'<': "&lt;", '>': "&gt;", '"': '&quot;', '\'': '&#39;'}[ch];
@@ -97,15 +138,16 @@
97
 
98
  Sitemap.run({
99
  tables: $('#simple-wp-sitemap-form table'),
 
100
  textarea: $('#swsp-add-pages-textarea'),
101
- updated: $('#simple_wp_last_updated'),
102
- activeP: $('#simple_wp_active-page'),
 
 
103
  form: $('#simple-wp-sitemap-form'),
104
- defaults: $('#sitemap-defaults'),
105
- ul: $('#sitemap-display-order'),
106
- btns: $('#sitemap-settings li'),
107
- theBtn: $('#upgradeToPremium'),
108
- theField: $('#upgradeField'),
109
  error: $('#swpErrorText'),
110
  });
111
  })(jQuery);
1
  (function ($) {
2
  var Sitemap = {
3
+
4
+ // Constructor function
5
  run: function (config) {
6
  var self = this;
7
  this.c = config;
8
 
9
+ this.c.menuBtns.each(function (i, btn) {
10
+ btn = $(btn);
11
+
12
+ if (self.c.activePage.val() === btn.attr('id')) {
13
+ self.changeMenuState(btn);
14
+ }
15
+ });
16
+
17
+ this.bindEvents();
18
+ },
19
+
20
+ // Binds all events
21
+ bindEvents: function () {
22
+ var self = this;
23
+
24
+ this.c.menuBtns.on('click', function () {
25
+ self.changeMenuState($(this));
26
+ });
27
+
28
+ this.c.orderList.on('click', function (e) {
29
+ self.changeOrderItem($(e.target));
30
+ });
31
+
32
+ this.c.defaultBtn.on('click', function () {
33
+ self.restoreDefaultOrder();
34
+ });
35
+
36
+ this.c.form.on('submit', function (e) {
37
+ e.preventDefault();
38
+ self.submitForm();
39
+ });
40
+
41
+ this.c.premiumBtn.on('click', function () {
42
+ self.upgrade();
43
+ });
44
+
45
+ this.c.premiumInput.on('keypress', function (e) {
46
  if (e.which === 13) {
47
  e.preventDefault();
48
+ self.upgrade();
 
 
 
 
49
  }
50
  });
51
 
52
+ this.c.error.on('click', function (e) {
53
+ if (!$(e.target).is('a')) {
54
+ $(this).text('');
55
  }
56
  });
 
 
 
 
57
  },
58
 
59
+ // Changes menu state and active page
60
+ changeMenuState: function (btn) {
61
+ this.c.menuBtns.attr('class', '');
62
  btn.attr('class', 'sitemap-active');
63
+
64
+ this.c.tables.attr('id', '')
65
+ .parent()
66
+ .find('table[data-id="' + btn.attr('id') + '"]')
67
+ .attr('id', 'sitemap-table-show');
68
+
69
+ this.c.activePage.val(btn.attr('id'));
70
  },
71
 
72
+ // Changes an item in order menu
73
+ changeOrderItem: function (node) {
74
  var li = node.parent(), elem;
75
 
76
  if (node.attr('class') === 'sitemap-up' && li.prev()[0]) {
77
  li.prev().before(li);
78
+
79
  } else if (node.attr('class') === 'sitemap-down' && li.next()[0]) {
80
  li.next().after(li);
81
+
82
  } else if (node.hasClass('sitemap-change-btn')) {
83
  elem = li.find('.swp-name');
84
 
92
  }
93
  },
94
 
95
+ // Sets hidden fields values and submits the form to save changes
96
  submitForm: function () {
97
+ var inputs = this.c.orderList.find('input[type=hidden]'),
98
+ titles = this.c.orderList.find('[data-name]'),
99
  self = this;
100
 
101
  $.each(inputs, function (i, node) {
104
  this.c.form[0].submit();
105
  },
106
 
107
+ // Submits form to upgrade plugin to premium
108
+ upgrade: function () {
109
+ this.c.premiumForm.find('input[type=hidden]').attr({
110
+ name: 'upgrade_to_premium',
111
+ value: this.esc(this.c.premiumInput.val())
112
+ });
113
+ this.c.premiumForm.submit();
114
  },
115
 
116
+ // Restores default order options
117
+ restoreDefaultOrder: function () {
118
  var sections = ['Home', 'Posts', 'Pages', 'Other', 'Categories', 'Tags', 'Authors'],
119
  html = '';
120
 
121
  $.each(sections, function (i) {
122
+ html += '<li><span class="swp-name" data-name="' + sections[i].toLowerCase() + '">' + sections[i] + '</span>' +
123
+ '<span class="sitemap-down" title="move down"></span><span class="sitemap-up" title="move up"></span>' +
124
+ '<input type="hidden" name="simple_wp_' + sections[i].toLowerCase() + '_n" value="' + (i + 1) + '">' +
125
+ '<input type="button" value="Change" class="button-secondary sitemap-change-btn"></li>';
126
  });
127
+ this.c.orderList.html(html);
128
+ this.c.updatedText.val('');
129
  },
130
 
131
+ // Escapes some special chars
132
  esc: function (str) {
133
  return str.replace(/[<"'>]/g, function (ch) {
134
  return {'<': "&lt;", '>': "&gt;", '"': '&quot;', '\'': '&#39;'}[ch];
138
 
139
  Sitemap.run({
140
  tables: $('#simple-wp-sitemap-form table'),
141
+ updatedText: $('#simple_wp_last_updated'),
142
  textarea: $('#swsp-add-pages-textarea'),
143
+ activePage: $('#simple_wp_active-page'),
144
+ orderList: $('#sitemap-display-order'),
145
+ premiumForm: $('#simpleWpHiddenForm'),
146
+ menuBtns: $('#sitemap-settings li'),
147
  form: $('#simple-wp-sitemap-form'),
148
+ premiumBtn: $('#upgradeToPremium'),
149
+ defaultBtn: $('#sitemap-defaults'),
150
+ premiumInput: $('#upgradeField'),
 
 
151
  error: $('#swpErrorText'),
152
  });
153
  })(jQuery);
readme.txt CHANGED
@@ -6,7 +6,7 @@ License URI: http://www.gnu.org/licenses/gpl.html
6
  Tags: sitemap, site map, sitemap.xml, xml sitemap, html sitemap, simple sitemap, seo sitemap, google sitemap, sitemap.html, sitemap plugin, wordpress sitemap
7
  Requires at least: 4.0
8
  Tested up to: 4.6.1
9
- Stable tag: 1.1.5
10
 
11
  An easy sitemap plugin that adds both an xml and an html sitemap to your site, which updates and maintains themselves so you don't have to!
12
 
@@ -82,6 +82,10 @@ When you deactivate the plugin they get removed automatically.
82
 
83
  == Changelog ==
84
 
 
 
 
 
85
  = 1.1.5 (Sep 21, 2016) =
86
  * Added option to disable html sitemap
87
  * Plugin description changed
6
  Tags: sitemap, site map, sitemap.xml, xml sitemap, html sitemap, simple sitemap, seo sitemap, google sitemap, sitemap.html, sitemap plugin, wordpress sitemap
7
  Requires at least: 4.0
8
  Tested up to: 4.6.1
9
+ Stable tag: 1.1.6
10
 
11
  An easy sitemap plugin that adds both an xml and an html sitemap to your site, which updates and maintains themselves so you don't have to!
12
 
82
 
83
  == Changelog ==
84
 
85
+ = 1.1.6 (Sep 27, 2016) =
86
+ * 404 fix for disabled html sitemap
87
+ * Couple bugfixes and some code cleanup
88
+
89
  = 1.1.5 (Sep 21, 2016) =
90
  * Added option to disable html sitemap
91
  * Plugin description changed
simple-wp-sitemap.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Simple Wp Sitemap
5
  * Plugin URI: http://www.webbjocke.com/simple-wp-sitemap/
6
  * Description: An easy sitemap plugin that adds both an xml and an html sitemap to your site, which updates and maintains themselves so you don't have to!
7
- * Version: 1.1.5
8
  * Author: Webbjocke
9
  * Author URI: http://www.webbjocke.com/
10
  * License: GPLv3
@@ -31,7 +31,7 @@ along with this program. If not, see http://www.gnu.org/licenses/.
31
  // Main class
32
 
33
  class SimpleWpSitemap {
34
- private static $version = 13; // only changes when needed
35
 
36
  // Runs on plugin activation
37
  public static function activateSitemaps () {
@@ -104,16 +104,25 @@ class SimpleWpSitemap {
104
  public static function generateSitemapContent () {
105
  global $wp_query;
106
 
107
- if (isset($wp_query->query_vars['thesimplewpsitemap']) && (($q = $wp_query->query_vars['thesimplewpsitemap']) === 'xml' || ($q === 'html' && !get_option('simple_wp_block_html')))) {
108
  $wp_query->is_404 = false;
109
 
110
- require_once 'simpleWpMapBuilder.php';
111
- $sitemap = new SimpleWpMapBuilder();
112
-
113
- if ($q === 'xml') {
 
 
 
 
 
114
  header('Content-type: application/xml; charset=utf-8');
115
  }
116
- $sitemap->getContent($q);
 
 
 
 
117
  exit;
118
  }
119
  }
@@ -129,19 +138,19 @@ class SimpleWpSitemap {
129
  // Interface for settings page, also handles initial post request when settings are changed
130
  public static function sitemapAdminArea () {
131
  require_once 'simpleWpMapOptions.php';
132
- $options = new SimpleWpMapOptions();
133
 
134
- if (isset($_POST['simple_wp_other_urls'], $_POST['simple_wp_block_urls'], $_POST['simple_wp_home_n'], $_POST['simple_wp_posts_n'], $_POST['simple_wp_pages_n'], $_POST['simple_wp_other_n'], $_POST['simple_wp_categories_n'], $_POST['simple_wp_tags_n'], $_POST['simple_wp_authors_n'], $_POST['simple_wp_active-page'], $_POST['simple_wp_last_updated'])) {
 
135
 
136
- $order = $options->getDefaultOrder();
137
  foreach ($order as $key => $val) {
138
  $arr = explode('-|-', $_POST['simple_wp_' . $key . '_n']);
139
  $order[$key] = array('i' => $arr[0], 'title' => isset($arr[1]) ? $arr[1] : $key);
140
  }
141
- $options->setOptions($_POST['simple_wp_other_urls'], $_POST['simple_wp_block_urls'], (isset($_POST['simple_wp_attr_link']) ? 1 : 0), (isset($_POST['simple_wp_disp_categories']) ? 1 : 0), (isset($_POST['simple_wp_disp_tags']) ? 1 : 0), (isset($_POST['simple_wp_disp_authors']) ? 1 : 0), $order, $_POST['simple_wp_active-page'], $_POST['simple_wp_last_updated'], (isset($_POST['simple_wp_block_html']) ? 1 : 0));
142
  }
143
  elseif (isset($_POST['upgrade_to_premium'])) {
144
- $options->upgradePlugin($_POST['upgrade_to_premium']);
145
  }
146
  require_once 'simpleWpMapAdmin.php';
147
  }
4
  * Plugin Name: Simple Wp Sitemap
5
  * Plugin URI: http://www.webbjocke.com/simple-wp-sitemap/
6
  * Description: An easy sitemap plugin that adds both an xml and an html sitemap to your site, which updates and maintains themselves so you don't have to!
7
+ * Version: 1.1.6
8
  * Author: Webbjocke
9
  * Author URI: http://www.webbjocke.com/
10
  * License: GPLv3
31
  // Main class
32
 
33
  class SimpleWpSitemap {
34
+ private static $version = 16; // only changes when needed
35
 
36
  // Runs on plugin activation
37
  public static function activateSitemaps () {
104
  public static function generateSitemapContent () {
105
  global $wp_query;
106
 
107
+ if (isset($wp_query->query_vars['thesimplewpsitemap']) && in_array(($q = $wp_query->query_vars['thesimplewpsitemap']), array('xml', 'html'))) {
108
  $wp_query->is_404 = false;
109
 
110
+ if ($q === 'html') {
111
+ if ($htmlOpt = get_option('simple_wp_block_html')) {
112
+ if ($htmlOpt === '404') {
113
+ $wp_query->is_404 = true;
114
+ status_header(404);
115
+ }
116
+ return;
117
+ }
118
+ } else {
119
  header('Content-type: application/xml; charset=utf-8');
120
  }
121
+
122
+ require_once 'simpleWpMapBuilder.php';
123
+
124
+ $sitemap = new SimpleWpMapBuilder();
125
+ $sitemap->generateSitemap($q);
126
  exit;
127
  }
128
  }
138
  // Interface for settings page, also handles initial post request when settings are changed
139
  public static function sitemapAdminArea () {
140
  require_once 'simpleWpMapOptions.php';
141
+ $ops = new SimpleWpMapOptions();
142
 
143
+ if (isset($_POST['simple_wp_other_urls'], $_POST['simple_wp_block_urls'], $_POST['simple_wp_home_n'], $_POST['simple_wp_posts_n'], $_POST['simple_wp_pages_n'], $_POST['simple_wp_other_n'], $_POST['simple_wp_categories_n'], $_POST['simple_wp_tags_n'], $_POST['simple_wp_authors_n'], $_POST['simple_wp_active_page'], $_POST['simple_wp_last_updated'], $_POST['simple_wp_block_html'])) {
144
+ $order = $ops->getDefaultOrder();
145
 
 
146
  foreach ($order as $key => $val) {
147
  $arr = explode('-|-', $_POST['simple_wp_' . $key . '_n']);
148
  $order[$key] = array('i' => $arr[0], 'title' => isset($arr[1]) ? $arr[1] : $key);
149
  }
150
+ $ops->setOptions($_POST['simple_wp_other_urls'], $_POST['simple_wp_block_urls'], (isset($_POST['simple_wp_attr_link']) ? 1 : 0), (isset($_POST['simple_wp_disp_categories']) ? 1 : 0), (isset($_POST['simple_wp_disp_tags']) ? 1 : 0), (isset($_POST['simple_wp_disp_authors']) ? 1 : 0), $order, $_POST['simple_wp_active_page'], $_POST['simple_wp_last_updated'], $_POST['simple_wp_block_html']);
151
  }
152
  elseif (isset($_POST['upgrade_to_premium'])) {
153
+ $ops->upgradePlugin($_POST['upgrade_to_premium']);
154
  }
155
  require_once 'simpleWpMapAdmin.php';
156
  }
simpleWpMapAdmin.php CHANGED
@@ -4,18 +4,29 @@
4
  */
5
  ?>
6
  <div class="wrap">
 
7
  <h2 id="simple-wp-sitemap-h2">
8
- <img src="<?php printf('%ssign.png', $options->pluginUrl()); ?>" alt="logo" width="40" height="40">
9
  <span>Simple Wp Sitemap settings</span>
10
  </h2>
 
11
  <p>Your two sitemaps are active! Here you can change and customize them.</p>
12
  <p><strong>Links to your xml and html sitemap:</strong></p>
 
13
  <ul>
14
- <li>Xml sitemap: <a href="<?php echo $options->sitemapUrl('xml'); ?>"><?php echo $options->sitemapUrl('xml'); ?></a></li>
15
- <li>Html sitemap: <a href="<?php echo $options->sitemapUrl('html'); ?>"><?php echo $options->sitemapUrl('html'); ?></a> <?php if (get_option('simple_wp_block_html')) { echo '(disabled)'; } ?></li>
 
 
 
 
 
 
16
  </ul>
 
17
  <noscript>(Please enable javascript to edit options)</noscript>
18
- <form method="post" action="<?php echo $options->getSubmitUrl(); ?>" id="simple-wp-sitemap-form">
 
19
 
20
  <?php settings_fields('simple_wp-sitemap-group'); ?>
21
 
@@ -24,91 +35,213 @@
24
  <li id="sitemap-advanced">Order</li>
25
  <li id="sitemap-premium">Premium</li>
26
  </ul>
27
- <input type="hidden" id="simple_wp_active-page" name="simple_wp_active-page" value="<?php echo $options->getPage(); ?>">
 
28
 
29
  <table id="sitemap-table-show" class="widefat form-table table-hidden" data-id="sitemap-normal">
30
- <tr><td><strong>Add pages</strong></td></tr>
31
- <tr><td>Add pages to the sitemaps in addition to your normal wordpress ones. Just paste "full" urls in the textarea like: <strong>http://www.example.com/a-page/</strong>. Each link on a new row <em>(this will affect both your xml and html sitemap)</em>.</td></tr>
32
- <tr><td><textarea rows="7" name="simple_wp_other_urls" placeholder="http://www.example.com/a-page/" class="large-text code" id="swsp-add-pages-textarea"><?php echo $options->getOptions('simple_wp_other_urls'); ?></textarea></td></tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  <tr><td><hr></td></tr>
35
 
36
- <tr><td><strong>Block pages</strong></td></tr>
37
- <tr><td>Add pages you want to block from showing up in the sitemaps. Same as above, just paste every link on a new row. <em>(Hint: copy paste links from one of the sitemaps to get correct urls)</em>.</td></tr>
38
- <tr><td><textarea rows="7" name="simple_wp_block_urls" placeholder="http://www.example.com/block-this-page/" class="large-text code"><?php echo $options->getOptions('simple_wp_block_urls'); ?></textarea></td></tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  <tr><td><hr></td></tr>
41
 
42
- <tr><td><strong>Extra sitemap includes</strong></td></tr>
43
- <tr><td>Check if you want to include categories, tags and/or author pages in the sitemaps.</td></tr>
44
- <tr><td><input type="checkbox" name="simple_wp_disp_categories" id="simple_wp_cat" <?php echo $options->getOptions('simple_wp_disp_categories'); ?>><label for="simple_wp_cat"> Include categories</label></td></tr>
45
- <tr><td><input type="checkbox" name="simple_wp_disp_tags" id="simple_wp_tags" <?php echo $options->getOptions('simple_wp_disp_tags'); ?>><label for="simple_wp_tags"> Include tags</label></td></tr>
46
- <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>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  <tr><td><hr></td></tr>
49
 
50
- <tr><td><strong>Disable html sitemap</strong></td></tr>
51
- <tr><td>Check to disable the html sitemap if you only want to use the xml sitemap on your site.</td></tr>
52
- <tr><td><input type="checkbox" name="simple_wp_block_html" id="simple_wp_block_html" <?php echo $options->getOptions('simple_wp_block_html'); ?>><label for="simple_wp_block_html"> Disable html sitemap</label></td></tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
  <tr><td><hr></td></tr>
55
 
56
- <tr><td><strong>Like the plugin?</strong></td></tr>
57
- <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>
58
- <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>
59
- <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>
60
- </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  <table class="widefat form-table table-hidden" data-id="sitemap-advanced">
63
- <tr><td><strong>Display order &amp; titles</strong></td></tr>
64
- <tr><td>
65
- If you want to change the display order in your sitemaps, click the arrows to move sections up or down. They will be displayed as ordered below <em>(highest up is displayed first and lowest down last)</em>.<br><br>
66
- Hit the "Change" buttons to change the title displayed in the sitemaps.
67
- </td></tr>
68
- <tr><td>
69
- <ul id="sitemap-display-order">
70
- <?php if (!($orderArray = $options->getOptions('simple_wp_disp_sitemap_order'))) {
71
- $orderArray = $options->getDefaultOrder();
72
- }
73
- foreach ($orderArray as $key => $val) {
74
- printf('<li><span class="swp-name" data-name="%s">%s</span><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"><input type="button" value="Change" class="button-secondary sitemap-change-btn"></li>', $key, $val['title'], $key, $val['i']);
75
- } ?>
76
- </ul>
77
- </td></tr>
78
- <tr><td><strong>Last updated text:</strong> <input type="text" name="simple_wp_last_updated" placeholder="Last updated" value="<?php echo $options->getOptions('simple_wp_last_updated'); ?>" id="simple_wp_last_updated"></td></tr>
79
- <tr><td><input type="button" id="sitemap-defaults" class="button-secondary" title="Restore the default display order" value="Restore defaults"></td></tr>
80
- </table>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  <table class="widefat form-table table-hidden" data-id="sitemap-premium">
83
- <tr><td><strong>Simple Wp Sitemap Premium</strong></td></tr>
84
- <tr><td>Premium is an enhanced version of Simple Wp Sitemap and includes:</td></tr>
85
- <tr><td>
86
- <ul class="simple-wp-sitemap-includes">
87
- <li>Image sitemaps <em>(for better image SEO)</em></li>
88
- <li>Split sitemaps into multiple files</li>
89
- <li>Add your logo</li>
90
- <li>Custom css</li>
91
- <li>Color picker</li>
92
- <li>Https support</li>
93
- <li>Exclude directories</li>
94
- <li>Free updates</li>
95
- </ul>
96
- </td></tr>
 
 
 
 
 
 
 
 
 
97
 
98
  <tr><td><hr></td></tr>
99
 
100
- <tr><td><strong>If you have a premium code, enter it here to upgrade</strong><br><br>
101
- <input type="text" id="upgradeField" value="<?php echo $options->getPosted(); ?>"><span class="button-secondary" id="upgradeToPremium">Upgrade</span> <span style="color:red;" id="swpErrorText"><?php echo $options->getError(); ?></span></td></tr>
102
- <tr><td>
103
- <hr><br><strong>Available at</strong>: <a target="_blank" href="https://www.webbjocke.com/downloads/simple-wp-sitemap-premium">webbjocke.com/downloads/simple-wp-sitemap-premium</a>
104
- </td></tr>
105
- </table>
 
 
 
 
 
 
 
106
 
107
  <p class="submit"><input type="submit" class="button-primary" value="Save Changes"></p>
 
108
  <p><em>(If you have a caching plugin, you might have to clear cache before changes will be shown in the sitemaps)</em></p>
 
109
  </form>
110
 
111
- <form method="post" action="<?php echo $options->getSubmitUrl(); ?>" class="table-hidden" id="simpleWpHiddenForm">
112
  <input type="hidden">
113
  </form>
114
- </div>
 
4
  */
5
  ?>
6
  <div class="wrap">
7
+
8
  <h2 id="simple-wp-sitemap-h2">
9
+ <img src="<?php printf('%ssign.png', $ops->pluginUrl()); ?>" alt="logo" width="40" height="40">
10
  <span>Simple Wp Sitemap settings</span>
11
  </h2>
12
+
13
  <p>Your two sitemaps are active! Here you can change and customize them.</p>
14
  <p><strong>Links to your xml and html sitemap:</strong></p>
15
+
16
  <ul>
17
+ <li>Xml sitemap: <?php printf('<a href="%1$s">%1$s</a>', $ops->sitemapUrl('xml')); ?></li>
18
+ <li>Html sitemap:
19
+ <?php if ($ops->getOption('simple_wp_block_html')) {
20
+ echo '(disabled)';
21
+ } else {
22
+ printf('<a href="%1$s">%1$s</a>', $ops->sitemapUrl('html'));
23
+ } ?>
24
+ </li>
25
  </ul>
26
+
27
  <noscript>(Please enable javascript to edit options)</noscript>
28
+
29
+ <form method="post" action="<?php echo $ops->getSubmitUrl(); ?>" id="simple-wp-sitemap-form">
30
 
31
  <?php settings_fields('simple_wp-sitemap-group'); ?>
32
 
35
  <li id="sitemap-advanced">Order</li>
36
  <li id="sitemap-premium">Premium</li>
37
  </ul>
38
+
39
+ <input type="hidden" id="simple_wp_active-page" name="simple_wp_active_page" value="<?php echo $ops->getPage(); ?>">
40
 
41
  <table id="sitemap-table-show" class="widefat form-table table-hidden" data-id="sitemap-normal">
42
+ <tr>
43
+ <td>
44
+ <strong>Add pages</strong>
45
+ </td>
46
+ </tr>
47
+ <tr>
48
+ <td>
49
+ Add pages to the sitemaps in addition to your normal wordpress ones. Just paste "full" urls in the textarea like:
50
+ <strong>http://www.example.com/a-page/</strong>. Each link on a new row <em>(this will affect both your xml and html sitemap)</em>.
51
+ </td>
52
+ </tr>
53
+ <tr>
54
+ <td>
55
+ <textarea rows="7" name="simple_wp_other_urls" placeholder="http://www.example.com/a-page/" class="large-text code" id="swsp-add-pages-textarea"><?php echo $ops->getOption('simple_wp_other_urls'); ?></textarea>
56
+ </td>
57
+ </tr>
58
 
59
  <tr><td><hr></td></tr>
60
 
61
+ <tr>
62
+ <td>
63
+ <strong>Block pages</strong>
64
+ </td>
65
+ </tr>
66
+ <tr>
67
+ <td>
68
+ Add pages you want to block from showing up in the sitemaps. Same as above, just paste every link on a new row.
69
+ <em>(Hint: copy paste links from one of the sitemaps to get correct urls)</em>.
70
+ </td>
71
+ </tr>
72
+ <tr>
73
+ <td>
74
+ <textarea rows="7" name="simple_wp_block_urls" placeholder="http://www.example.com/block-this-page/" class="large-text code"><?php echo $ops->getOption('simple_wp_block_urls'); ?></textarea>
75
+ </td>
76
+ </tr>
77
 
78
  <tr><td><hr></td></tr>
79
 
80
+ <tr>
81
+ <td>
82
+ <strong>Extra sitemap includes</strong>
83
+ </td>
84
+ </tr>
85
+ <tr>
86
+ <td>
87
+ Check if you want to include categories, tags and/or author pages in the sitemaps.
88
+ </td>
89
+ </tr>
90
+ <tr>
91
+ <td>
92
+ <input type="checkbox" name="simple_wp_disp_categories" id="simple_wp_cat" <?php echo $ops->getOption('simple_wp_disp_categories'); ?>><label for="simple_wp_cat"> Include categories</label>
93
+ </td>
94
+ </tr>
95
+ <tr>
96
+ <td>
97
+ <input type="checkbox" name="simple_wp_disp_tags" id="simple_wp_tags" <?php echo $ops->getOption('simple_wp_disp_tags'); ?>><label for="simple_wp_tags"> Include tags</label>
98
+ </td>
99
+ </tr>
100
+ <tr>
101
+ <td>
102
+ <input type="checkbox" name="simple_wp_disp_authors" id="simple_wp_authors" <?php echo $ops->getOption('simple_wp_disp_authors'); ?>><label for="simple_wp_authors"> Include authors</label>
103
+ </td>
104
+ </tr>
105
 
106
  <tr><td><hr></td></tr>
107
 
108
+ <tr>
109
+ <td>
110
+ <strong>Html sitemap</strong>
111
+ </td>
112
+ </tr>
113
+ <tr>
114
+ <td>
115
+ Enable or disable your html sitemap. This will not effect your xml sitemap.
116
+ </td>
117
+ </tr>
118
+ <tr>
119
+ <td>
120
+ <select name="simple_wp_block_html" id="simple_wp_block_html">
121
+ <?php foreach (array('Enable' => '', 'Disable' => '1', 'Disable and set to 404' => '404') as $key => $val) {
122
+ printf('<option value="%s"%s>%s</option>', $val, $val == $ops->getOption('simple_wp_block_html') ? ' selected' : '', $key);
123
+ } ?>
124
+ </select>
125
+ </td>
126
+ </tr>
127
 
128
  <tr><td><hr></td></tr>
129
 
130
+ <tr>
131
+ <td>
132
+ <strong>Like the plugin?</strong>
133
+ </td>
134
+ </tr>
135
+ <tr>
136
+ <td>
137
+ Show your support by rating the plugin at wordpress.org, and/or by adding an attribution link to the sitemap.html file :)
138
+ </td>
139
+ </tr>
140
+ <tr>
141
+ <td>
142
+ <input type="checkbox" name="simple_wp_attr_link" id="simple_wp_check" <?php echo $ops->getOption('simple_wp_attr_link'); ?>><label for="simple_wp_check"> Add "Generated by Simple Wp Sitemap" link at bottom of sitemap.html.</label>
143
+ </td>
144
+ </tr>
145
+ <tr>
146
+ <td>
147
+ A donation is also always welcome!
148
+ <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=UH6ANJA7M8DNS" id="simple-wp-sitemap-donate" target="_blank">
149
+ <img src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" alt="PayPal - The safer, easier way to pay online!">
150
+ </a>
151
+ </td>
152
+ </tr>
153
+ </table><!-- sitemap-normal -->
154
 
155
  <table class="widefat form-table table-hidden" data-id="sitemap-advanced">
156
+ <tr>
157
+ <td>
158
+ <strong>Display order &amp; titles</strong>
159
+ </td>
160
+ </tr>
161
+ <tr>
162
+ <td>
163
+ If you want to change the display order in your sitemaps, click the arrows to move sections up or down. They will be displayed as ordered below <em>(highest up is displayed first and lowest down last)</em>.<br><br>
164
+ Hit the "Change" buttons to change the title displayed in the sitemaps.
165
+ </td>
166
+ </tr>
167
+ <tr>
168
+ <td>
169
+ <ul id="sitemap-display-order">
170
+ <?php if (!($orderArray = $ops->getOption('simple_wp_disp_sitemap_order'))) {
171
+ $orderArray = $ops->getDefaultOrder();
172
+ }
173
+ foreach ($orderArray as $key => $val) {
174
+ printf(
175
+ '<li><span class="swp-name" data-name="%s">%s</span><span class="sitemap-down" title="move down"></span><span class="sitemap-up" title="move up"></span>' .
176
+ '<input type="hidden" name="simple_wp_%s_n" value="%d"><input type="button" value="Change" class="button-secondary sitemap-change-btn"></li>',
177
+ $key, $val['title'], $key, $val['i']
178
+ );
179
+ } ?>
180
+ </ul>
181
+ </td>
182
+ </tr>
183
+ <tr>
184
+ <td>
185
+ <strong>Last updated text:</strong>
186
+ <input type="text" name="simple_wp_last_updated" placeholder="Last updated" value="<?php echo $ops->getOption('simple_wp_last_updated'); ?>" id="simple_wp_last_updated">
187
+ </td>
188
+ </tr>
189
+ <tr>
190
+ <td>
191
+ <input type="button" id="sitemap-defaults" class="button-secondary" title="Restore the default display order" value="Restore defaults">
192
+ </td>
193
+ </tr>
194
+ </table><!-- sitemap-advanced -->
195
 
196
  <table class="widefat form-table table-hidden" data-id="sitemap-premium">
197
+ <tr>
198
+ <td>
199
+ <strong>Simple Wp Sitemap Premium</strong>
200
+ </td>
201
+ </tr>
202
+ <tr>
203
+ <td>
204
+ Premium is an enhanced version of Simple Wp Sitemap and includes:
205
+ </td>
206
+ </tr>
207
+ <tr>
208
+ <td>
209
+ <ul class="simple-wp-sitemap-includes">
210
+ <li>Image sitemaps</li>
211
+ <li>Split sitemaps into multiple files</li>
212
+ <li>Add your logo</li>
213
+ <li>Custom css</li>
214
+ <li>Color picker</li>
215
+ <li>Exclude directories</li>
216
+ <li>And much more!</li>
217
+ </ul>
218
+ </td>
219
+ </tr>
220
 
221
  <tr><td><hr></td></tr>
222
 
223
+ <tr>
224
+ <td>
225
+ <strong>If you have a premium code, enter it here to upgrade</strong><br><br>
226
+ <input type="text" id="upgradeField" value="<?php echo $ops->getPosted(); ?>"><span class="button-secondary" id="upgradeToPremium">Upgrade</span>
227
+ <span id="swpErrorText"><?php echo $ops->getError(); ?></span>
228
+ </td>
229
+ </tr>
230
+ <tr>
231
+ <td>
232
+ <hr><br><strong>Available at</strong>: <a target="_blank" href="https://www.webbjocke.com/downloads/simple-wp-sitemap-premium/">webbjocke.com/downloads/simple-wp-sitemap-premium</a>
233
+ </td>
234
+ </tr>
235
+ </table><!-- sitemap-premium -->
236
 
237
  <p class="submit"><input type="submit" class="button-primary" value="Save Changes"></p>
238
+
239
  <p><em>(If you have a caching plugin, you might have to clear cache before changes will be shown in the sitemaps)</em></p>
240
+
241
  </form>
242
 
243
+ <form method="post" action="<?php echo $ops->getSubmitUrl(); ?>" class="table-hidden" id="simpleWpHiddenForm">
244
  <input type="hidden">
245
  </form>
246
+
247
+ </div><!-- wrap -->
simpleWpMapBuilder.php CHANGED
@@ -22,8 +22,8 @@ class SimpleWpMapBuilder {
22
 
23
  // Constructor
24
  public function __construct () {
25
- $this->url = esc_url(plugins_url() . '/simple-wp-sitemap');
26
- $this->homeUrl = esc_url(get_home_url() . (substr(get_home_url(), -1) === '/' ? '' : '/'));
27
  $this->categories = get_option('simple_wp_disp_categories') ? array(0 => 0) : false;
28
  $this->tags = get_option('simple_wp_disp_tags') ? array(0 => 0) : false;
29
  $this->authors = get_option('simple_wp_disp_authors') ? array(0 => 0) : false;
@@ -31,8 +31,8 @@ class SimpleWpMapBuilder {
31
  @date_default_timezone_set(get_option('timezone_string'));
32
  }
33
 
34
- // Generates the sitemaps and returns the content
35
- public function getContent ($type) {
36
  if ($type === 'xml' || $type === 'html') {
37
  $this->$type = true;
38
  $this->pattern = ($this->xml ? 'Y-m-d\TH:i:sP' : 'Y-m-d H:i');
@@ -40,7 +40,7 @@ class SimpleWpMapBuilder {
40
  $this->setUpBlockedUrls();
41
  $this->setLastUpdated();
42
  $this->generateContent();
43
- $this->mergeAndPrint();
44
  }
45
  }
46
 
@@ -97,15 +97,17 @@ class SimpleWpMapBuilder {
97
  while ($q->have_posts()) {
98
  $q->the_post();
99
 
100
- $link = esc_url(get_permalink());
101
  $date = get_the_modified_date($this->pattern);
102
  $this->getCategoriesTagsAndAuthor($date);
103
 
104
  if (!$this->isBlockedUrl($link)) {
105
  if (!$this->home && $link === $this->homeUrl) {
106
  $this->home = $this->getXml($link, $date);
 
107
  } elseif (get_post_type() === 'page') {
108
  $this->pages .= $this->getXml($link, $date);
 
109
  } else { // posts (also all custom post types are added here)
110
  $this->posts .= $this->getXml($link, $date);
111
  }
@@ -138,63 +140,75 @@ class SimpleWpMapBuilder {
138
  }
139
  }
140
 
141
- // Merges the arrays with post data into strings and gets user submitted pages, categories, tags and author pages
142
- public function mergeAndPrint () {
143
  if ($this->xml) {
144
- 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" . $this->sortAndGetString() . "</urlset>\n<!-- Sitemap content by Simple Wp Sitemap -->";
 
 
 
145
  } else {
146
- echo '<!doctype html><html lang="' . get_locale() . '"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>' . get_bloginfo('name') . ' Html Sitemap</title><link rel="stylesheet" href="' . $this->url . '/css/html.css"></head><body><div id="wrapper"><h1><a href="' . $this->homeUrl . '">' . get_bloginfo('name') . '</a> Html Sitemap</h1>' . $this->sortAndGetString() . $this->attributionLink() . "</div></body></html>\n<!-- Sitemap content by Simple Wp Sitemap -->";
 
 
147
  }
148
  }
149
 
150
- // Displays attribution link if user has checked the checkbox
151
- public function attributionLink () {
152
- if (get_option('simple_wp_attr_link')) {
153
- 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>';
154
- }
155
- return '';
156
- }
157
 
158
- // Sorts, builds up and returns the content in xml or html
159
- public function sortAndGetString () {
160
- if (!($orderArray = get_option('simple_wp_disp_sitemap_order')) || !isset($orderArray['home'])) {
161
- require_once 'simpleWpMapOptions.php'; $ops = new SimpleWpMapOptions(); $orderArray = $ops->migrateFromOld();
162
  }
163
  if (!$this->home) {
164
  $this->home = $this->getXml($this->homeUrl, date($this->pattern));
165
  }
166
 
167
- $str = '';
168
  foreach ($orderArray as $key => $arr) {
169
- $str .= $this->getTitleStr($key, $arr);
170
  }
171
- return $str;
172
  }
173
 
174
- // Gets titles xml or html
175
- public function getTitleStr ($title, $arr) {
176
- if ($xml = $this->$title ? $this->$title : '') {
177
  if (in_array($title, array('categories', 'tags', 'authors'))) {
178
- $xml = $this->stringifyCatsTagsAuths($xml, $title);
179
  }
180
- if ($xml) {
181
- $xml = $this->xml ? $xml : '<div class="header"><p class="header-txt">' . (($arr['title'] === 'Authors' && count($this->authors) <= 2) ? 'Author' : $arr['title']) . '</p><p class="header-date">' . $this->lastUpdated . '</p></div><ul>' . $xml . '</ul>';
 
 
 
 
 
 
182
  $this->$title = null;
183
  }
184
  }
185
- return $xml;
 
 
 
 
 
 
186
  }
187
 
188
  // Gets categories, tags and author links
189
- public function stringifyCatsTagsAuths ($content, $title) {
190
  $xml = '';
191
- if ($content) {
192
- foreach ($content as $id => $date) {
193
  if ($date) {
194
  switch ($title) {
195
- case 'tags': $link = esc_url(get_tag_link($id)); break;
196
- case 'categories': $link = esc_url(get_category_link($id)); break;
197
- default: $link = esc_url(get_author_posts_url($id)); // Authors
198
  }
199
  if (!$this->isBlockedUrl($link)) {
200
  $xml .= $this->getXml($link, $date);
22
 
23
  // Constructor
24
  public function __construct () {
25
+ $this->homeUrl = home_url('/');
26
+ $this->url = plugins_url() . '/simple-wp-sitemap/';
27
  $this->categories = get_option('simple_wp_disp_categories') ? array(0 => 0) : false;
28
  $this->tags = get_option('simple_wp_disp_tags') ? array(0 => 0) : false;
29
  $this->authors = get_option('simple_wp_disp_authors') ? array(0 => 0) : false;
31
  @date_default_timezone_set(get_option('timezone_string'));
32
  }
33
 
34
+ // Generates an xml or html sitemap
35
+ public function generateSitemap ($type) {
36
  if ($type === 'xml' || $type === 'html') {
37
  $this->$type = true;
38
  $this->pattern = ($this->xml ? 'Y-m-d\TH:i:sP' : 'Y-m-d H:i');
40
  $this->setUpBlockedUrls();
41
  $this->setLastUpdated();
42
  $this->generateContent();
43
+ $this->printOutput();
44
  }
45
  }
46
 
97
  while ($q->have_posts()) {
98
  $q->the_post();
99
 
100
+ $link = get_permalink();
101
  $date = get_the_modified_date($this->pattern);
102
  $this->getCategoriesTagsAndAuthor($date);
103
 
104
  if (!$this->isBlockedUrl($link)) {
105
  if (!$this->home && $link === $this->homeUrl) {
106
  $this->home = $this->getXml($link, $date);
107
+
108
  } elseif (get_post_type() === 'page') {
109
  $this->pages .= $this->getXml($link, $date);
110
+
111
  } else { // posts (also all custom post types are added here)
112
  $this->posts .= $this->getXml($link, $date);
113
  }
140
  }
141
  }
142
 
143
+ // Prints all output
144
+ public function printOutput () {
145
  if ($this->xml) {
146
+ 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";
147
+ $this->sortAndPrintSections();
148
+ echo '</urlset>';
149
+
150
  } else {
151
+ echo '<!doctype html><html lang="', get_locale(), '"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>', get_bloginfo('name'), ' Html Sitemap</title><link rel="stylesheet" href="', $this->url, 'css/html.css"></head><body><div id="wrapper"><h1><a href="', $this->homeUrl, '">', get_bloginfo('name'), '</a> Html Sitemap</h1>';
152
+ $this->sortAndPrintSections();
153
+ echo '</div></body></html>';
154
  }
155
  }
156
 
157
+ // Sorts and prints the content sections
158
+ public function sortAndPrintSections () {
159
+ $orderArray = get_option('simple_wp_disp_sitemap_order');
 
 
 
 
160
 
161
+ if (!$orderArray || !isset($orderArray['home'])) {
162
+ require_once 'simpleWpMapOptions.php';
163
+ $ops = new SimpleWpMapOptions();
164
+ $orderArray = $ops->migrateFromOld();
165
  }
166
  if (!$this->home) {
167
  $this->home = $this->getXml($this->homeUrl, date($this->pattern));
168
  }
169
 
 
170
  foreach ($orderArray as $key => $arr) {
171
+ $this->printSection($key, $arr);
172
  }
173
+ $this->attributionLink();
174
  }
175
 
176
+ // Prints a sections xml/html
177
+ public function printSection ($title, $arr) {
178
+ if ($this->$title) {
179
  if (in_array($title, array('categories', 'tags', 'authors'))) {
180
+ $this->$title = $this->getMetaLinks($title);
181
  }
182
+ if ($this->$title) {
183
+ if ($this->html) {
184
+ if ($arr['title'] === 'Authors' && count($this->authors) <= 2) {
185
+ $arr['title'] = 'Author';
186
+ }
187
+ $this->$title = '<div class="header"><p class="header-txt">' . esc_html($arr['title']) . '</p><p class="header-date">' . $this->lastUpdated . '</p></div><ul>' . $this->$title . '</ul>';
188
+ }
189
+ echo $this->$title;
190
  $this->$title = null;
191
  }
192
  }
193
+ }
194
+
195
+ // Displays attribution link if user has checked the checkbox
196
+ public function attributionLink () {
197
+ if ($this->html && get_option('simple_wp_attr_link')) {
198
+ echo '<p id="attr"><a id="attr-a" href="http://www.webbjocke.com/simple-wp-sitemap/" target="_blank" title="http://www.webbjocke.com/simple-wp-sitemap/">Generated by: Simple Wp Sitemap</a></p>';
199
+ }
200
  }
201
 
202
  // Gets categories, tags and author links
203
+ public function getMetaLinks ($title) {
204
  $xml = '';
205
+ if ($this->$title) {
206
+ foreach ($this->$title as $id => $date) {
207
  if ($date) {
208
  switch ($title) {
209
+ case 'tags': $link = get_tag_link($id); break;
210
+ case 'categories': $link = get_category_link($id); break;
211
+ default: $link = get_author_posts_url($id); // Authors
212
  }
213
  if (!$this->isBlockedUrl($link)) {
214
  $xml .= $this->getXml($link, $date);
simpleWpMapOptions.php CHANGED
@@ -5,16 +5,10 @@
5
  */
6
 
7
  class SimpleWpMapOptions {
8
- private $posted = '';
9
  private $error = '';
 
10
  private $cantDl = false;
11
  private $activePage = '';
12
- private $homeUrl;
13
-
14
- // Constructor: sets homeUrl with trailing slash
15
- public function __construct () {
16
- $this->homeUrl = $this->sanitizeUrl(get_home_url() . (substr(get_home_url(), -1) === '/' ? '' : '/'));
17
- }
18
 
19
  // Returns form submit url for the plugin directory
20
  public function getSubmitUrl () {
@@ -23,7 +17,7 @@ class SimpleWpMapOptions {
23
 
24
  // Returns a sitemap url
25
  public function sitemapUrl ($format) {
26
- return sprintf('%ssitemap.%s', $this->homeUrl, $format);
27
  }
28
 
29
  // Get the url to the plugin dir
@@ -36,7 +30,7 @@ class SimpleWpMapOptions {
36
  return array('home' => array('title' => 'Home', 'i' => 1), 'posts' => array('title' => 'Posts', 'i' => 2), 'pages' => array('title' => 'Pages', 'i' => 3), 'other' => array('title' => 'Other', 'i' => 4), 'categories' => array('title' => 'Categories', 'i' => 5), 'tags' => array('title' => 'Tags', 'i' => 6), 'authors' => array('title' => 'Authors', 'i' => 7));
37
  }
38
 
39
- // Updates the settings/options
40
  public function setOptions ($otherUrls, $blockUrls, $attrLink, $categories, $tags, $authors, $orderArray, $activePage, $lastUpdated, $blockHtml) {
41
  @date_default_timezone_set(get_option('timezone_string'));
42
  update_option('simple_wp_other_urls', $this->addUrls($otherUrls, get_option('simple_wp_other_urls')));
@@ -45,26 +39,30 @@ class SimpleWpMapOptions {
45
  update_option('simple_wp_disp_categories', $categories);
46
  update_option('simple_wp_disp_tags', $tags);
47
  update_option('simple_wp_disp_authors', $authors);
48
- update_option('simple_wp_block_html', $blockHtml);
49
- update_option('simple_wp_last_updated', $this->sanitHtml($lastUpdated));
50
 
51
  if ($this->checkOrder($orderArray) && uasort($orderArray, array($this, 'sortArr'))) { // sort the array here
52
  update_option('simple_wp_disp_sitemap_order', $orderArray);
53
  }
54
 
55
- $this->activePage = $this->sanitHtml($activePage);
56
  }
57
 
58
- // Returns the options as strings to be displayed in textareas, checkbox values and orderarray (to do: refactor this messy function)
59
- public function getOptions ($val) {
60
  if (preg_match("/^simple_wp_(other_urls|block_urls)$/", $val)) {
61
  $val = get_option($val);
62
- } elseif (preg_match("/^simple_wp_(attr_link|disp_categories|disp_tags|disp_authors|block_html)$/", $val)) {
 
63
  return get_option($val) ? 'checked' : ''; // return checkbox checked values right here and dont bother with the loop below
 
64
  } elseif ($val === 'simple_wp_disp_sitemap_order' && ($orderArray = get_option($val))) {
65
  return $this->checkOrder($orderArray);
66
- } elseif ($val === 'simple_wp_last_updated') {
67
- return $this->sanitHtml(get_option($val));
 
 
68
  } else {
69
  $val = null;
70
  }
@@ -72,7 +70,7 @@ class SimpleWpMapOptions {
72
  $str = '';
73
  if (!$this->isNullOrWhiteSpace($val)) {
74
  foreach ($val as $sArr) {
75
- $str .= $this->sanitizeUrl($sArr['url']) . "\n";
76
  }
77
  }
78
  return trim($str);
@@ -86,21 +84,16 @@ class SimpleWpMapOptions {
86
  return ($word === null || $word === false || trim($word) === '');
87
  }
88
 
89
- // Sanitizes urls with esc_url and trims
90
- public function sanitizeUrl ($url) {
91
- return esc_url(trim($url));
92
- }
93
-
94
- // Escapes and trims html
95
- public function sanitHtml ($html) {
96
- return stripslashes(esc_html(trim($html)));
97
  }
98
 
99
  // Checks if orderArray is valid
100
  public function checkOrder ($orderArray) {
101
  if (is_array($orderArray)) {
102
  foreach ($orderArray as $title => $arr) {
103
- if (!is_array($arr) || !preg_match("/^[1-7]{1}$/", $arr['i']) || (!($orderArray[$title]['title'] = $this->sanitHtml($arr['title'])))) {
104
  return false;
105
  }
106
  }
@@ -110,26 +103,26 @@ class SimpleWpMapOptions {
110
  }
111
 
112
  // Adds new urls to the sitemaps
113
- public function addUrls ($urls, $oldUrls=null) {
114
  $arr = array();
115
 
116
  if (!$this->isNullOrWhiteSpace($urls)) {
117
  $urls = explode("\n", $urls);
118
 
119
- foreach ($urls as $u){
120
- if (!$this->isNullOrWhiteSpace($u)) {
121
- $u = $this->sanitizeUrl($u);
122
- $b = false;
123
  if ($oldUrls && is_array($oldUrls)) {
124
- foreach ($oldUrls as $o) {
125
- if ($o['url'] === $u && !$b) {
126
- $arr[] = $o;
127
- $b = true;
128
  }
129
  }
130
  }
131
- if (!$b && strlen($u) < 500) {
132
- $arr[] = array('url' => $u, 'date' => time());
133
  }
134
  }
135
  }
@@ -139,7 +132,7 @@ class SimpleWpMapOptions {
139
 
140
  // Upgrades the plugin to premium
141
  public function upgradePlugin ($code) {
142
- $this->posted = $this->sanitHtml(strip_tags($code));
143
  $this->activePage = 'sitemap-premium';
144
  $url = 'https://www.webbjocke.com/downloads/update/'; // make sure it's https
145
 
@@ -163,6 +156,7 @@ class SimpleWpMapOptions {
163
  ));
164
 
165
  if (is_wp_error($res) || $res['response']['code'] !== 200) {
 
166
  throw new Exception('Could not connect to server. Try again later');
167
  }
168
  if (!$res['body'] || trim($res['body']) === '' || $res['body'] === 'Invalid Code') {
@@ -199,7 +193,7 @@ class SimpleWpMapOptions {
199
  $this->redirect();
200
 
201
  } catch (Exception $ex) {
202
- $this->error = $ex->getMessage();
203
  }
204
  }
205
 
@@ -213,12 +207,12 @@ class SimpleWpMapOptions {
213
  return $this->activePage;
214
  }
215
 
216
- // Get method for error text (empty string on default)
217
  public function getError () {
218
- if ($this->error) {
219
- return $this->sanitHtml($this->error) . ($this->cantDl ? '<p style="black">You might have to manually download and install the upgrade. Do it at <a href="https://www.webbjocke.com/downloads/manual-download/">webbjocke.com/downloads/manual-download</a></p>' : '');
220
  }
221
- return '';
222
  }
223
 
224
  // Sort function for "uasort"
@@ -229,8 +223,9 @@ class SimpleWpMapOptions {
229
  // Deletes old or current sitemap files and updates order options
230
  public function migrateFromOld () {
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);
5
  */
6
 
7
  class SimpleWpMapOptions {
 
8
  private $error = '';
9
+ private $posted = '';
10
  private $cantDl = false;
11
  private $activePage = '';
 
 
 
 
 
 
12
 
13
  // Returns form submit url for the plugin directory
14
  public function getSubmitUrl () {
17
 
18
  // Returns a sitemap url
19
  public function sitemapUrl ($format) {
20
+ return sprintf('%ssitemap.%s', home_url('/'), $format);
21
  }
22
 
23
  // Get the url to the plugin dir
30
  return array('home' => array('title' => 'Home', 'i' => 1), 'posts' => array('title' => 'Posts', 'i' => 2), 'pages' => array('title' => 'Pages', 'i' => 3), 'other' => array('title' => 'Other', 'i' => 4), 'categories' => array('title' => 'Categories', 'i' => 5), 'tags' => array('title' => 'Tags', 'i' => 6), 'authors' => array('title' => 'Authors', 'i' => 7));
31
  }
32
 
33
+ // Updates all options
34
  public function setOptions ($otherUrls, $blockUrls, $attrLink, $categories, $tags, $authors, $orderArray, $activePage, $lastUpdated, $blockHtml) {
35
  @date_default_timezone_set(get_option('timezone_string'));
36
  update_option('simple_wp_other_urls', $this->addUrls($otherUrls, get_option('simple_wp_other_urls')));
39
  update_option('simple_wp_disp_categories', $categories);
40
  update_option('simple_wp_disp_tags', $tags);
41
  update_option('simple_wp_disp_authors', $authors);
42
+ update_option('simple_wp_block_html', $this->esc($blockHtml));
43
+ update_option('simple_wp_last_updated', $this->esc($lastUpdated));
44
 
45
  if ($this->checkOrder($orderArray) && uasort($orderArray, array($this, 'sortArr'))) { // sort the array here
46
  update_option('simple_wp_disp_sitemap_order', $orderArray);
47
  }
48
 
49
+ $this->activePage = $this->esc($activePage);
50
  }
51
 
52
+ // Returns an option value (to do: refactor this messy function)
53
+ public function getOption ($val) {
54
  if (preg_match("/^simple_wp_(other_urls|block_urls)$/", $val)) {
55
  $val = get_option($val);
56
+
57
+ } elseif (preg_match("/^simple_wp_(attr_link|disp_categories|disp_tags|disp_authors)$/", $val)) {
58
  return get_option($val) ? 'checked' : ''; // return checkbox checked values right here and dont bother with the loop below
59
+
60
  } elseif ($val === 'simple_wp_disp_sitemap_order' && ($orderArray = get_option($val))) {
61
  return $this->checkOrder($orderArray);
62
+
63
+ } elseif ($val === 'simple_wp_last_updated' || ($val === 'simple_wp_block_html' && get_option($val))) {
64
+ return $this->esc(get_option($val));
65
+
66
  } else {
67
  $val = null;
68
  }
70
  $str = '';
71
  if (!$this->isNullOrWhiteSpace($val)) {
72
  foreach ($val as $sArr) {
73
+ $str .= $this->esc($sArr['url'], 'url') . "\n";
74
  }
75
  }
76
  return trim($str);
84
  return ($word === null || $word === false || trim($word) === '');
85
  }
86
 
87
+ // Escapes urls and html
88
+ public function esc ($str, $isUrl = false) {
89
+ return $isUrl ? esc_url(trim($str)) : stripslashes(esc_html(trim($str)));
 
 
 
 
 
90
  }
91
 
92
  // Checks if orderArray is valid
93
  public function checkOrder ($orderArray) {
94
  if (is_array($orderArray)) {
95
  foreach ($orderArray as $title => $arr) {
96
+ if (!is_array($arr) || !preg_match("/^[1-7]{1}$/", $arr['i']) || (!($orderArray[$title]['title'] = $this->esc($arr['title'])))) {
97
  return false;
98
  }
99
  }
103
  }
104
 
105
  // Adds new urls to the sitemaps
106
+ public function addUrls ($urls, $oldUrls = null) {
107
  $arr = array();
108
 
109
  if (!$this->isNullOrWhiteSpace($urls)) {
110
  $urls = explode("\n", $urls);
111
 
112
+ foreach ($urls as $url){
113
+ if (!$this->isNullOrWhiteSpace($url)) {
114
+ $url = $this->esc($url, 'url');
115
+ $isOld = false;
116
  if ($oldUrls && is_array($oldUrls)) {
117
+ foreach ($oldUrls as $oldUrl) {
118
+ if ($oldUrl['url'] === $url && !$isOld) {
119
+ $arr[] = $oldUrl;
120
+ $isOld = true;
121
  }
122
  }
123
  }
124
+ if (!$isOld && strlen($url) < 2000) {
125
+ $arr[] = array('url' => $url, 'date' => time());
126
  }
127
  }
128
  }
132
 
133
  // Upgrades the plugin to premium
134
  public function upgradePlugin ($code) {
135
+ $this->posted = $this->esc($code);
136
  $this->activePage = 'sitemap-premium';
137
  $url = 'https://www.webbjocke.com/downloads/update/'; // make sure it's https
138
 
156
  ));
157
 
158
  if (is_wp_error($res) || $res['response']['code'] !== 200) {
159
+ $this->cantDl = true;
160
  throw new Exception('Could not connect to server. Try again later');
161
  }
162
  if (!$res['body'] || trim($res['body']) === '' || $res['body'] === 'Invalid Code') {
193
  $this->redirect();
194
 
195
  } catch (Exception $ex) {
196
+ $this->error = $this->esc($ex->getMessage());
197
  }
198
  }
199
 
207
  return $this->activePage;
208
  }
209
 
210
+ // Returns error message if upgrade went wrong (empty string on default)
211
  public function getError () {
212
+ if ($this->error && $this->cantDl) {
213
+ $this->error .= '<br><b>You might have to download and install the upgrade manually</b>';
214
  }
215
+ return $this->error;
216
  }
217
 
218
  // Sort function for "uasort"
223
  // Deletes old or current sitemap files and updates order options
224
  public function migrateFromOld () {
225
  if (function_exists('get_home_path')) {
 
226
  try {
227
+ $path = sprintf('%ssitemap.', get_home_path());
228
+
229
  foreach (array('xml', 'html') as $file) {
230
  if (file_exists($path . $file)) {
231
  unlink($path . $file);