]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #275 from shaarli/plugin-proposition
authorArthur <arthur@hoa.ro>
Sun, 8 Nov 2015 12:29:32 +0000 (13:29 +0100)
committerArthur <arthur@hoa.ro>
Sun, 8 Nov 2015 12:29:32 +0000 (13:29 +0100)
Plugin proposition

application/Utils.php
index.php
tests/UtilsTest.php

index 1422961d4a9acb522bf74d87ae848c77ae157cad..120333c560c93c29cf33a6e6175f829ae26ca6a4 100755 (executable)
@@ -97,12 +97,12 @@ function checkDateFormat($format, $string)
  */
 function generateLocation($referer, $host, $loopTerms = array())
 {
-    $final_referer = '?';
+    $finalReferer = '?';
 
     // No referer if it contains any value in $loopCriteria.
     foreach ($loopTerms as $value) {
         if (strpos($referer, $value) !== false) {
-            return $final_referer;
+            return $finalReferer;
         }
     }
 
@@ -111,11 +111,12 @@ function generateLocation($referer, $host, $loopTerms = array())
         $host = substr($host, 0, $pos);
     }
 
-    if (!empty($referer) && strpos(parse_url($referer, PHP_URL_HOST), $host) !== false) {
-        $final_referer = $referer;
+    $refererHost = parse_url($referer, PHP_URL_HOST);
+    if (!empty($referer) && (strpos($refererHost, $host) !== false || startsWith('?', $refererHost))) {
+        $finalReferer = $referer;
     }
 
-    return $final_referer;
+    return $finalReferer;
 }
 
 /**
index ea7bf4d105eb12d2c397868a9c3f0584852a39f9..7383348e80a575524814bc006ad52a3694840181 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -1439,10 +1439,14 @@ function renderPage()
         pubsubhub();
 
         // If we are called from the bookmarklet, we must close the popup:
-        if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; }
-        $returnurl = ( !empty($_POST['returnurl']) ? escape($_POST['returnurl']) : '?' );
-        $returnurl .= '#'.smallHash($_POST['lf_linkdate']);  // Scroll to the link which has been edited.
+        if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) {
+            echo '<script>self.close();</script>';
+            exit;
+        }
+
+        $returnurl = !empty($_POST['returnurl']) ? escape($_POST['returnurl']): '?';
         $location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
+        $location .= '#'.smallHash($_POST['lf_linkdate']);  // Scroll to the link which has been edited.
         header('Location: '. $location); // After saving the link, redirect to the page the user was on.
         exit;
     }
index 7f218ad5633482cf2cafc11bb70d2df27bca60ea..311d4bfb4979016146549518637f9af931e2b3e3 100755 (executable)
@@ -118,6 +118,8 @@ class UtilsTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($ref, generateLocation($ref, 'localhost'));
         $ref = 'http://localhost:8080/?test';
         $this->assertEquals($ref, generateLocation($ref, 'localhost:8080'));
+        $ref = '?localreferer#hash';
+        $this->assertEquals($ref, generateLocation($ref, 'localhost:8080'));
     }
 
     /**