echo " <td align=\"left\" width=\"350\">", gettext("Enable Sitemap"), ":</td>\n"; echo " <td align=\"left\">", form_radio("sitemap_enabled", "Y", gettext("Yes"), isset($forum_global_settings['sitemap_enabled']) && $forum_global_settings['sitemap_enabled'] == 'Y'), " ", form_radio("sitemap_enabled", "N", gettext("No"), isset($forum_global_settings['sitemap_enabled']) && $forum_global_settings['sitemap_enabled'] == 'N' || !isset($forum_global_settings['sitemap_enabled'])), "</td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td align=\"left\" width=\"350\">", gettext("Sitemap Update Frequency"), ":</td>\n"; echo " <td align=\"left\">", form_dropdown_array("sitemap_freq", $sitemap_freq_periods, isset($forum_global_settings['sitemap_freq']) && in_array($forum_global_settings['sitemap_freq'], array_keys($sitemap_freq_periods)) ? $forum_global_settings['sitemap_freq'] : DAY_IN_SECONDS), " </td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td align=\"left\" colspan=\"2\"> </td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td align=\"left\" colspan=\"2\">\n"; echo " <p class=\"smalltext\">", gettext("These settings allows your forum to be spidered by search engines like Google, AltaVista and Yahoo. If you switch this option off your forum will not be included in these search engines results."), "</p>\n"; echo " <p class=\"smalltext\">", gettext("In addition to simple spidering, Beehive can also generate a sitemap for the forum to make it easier for search engines to find and index the messages posted by your users."), "</p>\n"; if (isset($forum_global_settings['sitemap_enabled']) && $forum_global_settings['sitemap_enabled'] == "Y") { if (!sitemap_get_dir()) { html_display_error_msg(gettext("Sitemap directory must be writable by the web server / PHP process!"), '95%', 'center'); } } echo " <p class=\"smalltext\">", gettext("Sitemaps are automatically saved to the sitemaps sub-directory of your Beehive Forum installation. If this directory doesn't exist you must create it and ensure that it is writable by the server / PHP process. To allow search engines to find your sitemap you must add the URL to your robots.txt."), "</p>\n"; echo " <p class=\"smalltext\">", gettext("Depending on server performance and the number of forums and threads your Beehive installation contains, generating a sitemap may take several minutes to complete. If performance of your server is adversely affected it is recommend you disable generation of the sitemap."), "</p>\n"; echo " </td>\n"; echo " </tr>\n"; echo " <tr>\n"; echo " <td align=\"left\" colspan=\"2\"> </td>\n"; echo " </tr>\n"; echo " </table>\n"; echo " </td>\n"; echo " </tr>\n"; echo " </table>\n"; echo " </td>\n";
function sitemap_create_file() { // This can take a long time so we'll stop PHP timing out. set_time_limit(0); // Header for the sitemap index file $sitemap_index_header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $sitemap_index_header .= "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; // Sitemap index entry $sitemap_index_entry = "<sitemap>\n"; $sitemap_index_entry .= "<loc>%s/sitemaps/sitemap%s.xml</loc>\n"; $sitemap_index_entry .= "<lastmod>%s</lastmod>\n"; $sitemap_index_entry .= "</sitemap>\n"; // Sitemap index footer. $sitemap_index_footer = "</sitemapindex>"; // Header for the sitemap file $sitemap_header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; $sitemap_header .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"; // Sitemap URL entry $sitemap_url_entry = "<url>\n"; $sitemap_url_entry .= "<loc>%s/index.php?webtag=%s&msg=%s.1</loc>\n"; $sitemap_url_entry .= "<lastmod>%s</lastmod>\n"; $sitemap_url_entry .= "<changefreq>%s</changefreq>\n"; $sitemap_url_entry .= "</url>\n"; // Footer for the sitemap file. $sitemap_footer = "</urlset>"; // Sitemap file count $sitemap_file_count = 1; // Forum URL $forum_location = html_get_forum_uri(); // Check that search engine spidering is enabled if (forum_get_setting('allow_search_spidering', 'N')) { return false; } // Check that the sitemap setting is enabled. if (forum_get_setting('sitemap_enabled', 'N')) { return false; } // Fetch the sitemap path. if (!($sitemap_path = sitemap_get_dir())) { return false; } // Get the sitemap update frequencey (default: 24 hours) $sitemap_freq = forum_get_setting('sitemap_freq', null, DAY_IN_SECONDS); // Clear the stat cache so we don't get any stale results. clearstatcache(); // Check that the file is older than the update frequency. if (@file_exists("{$sitemap_path}/sitemap.xml")) { if (@($file_modified = filemtime("{$sitemap_path}/sitemap.xml"))) { if (time() - $file_modified < $sitemap_freq) { return false; } } } // Number of bytes written to file $bytes_written = 0; // Open the index file for writing. if (!@($fp_index = fopen("{$sitemap_path}/sitemap.xml", 'w'))) { return false; } // Write the sitemap index header to the index file fwrite($fp_index, $sitemap_index_header); // Open the sitemap file for writing. if (!@($fp = fopen("{$sitemap_path}/sitemap{$sitemap_file_count}.xml", 'w'))) { return false; } // Write the header to the file $bytes_written += fwrite($fp, $sitemap_header); // Query the database to find available forums. if (!($result_forums = sitemap_get_available_forums())) { return false; } // Iterate over each of the forums. while ($forum_data = $result_forums->fetch_assoc()) { // Get the MySQL result set for the current forum's threads. if (!($result_threads = sitemap_forum_get_threads($forum_data['FID']))) { return false; } // Iterate over the threads and add them to the sitemap file. while ($thread_data = $result_threads->fetch_assoc()) { $thread_last_modified = date(MYSQL_DATE, $thread_data['MODIFIED']); if ($thread_last_modified < time() - 90 * DAY_IN_SECONDS) { $change_frequency = "yearly"; } else { if ($thread_last_modified < time() - 30 * DAY_IN_SECONDS) { $change_frequency = "monthly"; } else { if ($thread_last_modified < time() - 4 * DAY_IN_SECONDS) { $change_frequency = "weekly"; } else { $change_frequency = "daily"; } } } // Generate the sitemap entry and write it to the file. $sitemap_entry = sprintf($sitemap_url_entry, $forum_location, $forum_data['WEBTAG'], $thread_data['TID'], $thread_last_modified, $change_frequency); // If the sitemap file is going to be larger than the 10MB max file size // We need to close the current file and open the next in sequence. if ($bytes_written + (mb_strlen($sitemap_entry) + mb_strlen($sitemap_footer)) >= 10000000) { // Write the footer to the file fwrite($fp, $sitemap_footer); // Close the file fclose($fp); // Generate an index entry $sitemap_index = sprintf($sitemap_index_entry, $forum_location, $sitemap_file_count, date(MYSQL_DATE)); // Write that to the index file. fwrite($fp_index, $sitemap_index); // Next sitemap file. $sitemap_file_count++; // Reset the written byte count $bytes_written = 0; // Try and open the file. If we fail write the footer to the index file, close and return false. if (!@($fp = fopen("{$sitemap_path}/sitemap{$sitemap_file_count}.xml", 'w'))) { fwrite($fp_index, $sitemap_index_footer); fclose($fp_index); return false; } } $bytes_written += fwrite($fp, $sitemap_entry); } } // Write the footer to the file fwrite($fp, $sitemap_footer); // Close the file fclose($fp); // Generate an index entry $sitemap_index = sprintf($sitemap_index_entry, $forum_location, $sitemap_file_count, date(MYSQL_DATE)); // Write that to the index file. fwrite($fp_index, $sitemap_index); // Write the footer fwrite($fp_index, $sitemap_index_footer); // Close the file. fclose($fp_index); // Hurrah! return true; }