Skip to content

Commit 2386029

Browse files
committed
Merge pull request dignajar#69 from rmed/master
Modified sitemap to display all posts
2 parents 3dc443f + 0e9f32c commit 2386029

File tree

4 files changed

+118
-19
lines changed

4 files changed

+118
-19
lines changed
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/*
3+
* Nibbleblog
4+
* http://www.nibbleblog.com
5+
6+
* Require
7+
8+
* Return
9+
10+
*/
11+
12+
// =====================================================================
13+
// PAGES
14+
// =====================================================================
15+
$pages = $_DB_PAGES->get_all();
16+
17+
foreach($pages as $key=>$value)
18+
{
19+
$page = $pages[$key];
20+
21+
$pages[$key]['permalink'] = Page::permalink();
22+
}
23+
24+
// =====================================================================
25+
// POSTS
26+
// =====================================================================
27+
$posts = $_DB_POST->get_all();
28+
29+
foreach($posts as $key=>$value)
30+
{
31+
32+
$post = $posts[$key];
33+
34+
$posts[$key]['permalink'] = Post::permalink();
35+
36+
}
37+
38+
// =====================================================================
39+
// CLEANING
40+
// =====================================================================
41+
unset($post);
42+
unset($page);
43+
44+
?>

admin/boot/sitemap.bit

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
// =====================================================================
3+
// RULES
4+
// =====================================================================
5+
require_once('rules/1-fs_php.bit');
6+
require_once('rules/2-objects.bit');
7+
require_once('rules/3-variables.bit');
8+
require_once('rules/4-blacklist.bit');
9+
require_once('rules/5-url.bit');
10+
11+
require_once('rules/8-posts_pages_sitemap.bit');
12+
13+
require_once('rules/99-misc.bit');
14+
?>

admin/kernel/db/db_posts.class.php

+42-1
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,21 @@ public function delete($args)
285285
return false;
286286
}
287287

288+
/*
289+
* Return an array with all published posts
290+
*
291+
*/
292+
public function get_all()
293+
{
294+
// Set only published posts
295+
$this->set_files_by_published();
296+
297+
if($this->files_count > 0)
298+
return $this->get_full_list();
299+
300+
return array();
301+
}
302+
288303
/*
289304
* Return an array with published posts filter by page and amount
290305
*
@@ -666,6 +681,32 @@ private function get_list_by($page_number, $post_per_page)
666681
return( $tmp_array );
667682
}
668683

684+
/*
685+
* Get a full list of posts
686+
*
687+
*/
688+
private function get_full_list()
689+
{
690+
$tmp_array = array();
691+
692+
foreach($this->files as $file)
693+
{
694+
$post = $this->get_items($file);
695+
696+
$position = $post['position'];
697+
698+
while(isset($tmp_array[$position]))
699+
$position++;
700+
701+
$tmp_array[$position] = $post;
702+
}
703+
704+
// Sort low to high
705+
ksort($tmp_array);
706+
707+
return $tmp_array;
708+
}
709+
669710
} // END Class
670711

671-
?>
712+
?>

sitemap.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
<?php
22
header("Content-type: text/xml; charset=utf-8");
33

4-
require('admin/boot/feed.bit');
4+
require('admin/boot/sitemap.bit');
55

66
// =====================================================================
77
// Sitemap
88
// =====================================================================
9-
$rss = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
10-
$rss.= '<urlset
9+
$smap = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
10+
$smap.= '<urlset
1111
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
1212
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1313
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
1414
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . PHP_EOL;
1515

16-
$rss.='<url>' . PHP_EOL;
17-
$rss.='<loc>'.$settings['url'].'</loc>' . PHP_EOL;
18-
$rss.='<changefreq>always</changefreq>' . PHP_EOL;
19-
$rss.='</url>' . PHP_EOL;
16+
$smap.='<url>' . PHP_EOL;
17+
$smap.='<loc>'.$settings['url'].'</loc>' . PHP_EOL;
18+
$smap.='<changefreq>always</changefreq>' . PHP_EOL;
19+
$smap.='</url>' . PHP_EOL;
2020

2121
foreach($pages as $page)
2222
{
2323
$permalink = Page::permalink(true);
2424

25-
$rss.='<url>' . PHP_EOL;
26-
$rss.='<loc>'.$permalink.'</loc>' . PHP_EOL;
27-
$rss.='<changefreq>always</changefreq>' . PHP_EOL;
28-
$rss.='</url>' . PHP_EOL;
25+
$smap.='<url>' . PHP_EOL;
26+
$smap.='<loc>'.$permalink.'</loc>' . PHP_EOL;
27+
$smap.='<changefreq>always</changefreq>' . PHP_EOL;
28+
$smap.='</url>' . PHP_EOL;
2929
}
3030

3131
foreach($posts as $post)
3232
{
3333
$permalink = Post::permalink(true);
3434

35-
$rss.='<url>' . PHP_EOL;
36-
$rss.='<loc>'.$permalink.'</loc>' . PHP_EOL;
37-
$rss.='<changefreq>always</changefreq>' . PHP_EOL;
38-
$rss.='</url>' . PHP_EOL;
35+
$smap.='<url>' . PHP_EOL;
36+
$smap.='<loc>'.$permalink.'</loc>' . PHP_EOL;
37+
$smap.='<changefreq>always</changefreq>' . PHP_EOL;
38+
$smap.='</url>' . PHP_EOL;
3939
}
4040

41-
$rss.= '</urlset>';
41+
$smap.= '</urlset>';
4242

43-
echo $rss;
43+
echo $smap;
4444

45-
?>
45+
?>

0 commit comments

Comments
 (0)