You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
4.1 KiB

  1. <?php
  2. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  3. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  4. // original author(s).
  5. //
  6. // This code is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  8. // License for more details.
  9. //
  10. // File: ./sitemap.php
  11. // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/sitemap.php $
  12. // Author(s): Richard Karnesky <mailto:rkarnesky@gmail.com>
  13. //
  14. // Created: 17-May-08, 15:50
  15. // Modified: $Date: 2017-04-13 02:00:18 +0000 (Thu, 13 Apr 2017) $
  16. // $Author: karnesky $
  17. // $Revision: 1416 $
  18. // Create a sitemap for better indexing by search engines.
  19. // <http://www.sitemaps.org/>
  20. // You can either use this to dynamically generate sitemaps or can make a
  21. // crontab entry to wget it (saving execution time & allowing you to manually
  22. // gzip the file (if your webserver doesn't already do this for you).
  23. // TODO:
  24. // - Handle cases where there are >50,000 URLs
  25. // - Possibly come up with smart ways to specify changefreq and priority
  26. // Incorporate some include files:
  27. include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password
  28. include 'includes/include.inc.php'; // include common functions
  29. include 'initialize/ini.inc.php'; // include common variables
  30. global $tableRefs;
  31. global $databaseBaseURL;
  32. global $fileVisibility;
  33. global $fileVisibilityException;
  34. global $filesBaseURL;
  35. // --------------------------------------------------------------------
  36. // START A SESSION:
  37. // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables:
  38. start_session(true);
  39. // --------------------------------------------------------------------
  40. // (1) OPEN CONNECTION, (2) SELECT DATABASE
  41. connectToMySQLDatabase(); // function 'connectToMySQLDatabase()' is defined in 'include.inc.php'
  42. // --------------------------------------------------------------------
  43. $query = "SELECT *,file FROM ".$tableRefs .' WHERE serial RLIKE ".+"';
  44. header('Content-Type: application/xml');
  45. echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
  46. echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
  47. echo " <url>\n";
  48. echo " <loc>". $databaseBaseURL."index.php</loc>\n";
  49. echo " <changefreq>monthly</changefreq>\n"; // liberal, based on nucapt's history (not total records)
  50. echo " </url>\n";
  51. // (3) RUN QUERY, (4) DISPLAY EXPORT FILE OR HEADER & RESULTS
  52. // (3) RUN the query on the database through the connection:
  53. $result = queryMySQLDatabase($query); // function 'queryMySQLDatabase()' is defined in 'include.inc.php'
  54. while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
  55. echo " <url>\n";
  56. echo " <loc>".$databaseBaseURL."show.php?record=".$row['serial']."</loc>\n";
  57. if (!empty($row['modified_date'])) {
  58. $datemod = " <lastmod>"
  59. . generateISO8601TimeStamp($row['modified_date'], $row['modified_time']) // function 'generateISO8601TimeStamp()' is defined in 'include.inc.php'
  60. . "</lastmod>\n";
  61. echo $datemod;
  62. }
  63. else
  64. $datemod = "";
  65. echo " </url>\n";
  66. if ($fileVisibility == "everyone" OR (!empty($fileVisibilityException) AND preg_match($fileVisibilityException[1], $row[$fileVisibilityException[0]]))) {
  67. if (!empty($row["file"])) { // if the 'file' field is NOT empty
  68. if (!preg_match("#^(https?|ftp|file)://#i", $row["file"])) { // if the 'file' field does not contain a full URL (starting with "http://", "https://", "ftp://" or "file://")
  69. echo " <url>\n";
  70. echo " <loc>".$databaseBaseURL.$filesBaseURL.$row["file"]."</loc>\n";
  71. if (!empty($datemod))
  72. echo $datemod;
  73. echo " </url>\n";
  74. }
  75. }
  76. }
  77. }
  78. echo "</urlset>";
  79. disconnectFromMySQLDatabase(); // function 'disconnectFromMySQLDatabase()' is defined in 'include.inc.php'
  80. exit; // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> !EXIT! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  81. // --------------------------------------------------------------------
  82. ?>