X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fsitemap.php;h=51a9bbd7573629d74803b446611783880b6f1ca0;hb=8e4f985e4502a14d66f84f9e5c8d4a54bb8e5594;hp=fbfd14e199431a71a49a283b4d28f245cbd147f5;hpb=808b40dc534316a82b9c614f1d8438fd1b149074;p=quix0rs-gnu-social.git
diff --git a/scripts/sitemap.php b/scripts/sitemap.php
old mode 100644
new mode 100755
index fbfd14e199..51a9bbd757
--- a/scripts/sitemap.php
+++ b/scripts/sitemap.php
@@ -18,189 +18,193 @@ index_map();
# ------------------------------------------------------------------------------
# Generate index sitemap of all other sitemaps.
-function index_map() {
- global $output_paths;
- $output_dir = $output_paths['output_dir'];
- $output_url = $output_paths['output_url'];
-
- foreach (glob("$output_dir*.xml") as $file_name) {
-
- # Just the file name please.
- $file_name = preg_replace("|$output_dir|", '', $file_name);
-
- $index_urls .= sitemap(
- array(
- 'url' => $output_url . $file_name,
- 'changefreq' => 'daily'
- )
- );
- }
-
- write_file($output_paths['index_file'], sitemapindex($index_urls));
+function index_map()
+{
+ global $output_paths;
+ $output_dir = $output_paths['output_dir'];
+ $output_url = $output_paths['output_url'];
+
+ foreach (glob("$output_dir*.xml") as $file_name) {
+
+ # Just the file name please.
+ $file_name = preg_replace("|$output_dir|", '', $file_name);
+
+ $index_urls .= sitemap(
+ array(
+ 'url' => $output_url . $file_name,
+ 'changefreq' => 'daily'
+ )
+ );
+ }
+
+ write_file($output_paths['index_file'], sitemapindex($index_urls));
}
# Generate sitemap of standard site elements.
-function standard_map() {
- global $output_paths;
-
- $standard_map_urls .= url(
- array(
- 'url' => common_local_url('public'),
- 'changefreq' => 'daily',
- 'priority' => '1',
- )
- );
-
- $standard_map_urls .= url(
- array(
- 'url' => common_local_url('publicrss'),
- 'changefreq' => 'daily',
- 'priority' => '0.3',
- )
- );
-
- $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', 'privacy', 'source');
-
- foreach($docs as $title) {
- $standard_map_urls .= url(
- array(
- 'url' => common_local_url('doc', array('title' => $title)),
- 'changefreq' => 'monthly',
- 'priority' => '0.2',
- )
- );
- }
-
- $urlset_path = $output_paths['output_dir'] . 'standard.xml';
-
- write_file($urlset_path, urlset($standard_map_urls));
+function standard_map()
+{
+ global $output_paths;
+
+ $standard_map_urls .= url(
+ array(
+ 'url' => common_local_url('public'),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ )
+ );
+
+ $standard_map_urls .= url(
+ array(
+ 'url' => common_local_url('publicrss'),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ )
+ );
+
+ $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', 'privacy', 'source');
+
+ foreach($docs as $title) {
+ $standard_map_urls .= url(
+ array(
+ 'url' => common_local_url('doc', array('title' => $title)),
+ 'changefreq' => 'monthly',
+ 'priority' => '0.2',
+ )
+ );
+ }
+
+ $urlset_path = $output_paths['output_dir'] . 'standard.xml';
+
+ write_file($urlset_path, urlset($standard_map_urls));
}
# Generate sitemaps of all notices.
-function notices_map() {
- global $output_paths;
-
- $notices = DB_DataObject::factory('notice');
-
- $notices->query('SELECT id, uri, url, modified FROM notice');
-
- $notice_count = 0;
- $map_count = 1;
-
- while ($notices->fetch()) {
-
- # Maximum 50,000 URLs per sitemap file.
- if ($notice_count == 50000) {
- $notice_count = 0;
- $map_count++;
- }
-
- # remote notices have an URL
-
- if (!$notices->url && $notices->uri) {
- $notice = array(
- 'url' => ($notices->uri) ? $notices->uri : common_local_url('shownotice', array('notice' => $notices->id)),
- 'lastmod' => common_date_w3dtf($notices->modified),
- 'changefreq' => 'never',
- 'priority' => '1',
- );
-
- $notice_list[$map_count] .= url($notice);
- $notice_count++;
- }
- }
-
- # Make full sitemaps from the lists and save them.
- array_to_map($notice_list, 'notice');
+function notices_map()
+{
+ global $output_paths;
+
+ $notices = DB_DataObject::factory('notice');
+
+ $notices->query('SELECT id, uri, url, modified FROM notice where is_local = 1');
+
+ $notice_count = 0;
+ $map_count = 1;
+
+ while ($notices->fetch()) {
+
+ # Maximum 50,000 URLs per sitemap file.
+ if ($notice_count == 50000) {
+ $notice_count = 0;
+ $map_count++;
+ }
+
+ # remote notices have an URL
+
+ if (!$notices->url && $notices->uri) {
+ $notice = array(
+ 'url' => ($notices->uri) ? $notices->uri : common_local_url('shownotice', array('notice' => $notices->id)),
+ 'lastmod' => common_date_w3dtf($notices->modified),
+ 'changefreq' => 'never',
+ 'priority' => '1',
+ );
+
+ $notice_list[$map_count] .= url($notice);
+ $notice_count++;
+ }
+ }
+
+ # Make full sitemaps from the lists and save them.
+ array_to_map($notice_list, 'notice');
}
# Generate sitemaps of all users.
-function user_map() {
- global $output_paths;
-
- $users = DB_DataObject::factory('user');
-
- $users->query('SELECT id, nickname FROM user');
-
- $user_count = 0;
- $map_count = 1;
-
- while ($users->fetch()) {
-
- # Maximum 50,000 URLs per sitemap file.
- if ($user_count == 50000) {
- $user_count = 0;
- $map_count++;
- }
-
- $user_args = array('nickname' => $users->nickname);
-
- # Define parameters for generating elements.
- $user = array(
- 'url' => common_local_url('showstream', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '1',
- );
-
- $user_rss = array(
- 'url' => common_local_url('userrss', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '0.3',
- );
-
- $all = array(
- 'url' => common_local_url('all', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '1',
- );
-
- $all_rss = array(
- 'url' => common_local_url('allrss', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '0.3',
- );
-
- $replies = array(
- 'url' => common_local_url('replies', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '1',
- );
-
- $replies_rss = array(
- 'url' => common_local_url('repliesrss', $user_args),
- 'changefreq' => 'daily',
- 'priority' => '0.3',
- );
-
- $foaf = array(
- 'url' => common_local_url('foaf', $user_args),
- 'changefreq' => 'weekly',
- 'priority' => '0.5',
- );
-
- # Construct a element for each user facet and add it
- # to our existing list of those.
- $user_list[$map_count] .= url($user);
- $user_rss_list[$map_count] .= url($user_rss);
- $all_list[$map_count] .= url($all);
- $all_rss_list[$map_count] .= url($all_rss);
- $replies_list[$map_count] .= url($replies);
- $replies_rss_list[$map_count] .= url($replies_rss);
- $foaf_list[$map_count] .= url($foaf);
-
- $user_count++;
- }
-
- # Make full sitemaps from the lists and save them.
- # Possible factoring: put all the lists into a master array, thus allowing
- # calling with single argument (i.e., array_to_map('user')).
- array_to_map($user_list, 'user');
- array_to_map($user_rss_list, 'user_rss');
- array_to_map($all_list, 'all');
- array_to_map($all_rss_list, 'all_rss');
- array_to_map($replies_list, 'replies');
- array_to_map($replies_rss_list, 'replies_rss');
- array_to_map($foaf_list, 'foaf');
+function user_map()
+{
+ global $output_paths;
+
+ $users = DB_DataObject::factory('user');
+
+ $users->query('SELECT id, nickname FROM user');
+
+ $user_count = 0;
+ $map_count = 1;
+
+ while ($users->fetch()) {
+
+ # Maximum 50,000 URLs per sitemap file.
+ if ($user_count == 50000) {
+ $user_count = 0;
+ $map_count++;
+ }
+
+ $user_args = array('nickname' => $users->nickname);
+
+ # Define parameters for generating elements.
+ $user = array(
+ 'url' => common_local_url('showstream', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ );
+
+ $user_rss = array(
+ 'url' => common_local_url('userrss', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ );
+
+ $all = array(
+ 'url' => common_local_url('all', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ );
+
+ $all_rss = array(
+ 'url' => common_local_url('allrss', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ );
+
+ $replies = array(
+ 'url' => common_local_url('replies', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '1',
+ );
+
+ $replies_rss = array(
+ 'url' => common_local_url('repliesrss', $user_args),
+ 'changefreq' => 'daily',
+ 'priority' => '0.3',
+ );
+
+ $foaf = array(
+ 'url' => common_local_url('foaf', $user_args),
+ 'changefreq' => 'weekly',
+ 'priority' => '0.5',
+ );
+
+ # Construct a element for each user facet and add it
+ # to our existing list of those.
+ $user_list[$map_count] .= url($user);
+ $user_rss_list[$map_count] .= url($user_rss);
+ $all_list[$map_count] .= url($all);
+ $all_rss_list[$map_count] .= url($all_rss);
+ $replies_list[$map_count] .= url($replies);
+ $replies_rss_list[$map_count] .= url($replies_rss);
+ $foaf_list[$map_count] .= url($foaf);
+
+ $user_count++;
+ }
+
+ # Make full sitemaps from the lists and save them.
+ # Possible factoring: put all the lists into a master array, thus allowing
+ # calling with single argument (i.e., array_to_map('user')).
+ array_to_map($user_list, 'user');
+ array_to_map($user_rss_list, 'user_rss');
+ array_to_map($all_list, 'all');
+ array_to_map($all_rss_list, 'all_rss');
+ array_to_map($replies_list, 'replies');
+ array_to_map($replies_rss_list, 'replies_rss');
+ array_to_map($foaf_list, 'foaf');
}
# ------------------------------------------------------------------------------
@@ -208,88 +212,93 @@ function user_map() {
# ------------------------------------------------------------------------------
# Generate a element.
-function url($url_args) {
- $url = preg_replace('/&/', '&', $url_args['url']); # escape ampersands for XML
- $lastmod = $url_args['lastmod'];
- $changefreq = $url_args['changefreq'];
- $priority = $url_args['priority'];
+function url($url_args)
+{
+ $url = preg_replace('/&/', '&', $url_args['url']); # escape ampersands for XML
+ $lastmod = $url_args['lastmod'];
+ $changefreq = $url_args['changefreq'];
+ $priority = $url_args['priority'];
- if (is_null($url)) {
- error("url() arguments require 'url' value.");
- }
+ if (is_null($url)) {
+ error("url() arguments require 'url' value.");
+ }
- $url_out = "\t\n";
- $url_out .= "\t\t$url\n";
+ $url_out = "\t\n";
+ $url_out .= "\t\t$url\n";
- if ($changefreq) {
- $url_out .= "\t\t$changefreq\n";
- }
+ if ($changefreq) {
+ $url_out .= "\t\t$changefreq\n";
+ }
- if ($lastmod) {
- $url_out .= "\t\t$lastmod\n";
- }
+ if ($lastmod) {
+ $url_out .= "\t\t$lastmod\n";
+ }
- if ($priority) {
- $url_out .= "\t\t$priority\n";
- }
+ if ($priority) {
+ $url_out .= "\t\t$priority\n";
+ }
- $url_out .= "\t\n";
+ $url_out .= "\t\n";
- return $url_out;
+ return $url_out;
}
-function sitemap($sitemap_args) {
- $url = preg_replace('/&/', '&', $sitemap_args['url']); # escape ampersands for XML
- $lastmod = $sitemap_args['lastmod'];
+function sitemap($sitemap_args)
+{
+ $url = preg_replace('/&/', '&', $sitemap_args['url']); # escape ampersands for XML
+ $lastmod = $sitemap_args['lastmod'];
- if (is_null($url)) {
- error("url() arguments require 'url' value.");
- }
+ if (is_null($url)) {
+ error("url() arguments require 'url' value.");
+ }
- $sitemap_out = "\t\n";
- $sitemap_out .= "\t\t$url\n";
+ $sitemap_out = "\t\n";
+ $sitemap_out .= "\t\t$url\n";
- if ($lastmod) {
- $sitemap_out .= "\t\t$lastmod\n";
- }
+ if ($lastmod) {
+ $sitemap_out .= "\t\t$lastmod\n";
+ }
- $sitemap_out .= "\t\n";
+ $sitemap_out .= "\t\n";
- return $sitemap_out;
+ return $sitemap_out;
}
# Generate a element.
-function urlset($urlset_text) {
- $urlset = '' . "\n" .
- '' . "\n" .
- $urlset_text .
- '';
-
- return $urlset;
+function urlset($urlset_text)
+{
+ $urlset = '' . "\n" .
+ '' . "\n" .
+ $urlset_text .
+ '';
+
+ return $urlset;
}
# Generate a element.
-function sitemapindex($sitemapindex_text) {
- $sitemapindex = '' . "\n" .
- '' . "\n" .
- $sitemapindex_text .
- '';
-
- return $sitemapindex;
+function sitemapindex($sitemapindex_text)
+{
+ $sitemapindex = '' . "\n" .
+ '' . "\n" .
+ $sitemapindex_text .
+ '';
+
+ return $sitemapindex;
}
# Generate a sitemap from an array containing elements and write it to a file.
-function array_to_map($url_list, $filename_prefix) {
- global $output_paths;
-
- if ($url_list) {
- # $map_urls is a long string containing concatenated elements.
- while (list($map_idx, $map_urls) = each($url_list)) {
- $urlset_path = $output_paths['output_dir'] . "$filename_prefix-$map_idx.xml";
-
- write_file($urlset_path, urlset($map_urls));
- }
- }
+function array_to_map($url_list, $filename_prefix)
+{
+ global $output_paths;
+
+ if ($url_list) {
+ # $map_urls is a long string containing concatenated elements.
+ while (list($map_idx, $map_urls) = each($url_list)) {
+ $urlset_path = $output_paths['output_dir'] . "$filename_prefix-$map_idx.xml";
+
+ write_file($urlset_path, urlset($map_urls));
+ }
+ }
}
# ------------------------------------------------------------------------------
@@ -297,80 +306,84 @@ function array_to_map($url_list, $filename_prefix) {
# ------------------------------------------------------------------------------
# Parse command line arguments.
-function parse_args() {
- $args = getopt('f:d:u:');
-
- if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) {
- error('Mandatory arguments: -f -d