comparison Sitemap.inc @ 112:4854db07f14f

Fix bug when creating sitemaps introduced when adding common element.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Tue, 15 Mar 2016 15:11:37 +0100
parents a5c37e845d7c
children d547cae319f0
comparison
equal deleted inserted replaced
111:adf7b11921f4 112:4854db07f14f
67 function mayValidate() 67 function mayValidate()
68 { 68 {
69 return false; 69 return false;
70 } 70 }
71 71
72 private function processDir($dir, $lang, $acceptedLanguages, $base) {
73 $urls = array();
74
75 if ($handle = opendir(basePath() . "/${dir}")) {
76 while (false !== ($entry = readdir($handle))) {
77 if (endsWith($entry, '.xml')) {
78 $fentry = basepath() . "/${dir}/${entry}";
79
80 $doc = new DOMDocument();
81
82 if (file_exists($fentry)) {
83 $doc->load($fentry);
84
85 $opts = array();
86 if (count($acceptedLanguages) > 1) {
87 $opts['lang'] = $lang;
88 }
89
90 $toplevel = $doc->getElementsByTagName("toplevel");
91
92 if($toplevel->length) {
93 $name = substr($entry, 0, -4);
94
95 if ($name != $this->options->getInputDefault('name')) {
96 $opts['name'] = $name;
97 }
98
99 $optstring = genUrl($opts, array(), array('lang', 'name'));
100
101 $location = "${base}${optstring}/";
102
103 array_push($urls, $location);
104 }
105 }
106 }
107 }
108 closedir($handle);
109 }
110 return $urls;
111 }
112
72 function generateContent() { 113 function generateContent() {
114
73 /// The final output variable 115 /// The final output variable
74 $out = '<?xml version="1.0" encoding="UTF-8"?>'; 116 $out = '<?xml version="1.0" encoding="UTF-8"?>';
75 $out .= "\n"; 117 $out .= "\n";
76 $out .= '<?xml-stylesheet type="text/xsl" href="/css/gss.xsl"?>'; 118 $out .= '<?xml-stylesheet type="text/xsl" href="/css/gss.xsl"?>';
77 $out .= "\n"; 119 $out .= "\n";
90 $acceptedLanguages = $this->options->getAcceptedLanguages(); 132 $acceptedLanguages = $this->options->getAcceptedLanguages();
91 133
92 $urls = array(); 134 $urls = array();
93 135
94 foreach($this->options->getAcceptedLanguages() as $lang) { 136 foreach($this->options->getAcceptedLanguages() as $lang) {
95 if ($handle = opendir(basePath() . "/${lang}")) { 137 $urls=array_merge($urls,
96 while (false !== ($entry = readdir($handle))) { 138 $this->processDir($lang, $lang,
97 if (endsWith($entry, '.xml')) { 139 $acceptedLanguages, $base)
98 $fentry = basepath() . "/${lang}/${entry}"; 140 );
99 $doc = new DOMDocument(); 141 $urls=array_merge($urls,
100 142 $this->processDir("common", $lang,
101 if (file_exists($fentry)) { 143 $acceptedLanguages, $base)
102 $doc->load($fentry); 144 );
103
104 $opts = array();
105 if (count($acceptedLanguages) > 1) {
106 $opts['lang'] = $lang;
107 }
108
109 $toplevel = $doc->getElementsByTagName("toplevel");
110
111 if($toplevel->length) {
112 $name = substr($entry, 0, -4);
113
114 if ($name != $this->options->getInputDefault('name')) {
115 $opts['name'] = $name;
116 }
117
118 $optstring = genUrl($opts, array(), array('lang', 'name'));
119
120 $location = "${base}${optstring}/";
121
122 array_push($urls, $location);
123 }
124 }
125 }
126 }
127 closedir($handle);
128 }
129 } 145 }
130 146
131 usort($urls, "cmp_length_lex"); 147 usort($urls, "cmp_length_lex");
132 148
133 foreach($urls as $location) { 149 foreach($urls as $location) {
134 $headers = Http::getHeaders($location, 5); 150 $headers = Http::getHeaders($location, 5);
135 151