PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/sitemap.xml.php

http://pixie-cms.googlecode.com/
PHP | 163 lines | 118 code | 0 blank | 45 comment | 14 complexity | f9385898f0d9f2381dc71303eaa7e6a1 MD5 | raw file
  1. <?php
  2. /**
  3. * Pixie: The Small, Simple, Site Maker.
  4. *
  5. * Licence: GNU General Public License v3
  6. * Copyright (C) 2010, Scott Evans
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see http://www.gnu.org/licenses/
  20. *
  21. * Title: Sitemap Generator
  22. *
  23. * @package Pixie
  24. * @copyright 2008-2010 Scott Evans
  25. * @author Scott Evans
  26. * @author Sam Collett
  27. * @author Tony White
  28. * @author Isa Worcs
  29. * @link http://www.getpixie.co.uk
  30. * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3
  31. * @todo Tag release for Pixie 1.04
  32. *
  33. */
  34. if (defined('DIRECT_ACCESS')) {
  35. require_once 'admin/lib/lib_misc.php';
  36. pixieExit();
  37. exit();
  38. }
  39. define('DIRECT_ACCESS', 1);
  40. require_once 'admin/lib/lib_misc.php';
  41. /* perform basic sanity checks */
  42. bombShelter();
  43. /* check URL size */
  44. error_reporting(0);
  45. include_once 'admin/config.php';
  46. include_once 'admin/lib/lib_db.php';
  47. include_once 'admin/lib/lib_date.php';
  48. include_once 'admin/lib/lib_tags.php';
  49. $prefs = get_prefs();
  50. extract($prefs);
  51. require_once('admin/lib/lib_sitemap.php');
  52. $rs = safe_rows('*', 'pixie_core', "public='yes' and page_name!='404' and page_type!='plugin' order by page_views desc");
  53. $num = count($rs);
  54. $i = 0;
  55. while ($i < $num) {
  56. $out = $rs[$i];
  57. $pageid = $out['page_id'];
  58. $pagename = $out['page_name'];
  59. $type = $out['page_type'];
  60. $lastmodified = $out['last_modified'];
  61. $url = createURL($pagename);
  62. if ($type == 'dynamic') {
  63. $change = 'weekly';
  64. $rz = safe_rows('*', 'pixie_dynamic_posts', "page_id='$pageid' and public = 'yes' order by post_views desc");
  65. $num1 = count($rz);
  66. $j = 0;
  67. while ($j < $num1) {
  68. $dynpg = $rz[$j];
  69. $dynpgslug = $dynpg['post_slug'];
  70. $dynpglastmodified = $dynpg['last_modified'];
  71. $dynpgurl = createURL($pagename, 'permalink', $dynpgslug);
  72. $log = returnUnixtimestamp($dynpglastmodified);
  73. $dynpglm = safe_strftime('%Y-%m-%d', $log);
  74. $cats[] = array(
  75. 'loc' => $dynpgurl,
  76. 'changefreq' => 'yearly',
  77. 'lastmod' => $dynpglm
  78. );
  79. $j++;
  80. }
  81. // pagination
  82. $total = count(safe_rows('*', 'pixie_dynamic_posts', "page_id='$pageid' and public = 'yes' order by post_views desc"));
  83. $show = safe_field('posts_per_page', 'pixie_dynamic_settings', "page_id='$pageid'");
  84. $roundup = ceil($total / $show);
  85. $latestdate = safe_field('posted', 'pixie_dynamic_posts', "page_id='$pageid' and public = 'yes' order by posted desc limit 1");
  86. $log = returnUnixtimestamp($latestdate);
  87. $recent = safe_strftime('%Y-%m-%d', $log);
  88. $k = 2;
  89. while ($k <= $roundup) {
  90. $dynpgurl = createURL($pagename, 'page', $k);
  91. $cats[] = array(
  92. 'loc' => $dynpgurl,
  93. 'changefreq' => 'monthly',
  94. 'lastmod' => $recent
  95. );
  96. $k++;
  97. }
  98. // tag list /dynamic/tags/
  99. $dynpgurl = createURL($pagename, 'tags');
  100. $cats[] = array(
  101. 'loc' => $dynpgurl,
  102. 'changefreq' => 'monthly',
  103. 'lastmod' => $recent
  104. );
  105. // popular /dynamic/popular/
  106. $dynpgurl = createURL($pagename, 'popular');
  107. $cats[] = array(
  108. 'loc' => $dynpgurl,
  109. 'changefreq' => 'monthly',
  110. 'lastmod' => $recent
  111. );
  112. // archives /dynamic/arhcives/
  113. $dynpgurl = createURL($pagename, 'archives');
  114. $cats[] = array(
  115. 'loc' => $dynpgurl,
  116. 'changefreq' => 'monthly',
  117. 'lastmod' => $recent
  118. );
  119. // every tag /dynamic/tag/$tagname
  120. $tags_array = all_tags('pixie_dynamic_posts', "public = 'yes' and page_id = '$pageid'");
  121. if (count($tags_array) != 0) {
  122. sort($tags_array);
  123. for ($final = 1; $final < (count($tags_array)); $final++) {
  124. $current = $tags_array[$final];
  125. $link = str_replace(" ", "-", $current);
  126. $url1 = createURL($pagename, 'tag', $link);
  127. //print $final." ".$current."\n";
  128. $cats[] = array(
  129. 'loc' => $url1,
  130. 'changefreq' => 'monthly',
  131. 'lastmod' => $recent
  132. );
  133. }
  134. }
  135. // also need a dynamic prority calculator 0 -> 1
  136. } else if ($type == 'module') {
  137. $change = 'monthly';
  138. } else {
  139. $change = 'monthly';
  140. }
  141. $logunix = returnUnixtimestamp($lastmodified);
  142. $lm = safe_strftime('%Y-%m-%d', $logunix);
  143. $cats[] = array(
  144. 'loc' => $url,
  145. 'changefreq' => $change,
  146. 'lastmod' => $lm
  147. );
  148. $i++;
  149. }
  150. $site_map_container = new google_sitemap();
  151. for ($i = 0; $i < count($cats); $i++) {
  152. $value = $cats[$i];
  153. $site_map_item = new google_sitemap_item($value['loc'], $value['lastmod'], $value['changefreq'], '0.7');
  154. $site_map_container->add_item($site_map_item);
  155. }
  156. /* http://php.net/manual/en/function.header.php
  157. header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.
  158. There must be no spaces or empty lines that are output before header() is called. What's happening here then? */
  159. /* I think we should use goto for this */
  160. header("Content-type: application/xml; charset=\"" . $site_map_container->charset . "\"", TRUE);
  161. header('Pragma: no-cache');
  162. print $site_map_container->build();
  163. ?>