Merge pull request #368 from ArthurHoaro/returnurl-again
Fixes #356 - adding a link should return added link's hash
This commit is contained in:
commit
70df947af6
3 changed files with 15 additions and 8 deletions
|
@ -97,12 +97,12 @@ function checkDateFormat($format, $string)
|
||||||
*/
|
*/
|
||||||
function generateLocation($referer, $host, $loopTerms = array())
|
function generateLocation($referer, $host, $loopTerms = array())
|
||||||
{
|
{
|
||||||
$final_referer = '?';
|
$finalReferer = '?';
|
||||||
|
|
||||||
// No referer if it contains any value in $loopCriteria.
|
// No referer if it contains any value in $loopCriteria.
|
||||||
foreach ($loopTerms as $value) {
|
foreach ($loopTerms as $value) {
|
||||||
if (strpos($referer, $value) !== false) {
|
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);
|
$host = substr($host, 0, $pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($referer) && strpos(parse_url($referer, PHP_URL_HOST), $host) !== false) {
|
$refererHost = parse_url($referer, PHP_URL_HOST);
|
||||||
$final_referer = $referer;
|
if (!empty($referer) && (strpos($refererHost, $host) !== false || startsWith('?', $refererHost))) {
|
||||||
|
$finalReferer = $referer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $final_referer;
|
return $finalReferer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
10
index.php
10
index.php
|
@ -1354,10 +1354,14 @@ function renderPage()
|
||||||
pubsubhub();
|
pubsubhub();
|
||||||
|
|
||||||
// If we are called from the bookmarklet, we must close the popup:
|
// 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; }
|
if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) {
|
||||||
$returnurl = ( !empty($_POST['returnurl']) ? escape($_POST['returnurl']) : '?' );
|
echo '<script>self.close();</script>';
|
||||||
$returnurl .= '#'.smallHash($_POST['lf_linkdate']); // Scroll to the link which has been edited.
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$returnurl = !empty($_POST['returnurl']) ? escape($_POST['returnurl']): '?';
|
||||||
$location = generateLocation($returnurl, $_SERVER['HTTP_HOST'], array('addlink', 'post', 'edit_link'));
|
$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.
|
header('Location: '. $location); // After saving the link, redirect to the page the user was on.
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,6 +118,8 @@ public function testGenerateLocation() {
|
||||||
$this->assertEquals($ref, generateLocation($ref, 'localhost'));
|
$this->assertEquals($ref, generateLocation($ref, 'localhost'));
|
||||||
$ref = 'http://localhost:8080/?test';
|
$ref = 'http://localhost:8080/?test';
|
||||||
$this->assertEquals($ref, generateLocation($ref, 'localhost:8080'));
|
$this->assertEquals($ref, generateLocation($ref, 'localhost:8080'));
|
||||||
|
$ref = '?localreferer#hash';
|
||||||
|
$this->assertEquals($ref, generateLocation($ref, 'localhost:8080'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue