]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Improve annoying URL parameters cleaning:
authornodiscc <nodiscc@gmail.com>
Thu, 5 Mar 2015 12:33:30 +0000 (13:33 +0100)
committernodiscc <nodiscc@gmail.com>
Thu, 5 Mar 2015 12:33:30 +0000 (13:33 +0100)
 * Use regular expressions to avoid suplicating params depending on their position in the URL (&param=,?param=)
 * Only remove the relevant URL pattern and don't remove following params, fixes https://github.com/shaarli/Shaarli/issues/136
 * Credits to Marcus Rohrmoser (https://github.com/mro)

index.php

index cc3d7360227a04fae5a113dde56f9003f352f385..0b507b455ca2503d3456366fe449d4a7c2f4af89 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1642,11 +1642,12 @@ function renderPage()
     {
         $url=$_GET['post'];
 
+
         // We remove the annoying parameters added by FeedBurner, GoogleFeedProxy, Facebook...
-        $annoyingpatterns = array('&utm_source=', '?utm_source=', '#xtor=RSS-', '?fb_', '?__scoop', '#tk.rss_all?', '?utm_campaign=', '?utm_medium=');
+        $annoyingpatterns = array('/[\?&]utm_source=[^&]*/', '/[\?&]utm_campaign=[^&]*/', '/[\?&]utm_medium=[^&]*/', '/#xtor=RSS-[^&]*/', '/[\?&]fb_[^&]*/', '/[\?&]__scoop[^&]*/', '/#tk\.rss_all\?/');
         foreach($annoyingpatterns as $pattern)
         {
-            $i=strpos($url,$pattern); if ($i!==false) $url=substr($url,0,$i);
+            $url = preg_replace($pattern, "", $url);
         }
 
         $link_is_new = false;