comparison mgallery.php @ 348:596196f2b0c5 default tip

Improve relative URL translation in header text blobs.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 20 Dec 2023 09:17:55 +0200
parents 7da360685721
children
comparison
equal deleted inserted replaced
347:7da360685721 348:596196f2b0c5
204 if (($str = mgGetSetting("page_info")) !== FALSE) 204 if (($str = mgGetSetting("page_info")) !== FALSE)
205 echo "<div id=\"pageInfoFooter\">".$str."</div>"; 205 echo "<div id=\"pageInfoFooter\">".$str."</div>";
206 206
207 echo 207 echo
208 "\n</div>\n</body>\n</html>\n"; 208 "\n</div>\n</body>\n</html>\n";
209 }
210
211
212 function mgTranslateRelativeURLs($text, $path, $base)
213 {
214 // Translate / transform relative href="" URLs in given text
215 // XXX TODO: Perhaps use regexp backreferences instead of loop
216 $quoteList = ["'", "\""];
217 foreach ($quoteList as $quote)
218 {
219 $text = preg_replace_callback(
220 "@href\s*=\s*".$quote."([^\"]+)".$quote."@i",
221 function ($matches) use($path, $base)
222 {
223 $mstmp = $matches[1];
224 if (preg_match("@^[a-z]+://@i", $mstmp) === 0)
225 {
226 if ($mstmp[0] != "/")
227 $mstmp = $base."/".$path."/".str_replace("//", "/", $mstmp);
228 }
229 return "href=\"".$mstmp."\"";
230 }, $text);
231 }
232 return $text;
209 } 233 }
210 234
211 235
212 function mgGetImageTitleStr(&$data, $filename) 236 function mgGetImageTitleStr(&$data, $filename)
213 { 237 {
720 744
721 $ctrlFlags = mgGetSetting("album_flags"); 745 $ctrlFlags = mgGetSetting("album_flags");
722 if ($ctrlFlags & MGF_BREADCRUMBS) 746 if ($ctrlFlags & MGF_BREADCRUMBS)
723 mgPrintBreadCrumbs($galData); 747 mgPrintBreadCrumbs($galData);
724 748
725 if (isset($galData["header"]) && strlen($gheader = mgGetTrans($galData["header"])) > 0) 749 if (isset($galData["header"]) && strlen($headerText = mgGetTrans($galData["header"])) > 0)
726 { 750 {
727 // Translate relative URLs in header, if needed 751 // Translate relative URLs in header, if needed
728 $baseURL = mgGetSetting("image_url"); 752 echo "<div class=\"albumHeaderText\">".
729 753 mgTranslateRelativeURLs($headerText, $galPath, mgGetSetting("image_url")).
730 $headerText = preg_replace_callback( 754 "</div>\n";
731 "@href\s*=\s*\"([^\"]+)\"@i",
732 function ($matches) use($galPath, $baseURL)
733 {
734 $mstmp = $matches[1];
735 if (preg_match("@^[a-z]+://@i", $mstmp) === 0)
736 {
737 if ($mstmp[0] != "/")
738 $mstmp = $baseURL."/".$galPath."/".str_replace("//", "/", $mstmp);
739 }
740 return "href=\"".$mstmp."\"";
741 },
742 $gheader);
743
744 echo "<div class=\"albumHeaderText\">".$headerText."</div>\n";
745 } 755 }
746 756
747 echo mgGetPageInfoHeaderEnd(); 757 echo mgGetPageInfoHeaderEnd();
748 758
749 mgPrintTable("albumTable", $galData, $galPath, $galEntries, $galAlbumsIndex, 0, FALSE); 759 mgPrintTable("albumTable", $galData, $galPath, $galEntries, $galAlbumsIndex, 0, FALSE);