Simple Wp Sitemap - Version 1.0.0

Version Description

  • Initial public release
Download this release

Release Info

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

Version 1.0.0

css/html.css ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *{
2
+ margin: 0;
3
+ padding: 0;
4
+ }
5
+ html{
6
+ background: #edf4fa;
7
+ }
8
+ body{
9
+ max-width: 960px;
10
+ margin: 20px auto;
11
+ padding: 20px 4%;
12
+ box-shadow: 1px 1px 5px #d1d1d1;
13
+ font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
14
+ background: white;
15
+ border-radius: 5px;
16
+ }
17
+ h1{
18
+ margin: 10px 0 20px 5px;
19
+ }
20
+ p{
21
+ float: left;
22
+ word-break: break-all;
23
+ }
24
+ p:nth-child(2n){
25
+ float: right;
26
+ }
27
+ a{
28
+ text-decoration: none;
29
+ color: black;
30
+ padding: 5px;
31
+ transition: all 0.3s;
32
+ }
33
+ a:hover{
34
+ background: #b2cde0;
35
+ color: white;
36
+ }
37
+ div{
38
+ overflow: auto;
39
+ padding: 5px 5px 5px 0;
40
+ border-left: 1px solid #0f669c;
41
+ border-right: 1px solid #0f669c;
42
+ border-bottom: 1px solid #0f669c;
43
+ }
44
+ div:nth-child(2n){
45
+ background: #edf4fa;
46
+ }
47
+ div:nth-child(2){
48
+ border-top: 1px solid #0f669c;
49
+ }
50
+ div.header{
51
+ background: #b2cde0;
52
+ padding-left: 5px;
53
+ }
54
+ div:last-child{
55
+ margin-bottom: 20px;
56
+ }
57
+ #attr{
58
+ float: none;
59
+ margin: 25px 0 0 0;
60
+ text-align: right;
61
+ font-size: 0.8em;
62
+ color: gray;
63
+ }
64
+ #attr a{
65
+ color: gray;
66
+ }
67
+ #attr a:hover{
68
+ color: #b2cde0;
69
+ background: none;
70
+ }
71
+ @media screen and (max-width: 960px){
72
+ a{
73
+ padding: 5px 0;
74
+ }
75
+ p{
76
+ width: 100%;
77
+ margin-left: 5px;
78
+ }
79
+ p:nth-child(2){
80
+ float: left;
81
+ margin-left: 5px;
82
+ }
83
+ }
css/index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // silence is golden
css/xml.css ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ urlset{
2
+ max-width: 960px;
3
+ margin: 10px auto;
4
+ font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
5
+ }
6
+ url{
7
+ display: block;
8
+ overflow: auto;
9
+ padding: 5px;
10
+ font-size: 0.9em;
11
+ border-top: 1px solid gray;
12
+ border-right: 1px solid gray;
13
+ border-left: 1px solid gray;
14
+ word-break: break-all;
15
+ }
16
+ url:nth-child(2n+1){
17
+ background: whitesmoke;
18
+ }
19
+ url:last-child{
20
+ border-bottom: 1px solid gray;
21
+ }
22
+ loc{
23
+ float: left;
24
+ }
25
+ lastmod{
26
+ float: right;
27
+ }
28
+ @media screen and (max-width: 800px){
29
+ loc, lastmod{
30
+ width: 100%;
31
+ float: left;
32
+ }
33
+ }
index.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php // silence is golden
readme.txt ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.1.1
8
+ Stable tag: 1.0.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
+
12
+ == Description ==
13
+
14
+ Simple Wp Sitemap is a plugin that serves both an xml and an html sitemap to your page as static files. These are updated automatically everytime a post or page is created, edited or deleted, and makes sure they're easily indexed. What this means you only have to install and activate the plugin once, and it will just work for you without you ever having to worry.
15
+
16
+ Reason the sitemaps are created as static files and aren't generated everytime someone's visiting them, is because of the awesome performance that comes with not having to do database queries and php rendering all day. Sure you have to wait a couple milliseconds extra when you create a new or edit a post, but in my opinion that's totally worth it!
17
+
18
+ Also supports the option to add pages to the sitemaps that aren't part of your original wordpress site. For instance if you create a little html file and upload to your server and want it to be included in the sitemaps, it's easily done. You can also block pages that you don't want to be included in them.
19
+
20
+ So why use this instead of the other hundreds(?) of sitemap plugins that's out are and which has thousands(?) of downloads? Well for one thing it's just an easy, fast and secure plugin that will just work for you, and it also makes the life pretty easy for search engines that wants to index your site!
21
+
22
+ == Installation ==
23
+
24
+ 1. a. Go to the plugins page in your wordpress admin area and hit "add new".
25
+ b. Either search for "simple-wp-sitemap" and click install, or hit "upload plugin" and upload the zip file.
26
+ c. Another way is by just uploading the "simple-wp-sitemap" folder via ftp to the /wp-content/plugins/ directory.
27
+
28
+ 2. Activate the plugin and thats it, done.
29
+
30
+ 3. Customize the plugin and add/block pages by hitting the "Simple Wp Sitemap" option in the settings menu.
31
+
32
+ == Frequently asked questions ==
33
+
34
+ None so far :)
35
+
36
+ == Screenshots ==
37
+
38
+ A couple will be added soon with examples on how to customize the plugin and how the sitemaps looks like.
39
+
40
+ == Changelog ==
41
+
42
+ = 1.0.0 =
43
+ * Initial public release
simple-wp-sitemap.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (!defined( 'ABSPATH' )){ die(); }
2
+
3
+ /*
4
+ * Plugin Name: Simple Wp Sitemap
5
+ * Plugin URI: http://www.webbjocke.com/
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.0
8
+ * Author: Webbjocke
9
+ * Author URI: http://www.webbjocke.com/
10
+ * License: GPLv3
11
+ */
12
+
13
+
14
+ // Main class
15
+
16
+ class SimpleWpSitemap {
17
+
18
+ // Updates the sitemaps
19
+ public static function updateSitemaps (){
20
+ require_once('simpleWpMapBuilder.php');
21
+ new SimpleWpMapBuilder('generate');
22
+ }
23
+
24
+ // Delete the files sitemap.xml and sitemap.html on deactivate
25
+ public static function removeSitemaps (){
26
+ require_once('simpleWpMapBuilder.php');
27
+ new SimpleWpMapBuilder('delete');
28
+ }
29
+
30
+ // Sets the menu option for admins
31
+ public static function sitemapAdminSetup (){
32
+ add_options_page('Simple Wp Sitemap', 'Simple Wp Sitemap', 'administrator', 'simpleWpSitemapSettings', array('SimpleWpSitemap', 'sitemapAdminArea'));
33
+ add_action('admin_init', array('SimpleWpSitemap', 'sitemapAdminInit'));
34
+ }
35
+
36
+ // Registers settings on admin_init
37
+ public static function sitemapAdminInit(){
38
+ register_setting('simple_wp-sitemap-group', 'simple_wp_other_urls');
39
+ register_setting('simple_wp-sitemap-group', 'simple_wp_block_urls');
40
+ register_setting('simple_wp-sitemap-group', 'simple_wp_attr_link');
41
+ }
42
+
43
+ // Interface for settings page, also handles initial post request when settings are changed
44
+ public static function sitemapAdminArea (){
45
+ require_once('simpleWpMapOptions.php');
46
+ $options = new SimpleWpMapOptions();
47
+
48
+ if (isset($_POST['simple_wp_other_urls'], $_POST['simple_wp_block_urls'])){
49
+ $options->setOptions($_POST['simple_wp_other_urls'], $_POST['simple_wp_block_urls'], isset($_POST['simple_wp_attr_link']) ? 1 : 0);
50
+ self::updateSitemaps();
51
+ } ?>
52
+
53
+ <div class="wrap">
54
+ <h1>Simple Wp Sitemap settings</h1>
55
+
56
+ <p>Change and customize the sitemap</p>
57
+
58
+ <form method="post" action="options-general.php?page=simpleWpSitemapSettings">
59
+
60
+ <?php settings_fields('simple_wp-sitemap-group'); ?>
61
+
62
+ <table class="widefat form-table">
63
+
64
+ <tr><td><b>Add pages</b></td></tr>
65
+ <tr><td>Add pages to the sitemaps in addition to the original wordpress ones. Just paste "absolute" links in the textarea like: <b>http://www.example.com/</b>, each link on a new row.</td></tr>
66
+ <tr><td><textarea rows="7" name="simple_wp_other_urls" class="large-text code"><?php echo $options->getOptions('simple_wp_other_urls'); ?></textarea></td></tr>
67
+
68
+ <tr><td><b>Block pages</b></td></tr>
69
+ <tr><td>Add pages you dont't want to show up in the sitemaps. Same as above and just paste every link on a new row. (Hint: go to the sitemap.xml file and copy the whole link from there and paste it here).</td></tr>
70
+ <tr><td><textarea rows="7" name="simple_wp_block_urls" class="large-text code"><?php echo $options->getOptions('simple_wp_block_urls'); ?></textarea></td></tr>
71
+
72
+ <tr><td><b>Like the plugin?</b></td></tr>
73
+ <tr><td>Show your support by rating the plugin at wordpress.org, or atleast by adding an attribution link to the sitemap.html file :)</td></tr>
74
+ <tr><td><input type="checkbox" name="simple_wp_attr_link" id="simple_wp_check" <?php echo $options->getOptions('simple_wp_attr_link'); ?>></input> <label for="simple_wp_check">Add "Generated by Simple Wp Sitemap" link to bottom of sitemap.html.</label></td></tr>
75
+
76
+ </table>
77
+
78
+ <p class="submit"><input type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>"></p>
79
+
80
+ </form>
81
+
82
+ </div>
83
+ <?php }
84
+ }
85
+ add_action('admin_menu', array('SimpleWpSitemap', 'sitemapAdminSetup'));
86
+ add_action('deleted_post', array('SimpleWpSitemap', 'updateSitemaps'));
87
+ add_action('save_post', array('SimpleWpSitemap', 'updateSitemaps'));
88
+ register_activation_hook(__FILE__, array('SimpleWpSitemap', 'updateSitemaps'));
89
+ register_deactivation_hook(__FILE__, array('SimpleWpSitemap', 'removeSitemaps'));
simpleWpMapBuilder.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (!defined( 'ABSPATH' )){ die(); }
2
+
3
+ /*
4
+ * The sitemap creating class
5
+ */
6
+ class SimpleWpMapBuilder {
7
+ private $xml;
8
+ private $html;
9
+ private $file;
10
+ private $url;
11
+ private $homeUrl;
12
+ private $blockedUrls;
13
+
14
+ // Constructor, the only public function this class has
15
+ public function __construct($command){
16
+ $this->url = esc_url(plugins_url() . '/simple-wp-sitemap');
17
+ $this->homeUrl = esc_url(get_home_url() . (substr(get_home_url(), -1) === '/' ? '' : '/'));
18
+
19
+ switch($command){
20
+ case 'generate':
21
+ $this->generateSitemaps();
22
+ break;
23
+ case 'delete':
24
+ $this->deleteSitemaps();
25
+ break;
26
+ }
27
+ }
28
+
29
+ // Generates the maps
30
+ private function generateSitemaps(){
31
+ $this->setUpBlockedUrls();
32
+ $this->getContent();
33
+
34
+ $this->writeToFile($this->xml, 'xml');
35
+ $this->writeToFile($this->html, 'html');
36
+ }
37
+
38
+ // Deletes the maps
39
+ private function deleteSitemaps(){
40
+ $this->deleteFile('xml');
41
+ $this->deleteFile('html');
42
+ }
43
+
44
+ // Returns other urls (not standard wordpress) user has submitted
45
+ private function getOtherPages(){
46
+ $options = get_option('simple_wp_other_urls');
47
+ $html = '';
48
+ $xml = '';
49
+
50
+ if ($options){
51
+ foreach($options as $option){
52
+ if ($option && is_array($option)){
53
+ $html .= $this->getHtml($option['url'], $option['date']);
54
+ $xml .= $this->getXml($option['url'], $option['date']);
55
+ }
56
+ }
57
+ }
58
+ return array('xml' => $xml, 'html' => $html);
59
+ }
60
+
61
+ // Sets up blocked urls into an array
62
+ private function setUpBlockedUrls(){
63
+ $blocked = get_option('simple_wp_block_urls');
64
+ if ($blocked && is_array($blocked)){
65
+ $this->blockedUrls = array();
66
+
67
+ foreach($blocked as $block){
68
+ $this->blockedUrls[] = $block['url'];
69
+ }
70
+ }
71
+ else{
72
+ $this->blockedUrls = null;
73
+ }
74
+ }
75
+
76
+ // Matches url against all blocked ones that shouldn't be displayed
77
+ private function isBlockedUrl($url){
78
+ return $this->blockedUrls && in_array($url, $this->blockedUrls);
79
+ }
80
+
81
+ // Returns an html string
82
+ private function getHtml($link, $date){
83
+ return "\t<div>\n\t\t<p><a title=\"$link\" href=\"$link\">$link</a></p>\n\t\t<p>$date</p>\n\t</div>\n";
84
+ }
85
+
86
+ // Returns an xml string
87
+ private function getXml($link, $date){
88
+ return "<url>\n\t<loc>$link</loc>\n\t<lastmod>$date</lastmod>\n</url>\n";
89
+ }
90
+
91
+ // Returns table headers with specific names (has been changed to div)
92
+ private function htmlTableH($name){
93
+ return "\t<div class=\"header\">\n\t\t<p>$name:</p>\n\t\t<p>Last modified:</p>\n\t</div>\n";
94
+ }
95
+
96
+ // Creates the actual sitemaps content, and querys the database
97
+ private function getContent(){
98
+ $q = new WP_Query('post_type=any&posts_per_page=-1');
99
+ $name = get_bloginfo('name');
100
+ $xml = sprintf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/css\" href=\"%s/css/xml.css\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n", $this->url);
101
+ $html = sprintf("<!doctype html>\n<html>\n<head>\n\t<meta charset=\"utf-8\">\n\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n\t<title>%s Html Sitemap</title>\n\t<link rel=\"stylesheet\" href=\"%s/css/html.css\">\n</head>\n<body>\n\t<h1>%s Html Sitemap</h1>\n%s", $name, $this->url, $name, $this->htmlTableH('Home'));
102
+ $posts = array('xml' => '', 'html' => '');
103
+ $pages = array('xml' => '', 'html' => '');
104
+ $others = array('xml' => '', 'html' => '');
105
+ $homePage = false;
106
+
107
+ if ($q->have_posts()) {
108
+ while ($q->have_posts()) {
109
+ $q->the_post();
110
+
111
+ $link = esc_url(get_permalink());
112
+ $date = esc_html(get_the_modified_date('Y-m-d\TH:i:sP'));
113
+
114
+ if (!$this->isBlockedUrl($link)){
115
+ if ($link === $this->homeUrl){
116
+ $xml .= $this->getXml($link, $date);
117
+ $html .= $this->getHtml($link, $date);
118
+ $homePage = true;
119
+ }
120
+ elseif ('post' === get_post_type()){
121
+ $posts['xml'] .= $this->getXml($link, $date);
122
+ $posts['html'] .= $this->getHtml($link, $date);
123
+ }
124
+ elseif ('page' === get_post_type()){
125
+ $pages['xml'] .= $this->getXml($link, $date);
126
+ $pages['html'] .= $this->getHtml($link, $date);
127
+ }
128
+ else{
129
+ $others['xml'] .= $this->getXml($link, $date);
130
+ $others['html'] .= $this->getHtml($link, $date);
131
+ }
132
+ }
133
+ }
134
+ }
135
+
136
+ $localArr = $this->mergeArraysAndGetOtherPages($posts, $pages, $others, $homePage);
137
+
138
+ $this->xml = sprintf("%s%s</urlset>", $xml, $localArr['xml']);
139
+ $this->html = sprintf("%s%s\n\t%s</body>\n</html>", $html, $localArr['html'], $this->attributionLink());
140
+ wp_reset_postdata();
141
+ }
142
+
143
+ // Displays attribution link. Not default, user has to check a checkbox for this to be displayed (returns an empty string as default)
144
+ private function attributionLink(){
145
+ if (get_option('simple_wp_attr_link')){
146
+ return "<p id=\"attr\">Generated by: <a href=\"http://www.webbjocke.com/\">Simple Wp Sitemap</a></p>"; // will be changed to like webbjocke.com/simple-wp-sitemap or plugin page on wordpress.org if the plugin gets accepted
147
+ }
148
+ return '';
149
+ }
150
+
151
+ // Merges the arrays with post data into strings and gets user submitted pages
152
+ private function mergeArraysAndGetOtherPages($posts, $pages, $others, $homePage){
153
+ $xml = '';
154
+ $html = '';
155
+
156
+ if (!$homePage){ // if homepage isn't found in the query add it here (for instance if it's not a real "page" it wont be found)
157
+ $date = date('Y-m-d\TH:i:sP');
158
+ $xml .= $this->getXml($this->homeUrl, $date);
159
+ $html .= $this->getHtml($this->homeUrl, $date);
160
+ }
161
+
162
+ if ($posts['xml']) {
163
+ $xml .= $posts['xml'];
164
+ $html .= $this->htmlTableH('Posts') . $posts['html'];
165
+ }
166
+ if ($pages['xml']) {
167
+ $xml .= $pages['xml'];
168
+ $html .= $this->htmlTableH('Pages') . $pages['html'];
169
+ }
170
+ if ($others['xml']) {
171
+ $xml .= $others['xml'];
172
+ $html .= $this->htmlTableH('Other') . $others['html'];
173
+ }
174
+
175
+ $otherPages = $this->getOtherPages();
176
+ if ($otherPages['xml']){
177
+ $xml .= $otherPages['xml'];
178
+ $html .= (!$others['html'] ? $this->htmlTableH('Other') : '') . $otherPages['html'];
179
+ }
180
+
181
+ return array('xml' => $xml, 'html' => $html);
182
+ }
183
+
184
+ // Sets up file paths to home directory
185
+ private function setFile($fileType){
186
+ $this->file = sprintf("%s%ssitemap.%s", get_home_path(), (substr(get_home_path(), -1) === '/' ? '' : '/'), $fileType);
187
+ }
188
+
189
+ // Creates sitemap files and overrides old ones if there are any
190
+ private function writeToFile($data, $fileType){
191
+ $this->setFile($fileType);
192
+ try{
193
+ $fp = fopen($this->file, 'w');
194
+ if (file_exists($this->file)){
195
+ fwrite($fp, $data);
196
+ fclose($fp);
197
+ }
198
+ }
199
+ catch(Exception $ex){
200
+ die();
201
+ }
202
+ }
203
+
204
+ // Deletes the sitemap files
205
+ private function deleteFile($fileType){
206
+ $this->setFile($fileType);
207
+ try{
208
+ unlink($this->file);
209
+ }
210
+ catch(Exception $ex){
211
+ die();
212
+ }
213
+ }
214
+ }
simpleWpMapOptions.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (!defined( 'ABSPATH' )){ die(); }
2
+
3
+ /*
4
+ * Class that handles all admin settings
5
+ */
6
+ class SimpleWpMapOptions {
7
+
8
+ // Updates the settings/options
9
+ public function setOptions($otherUrls, $blockUrls, $attrLink){
10
+ update_option('simple_wp_other_urls', $this->addUrls($otherUrls, get_option('simple_wp_other_urls')));
11
+ update_option('simple_wp_block_urls', $this->addUrls($blockUrls));
12
+ update_option('simple_wp_attr_link', $attrLink);
13
+ }
14
+
15
+ // Returns the options as strings to be displayed in textareas, and checkbox values
16
+ public function getOptions($val){
17
+ switch($val){
18
+ case 'simple_wp_other_urls':
19
+ $val = get_option('simple_wp_other_urls');
20
+ break;
21
+ case 'simple_wp_block_urls':
22
+ $val = get_option('simple_wp_block_urls');
23
+ break;
24
+ case 'simple_wp_attr_link':
25
+ $val = get_option('simple_wp_attr_link');
26
+ return $val ? 'checked' : ''; // return checkbox checked value right here and dont bother with the loop below
27
+ default:
28
+ $val = null;
29
+ }
30
+
31
+ if (!$this->isNullOrWhiteSpace($val)){
32
+ $str = '';
33
+ foreach($val as $sArr){
34
+ $str .= $sArr['url'] . "\n";
35
+ }
36
+ return trim($str);
37
+ }
38
+ return '';
39
+ }
40
+
41
+ // Checks if string/array is empty
42
+ private function isNullOrWhiteSpace($word){
43
+ if (is_array($word)){
44
+ return false;
45
+ }
46
+ return ($word === null || $word === false || trim($word) === '');
47
+ }
48
+
49
+ // Sanitizes urls with esc_url and trim
50
+ private function sanitizeUrl($url){
51
+ return esc_url(trim($url));
52
+ }
53
+
54
+ // Adds new urls to the sitemaps
55
+ private function addUrls($urls, $oldUrls=null){
56
+ $arr = array();
57
+
58
+ if (!$this->isNullOrWhiteSpace($urls)){
59
+ $urls = explode("\n", $urls);
60
+
61
+ foreach ($urls as $u){
62
+ if (!$this->isNullOrWhiteSpace($u)){
63
+ $u = $this->sanitizeUrl($u);
64
+ $b = false;
65
+ if ($oldUrls && is_array($oldUrls)){
66
+ foreach ($oldUrls as $o){
67
+ if ($o['url'] === $u && !$b){
68
+ $arr[] = $o;
69
+ $b = true;
70
+ }
71
+ }
72
+ }
73
+ if (!$b){
74
+ $arr[] = array('url' => $u, 'date' => date('Y-m-d\TH:i:sP'));
75
+ }
76
+ }
77
+ }
78
+ }
79
+ return !empty($arr) ? $arr : '';
80
+ }
81
+ }