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.

101 lines
4.2 KiB

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