Commit 3fd06a97 authored by Malcolm Blaney's avatar Malcolm Blaney

Bug fix calling php header function, needs second parameter to not

overwrite previous value. Added rel=canonical to permalink posts,
which also appear as comments elsewhere. The stock module needed
a major change due to week to week pricing changes affecting ordering
prices for the following week. Fixed a tooltip bug that has been
around since the last jquery-ui upgrade.
parent 5161cd8d
This diff is collapsed.
......@@ -247,8 +247,8 @@ class Post extends Base {
return false;
}
$scheme = $this->user->config->Secure() ? 'https://' : 'http://';
$server_name = $this->user->config->ServerName();
$base_url = $this->user->config->Secure() ? 'https://' : 'http://';
$base_url .= $this->user->config->ServerName();
// Link to previous and next posts on permalink pages.
$navigation = '';
if ($permalink_page) {
......@@ -272,8 +272,9 @@ class Post extends Base {
}
// Show the webmention endpoint on permalink pages.
header('Link: <'.$scheme.$server_name.'/php/webmention.php>; '.
'rel="webmention"');
header('Link: <'.$base_url.'/php/webmention.php>; rel="webmention"');
// Also specify that this is the canonical version of the content.
header('Link: <'.$base_url.$permalink_url.'>; rel="canonical"', false);
$navigation = $this->Navigation($feed, $timestamp);
}
$mysqli->close();
......@@ -296,7 +297,7 @@ class Post extends Base {
// If name is empty just use the current value for author as the user
// details don't match a username.
if ($name !== '') {
$url = $scheme.$server_name;
$url = $base_url;
if ($author !== 'admin') {
$url .= '/'.$author;
}
......@@ -333,8 +334,8 @@ class Post extends Base {
$navigation];
$content = $this->Substitute($post_format, $patterns, $replacements);
if ($this->Substitute('post-web-actions') === 'true') {
// Add the scheme and domain to the permalink url for web actions.
$permalink_url = $scheme.$server_name.$permalink_url;
// Add the base url to the permalink url for web actions.
$permalink_url = $base_url.$permalink_url;
$content .= '<div class="post-web-actions">'.
'<indie-action do="like" with="'.$permalink_url.'">'.
'<a href="#" class="action">'.
......@@ -413,14 +414,14 @@ class Post extends Base {
else {
$this->Log('Post->Cron 1: '.$mysqli->error);
}
$scheme = $this->user->config->Secure() ? 'https://' : 'http://';
$server_name = $this->user->config->ServerName();
$base_url = $this->user->config->Secure() ? 'https://' : 'http://';
$base_url .= $this->user->config->ServerName();
foreach ($receive as $webmention) {
$us_source = $webmention['source'];
$us_target = $webmention['target'];
$full_target = $us_target;
if (strpos($full_target, 'http') !== 0) {
$full_target = $scheme.$server_name.$us_target;
$full_target = $base_url.$us_target;
}
list($this->user->page, $this->owner) = page_owner($full_target);
$result = $this->ProcessReceivedWebmention($us_source, $us_target);
......@@ -433,7 +434,7 @@ class Post extends Base {
if (!in_array($us_target, $already_sent)) {
$full_target = $us_target;
if (strpos($full_target, 'http') !== 0) {
$full_target = $scheme.$server_name.$us_target;
$full_target = $base_url.$us_target;
}
list($this->user->page, $this->owner) = page_owner($full_target);
if ($this->IsPermalink()) {
......@@ -912,9 +913,8 @@ class Post extends Base {
// matched in the source if given a relative url (ie by our own server).
$full_target = $us_target;
if (strpos($full_target, 'http') !== 0) {
$scheme = $this->user->config->Secure() ? 'https://' : 'http://';
$server_name = $this->user->config->ServerName();
$full_target = $scheme.$server_name.$us_target;
$full_target = $this->user->config->Secure() ? 'https://' : 'http://';
$full_target .= $this->user->config->ServerName().$us_target;
}
list($this->user->page, $this->owner) = page_owner($full_target);
// Check that target is an existing page on this server, and that it's a
......@@ -1543,11 +1543,11 @@ class Post extends Base {
}
private function SendWebmention($url, $permalink, $endpoint = '') {
$base_url = $this->user->config->Secure() ? 'https://' : 'http://';
$base_url .= $this->user->config->ServerName();
// Use our own endpoint for relative urls.
if (strpos($url, 'http') !== 0) {
$scheme = $this->user->config->Secure() ? 'https://' : 'http://';
$server_name = $this->user->config->ServerName();
$endpoint = $scheme.$server_name.'/php/webmention.php';
$endpoint = $base_url.'/php/webmention.php';
}
else if ($endpoint === '') {
// Do discovery on the url if an endpoint isn't provided.
......@@ -1555,9 +1555,7 @@ class Post extends Base {
if ($endpoint === '') return;
}
$scheme = $this->user->config->Secure() ? 'https://' : 'http://';
$source = $scheme.$this->user->config->ServerName().
$this->Url('', $permalink);
$source = $base_url.$this->Url('', $permalink);
$post_fields = 'source='.urlencode($source).'&target='.urlencode($url);
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_POST, true);
......
This diff is collapsed.
......@@ -47,8 +47,10 @@ event.preventDefault();}
function checkTracking(){if($(this).val()!==""&&$(this).val()!=="0"){$("#stock-track-input").prop("checked",true);}}
function showMoveSupplier(product){if($("#stock-move-user-input").val()!==""){return;}
var name=$("#stock-move-name-input").val();$.each(stock.products,function(index,item){if(name===item.name){$("#stock-move-user-input").val(item.user);return false;}});}
function showProduct(product){var productFound=false;var name=$("#stock-name-input").val();var supplier=$("#stock-user-input").val();if(product){name=product.name;supplier=product.user;}
$.each(stock.products,function(index,item){if(name===item.name){productFound=true;if(supplier===""||supplier===item.user){currentProduct=item;$("#stock-name-input").val(item.name);$("#stock-user-input").val(item.user);$("#stock-total-quantity-input").val(item.quantity);$("#stock-unit-select").val(item.unit);$("#stock-size-input").val(item.size);$("#stock-price-input").val(item.price);$("#stock-wholesale-input").val(item.wholesale);$("#stock-retail-input").val(item.retail);$("#stock-category-input").val(item.category);$("#stock-growing-input").val(item.grower);$("#stock-order-available-input").prop("checked",item.available===1);$("#stock-purchase-available-input").prop("checked",item.purchaseAvailable===1);$("#stock-supplier-available-input").prop("checked",item.supplierAvailable===1);$("#stock-taxable-input").prop("checked",item.taxable===1);$("#stock-composite-input").prop("checked",item.composite===1);$("#stock-track-input").prop("checked",item.track===1);$("#stock-alternative").prop("checked",false);$("#stock-alternative").button("refresh");$("#stock-alternative").button("option","disabled",item.alternative===0);return false;}}});if(!productFound&&currentProduct&&confirm("Do you want to create a new product?\n"+"(To rename please click cancel, then submit.)")){currentProduct=null;}}
function showProduct(product){var productFound=false;var name=$("#stock-name-input").val();var supplier=$("#stock-user-input").val();$("#stock-order-price-info").html("");if(product){name=product.name;supplier=product.user;}
$.each(stock.products,function(index,item){if(name===item.name){productFound=true;if(supplier===""||supplier===item.user){currentProduct=item;$("#stock-name-input").val(item.name);$("#stock-user-input").val(item.user);$("#stock-total-quantity-input").val(item.quantity);$("#stock-unit-select").val(item.unit);$("#stock-size-input").val(item.size);$("#stock-price-input").val(item.price);if(stock.orderPrice[item.user]&&stock.orderPrice[item.user][item.name]){var orderPrice=stock.orderPrice[item.user][item.name];if(orderPrice!==item.price){$("#stock-order-price-info").html("Order price changed to: $"+
orderPrice);}}
$("#stock-wholesale-input").val(item.wholesale);$("#stock-retail-input").val(item.retail);$("#stock-category-input").val(item.category);$("#stock-growing-input").val(item.grower);$("#stock-order-available-input").prop("checked",item.available===1);$("#stock-purchase-available-input").prop("checked",item.purchaseAvailable===1);$("#stock-supplier-available-input").prop("checked",item.supplierAvailable===1);$("#stock-taxable-input").prop("checked",item.taxable===1);$("#stock-composite-input").prop("checked",item.composite===1);$("#stock-track-input").prop("checked",item.track===1);$("#stock-alternative").prop("checked",false);$("#stock-alternative").button("refresh");$("#stock-alternative").button("option","disabled",item.alternative===0);return false;}}});if(!productFound&&currentProduct&&confirm("Do you want to create a new product?\n"+"(To rename please click cancel, then submit.)")){currentProduct=null;}}
function showAlternative(){var name=$("#stock-name-input").val();var supplier=$("#stock-user-input").val();if(stock.alternative[supplier]){var alternative=stock.alternative[supplier][name];if(alternative){if($("#stock-alternative").is(":checked")){$("#stock-size-input").val(alternative.halfSize);$("#stock-price-input").val(alternative.halfPrice);}
else{$("#stock-size-input").val(alternative.fullSize);$("#stock-price-input").val(alternative.fullPrice);}
updatePrices();}}}
......@@ -126,7 +128,7 @@ var data=JSON.parse(response);location.href="/php/private.php?file="+data.filena
function exportAll(){dobrado.log("Exporting all data...","info");$.post("/php/request.php",{request:"stock",action:"exportAll",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"stock exportAll")){return;}
var data=JSON.parse(response);location.href="/php/private.php?file="+data.filename;});return false;}
function updateSupplierInput(){if($(this).is(":checked")){$("#stock-supplier-available-input").prop("checked",true);}}
function resetForm(){$("#stock-user-input").val("");$("#stock-name-input").val("");$("#stock-unit-select").val("none");$("#stock-total-quantity-input").val("");$("#stock-new-quantity-input").val("");$("#stock-size-input").val("0");$("#stock-price-input").val("");$("#stock-wholesale-input").val("");$("#stock-retail-input").val("");$("#stock-category-input").val("");$("#stock-growing-input").val("");$("#stock-order-available-input").prop("checked",false);$("#stock-purchase-available-input").prop("checked",false);$("#stock-supplier-available-input").prop("checked",false);$("#stock-taxable-input").prop("checked",false);$("#stock-composite-input").prop("checked",false);$("#stock-track-input").prop("checked",false);currentProduct=null;}
function resetForm(){$("#stock-user-input").val("");$("#stock-name-input").val("");$("#stock-unit-select").val("none");$("#stock-total-quantity-input").val("");$("#stock-new-quantity-input").val("");$("#stock-size-input").val("0");$("#stock-price-input").val("");$("#stock-order-price-info").html("");$("#stock-wholesale-input").val("");$("#stock-retail-input").val("");$("#stock-category-input").val("");$("#stock-growing-input").val("");$("#stock-order-available-input").prop("checked",false);$("#stock-purchase-available-input").prop("checked",false);$("#stock-supplier-available-input").prop("checked",false);$("#stock-taxable-input").prop("checked",false);$("#stock-composite-input").prop("checked",false);$("#stock-track-input").prop("checked",false);currentProduct=null;}
function showAll(){dobrado.log("Updating grid...","info");$.post("/php/request.php",{request:"stock",action:"list",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"stock showAll")){return;}
stock=JSON.parse(response);updateProducts();updateNames();if(stockGrid){stockGrid.setData(stock.products);stockGrid.updateRowCount();stockGrid.render();stockGrid.setSelectedRows([]);}});}
function showHidden(){dobrado.log("Updating grid...","info");$.post("/php/request.php",{request:"stock",action:"showHidden",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"stock showHidden")){return;}
......
......@@ -339,6 +339,7 @@ if (!this.dobrado.stock) {
var productFound = false;
var name = $("#stock-name-input").val();
var supplier = $("#stock-user-input").val();
$("#stock-order-price-info").html("");
if (product) {
name = product.name;
supplier = product.user;
......@@ -361,6 +362,14 @@ if (!this.dobrado.stock) {
$("#stock-unit-select").val(item.unit);
$("#stock-size-input").val(item.size);
$("#stock-price-input").val(item.price);
if (stock.orderPrice[item.user] &&
stock.orderPrice[item.user][item.name]) {
var orderPrice = stock.orderPrice[item.user][item.name];
if (orderPrice !== item.price) {
$("#stock-order-price-info").html("Order price changed to: $" +
orderPrice);
}
}
$("#stock-wholesale-input").val(item.wholesale);
$("#stock-retail-input").val(item.retail);
$("#stock-category-input").val(item.category);
......@@ -1096,6 +1105,7 @@ if (!this.dobrado.stock) {
$("#stock-new-quantity-input").val("");
$("#stock-size-input").val("0");
$("#stock-price-input").val("");
$("#stock-order-price-info").html("");
$("#stock-wholesale-input").val("");
$("#stock-retail-input").val("");
$("#stock-category-input").val("");
......
......@@ -96,7 +96,7 @@ function updateConfig(){var username=$("#site-config-form #user-input").val();do
var config=JSON.parse(response);$("#site-config-form :input").each(function(){var name=$(this).attr("name");if(config&&config[name]){$(this).val(config[name]);}
else{$(this).val("");}});});}
var template={};function showTemplateForLabel(event,ui){var label=$("#site-template-label-input").val();if(ui){label=ui.item.value;}
if(label===""){$("#site-template-content-textarea").val("");$("#site-template-description-textarea").val("");return;}
$("#site-template-form .help").tooltip("option","content","");if(label===""){$("#site-template-content-textarea").val("");$("#site-template-description-textarea").val("");return;}
var group=$("#site-template-group-input").val();if(template.group[group]){var content="";if(template.group[group][label]){content=template.group[group][label];}
var description=template.description[label];$("#site-template-content-textarea").val(content);$("#site-template-description-textarea").val(description);}
else{$("#site-template-content-textarea").val("");$("#site-template-description-textarea").val("");}}
......@@ -115,7 +115,7 @@ var templateLabels=[];var templateGroups=[];$.each(template.group,function(group
function saveTemplate(){updateTemplate("saveTemplate");return false;}
function removeTemplate(){updateTemplate("removeTemplate");return false;}
function templateHelp(){var label=$("#site-template-label-input").val();if(label!==""){var description="No description found.";if(template.description[label]){description=template.description[label];}
$("#site-template-form .help").tooltip({content:description});$("#site-template-form .help").tooltip("open");}
$("#site-template-form .help").tooltip("option","disabled",false);$("#site-template-form .help").tooltip("option","content",description);$("#site-template-form .help").tooltip("open");}
return false;}
function loadTemplates(){$.post("/php/request.php",{request:"extended",mode:"site",action:"templates",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"site templates")){return;}
template=JSON.parse(response);var templateLabels=[];var templateGroups=[];$.each(template.group,function(group,value){templateGroups.push(group);$.each(value,function(label,content){if($.inArray(label,templateLabels)===-1){templateLabels.push(label);}});});$("#site-template-label-input").change(showTemplateForLabel);$("#site-template-label-input").autocomplete({source:templateLabels,select:showTemplateForLabel});$("#site-template-group-input").change(showTemplateForGroup);$("#site-template-group-input").autocomplete({source:templateGroups,select:showTemplateForGroup});});}
......@@ -128,8 +128,8 @@ if($("#site-search-textarea").val()===""){$(".site-search-results").html("");ret
dobrado.log("Searching...","info");$.post("/php/request.php",{request:"extended",mode:"site",action:"search",search:$("#site-search-textarea").val(),group:$("#site-search-group-input").val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"site search")){return;}
var extended=JSON.parse(response);searchData=extended.data;$(".site-search-update").hide();$(".site-search-results").after($(".site-search-update"));$(".site-search-results").html(extended.content);$(".search-match .edit-content").button().click(editContent);$(".search-match .edit-style").button().click(editStyle);});return false;}
dobrado.closeEditor();dobrado.current="";dobrado.log("Editor loading...","info");$.post("/php/request.php",{request:"extended",mode:"site",action:"display",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"site request")){return;}
var extended=JSON.parse(response);$("#extended-custom").html(extended.custom);$("button.rebuild-files").button().click(rebuild);$("#site-search-form .submit").button().click(search);$(".site-search-update .site-update-content .update").button().click(updateContent);$(".site-search-update .site-update-style .update").button().click(updateStyle);$("#site-config-form #user-input").change(updateConfig).keypress(updateConfigEnter);$("#site-config-form .submit").button().click(siteConfig);$("#extended-tabs li a").first().html("Site");$("#extended-tabs").show().tabs({activate:dobrado.extended.selectTab});if(extended.content===false){$("#extended-tabs").tabs("disable",1);}
else{$("#extended-content").html(extended.content);}
var extended=JSON.parse(response);$("#extended-custom").html(extended.custom);$("button.rebuild-files").button().click(rebuild);$("#site-config-form #user-input").change(updateConfig).keypress(updateConfigEnter);$("#site-config-form .submit").button().click(siteConfig);$("#extended-tabs li a").first().html("Site");$("#extended-tabs").show().tabs({activate:dobrado.extended.selectTab});if(extended.content===false){$("#extended-tabs").tabs("disable",1);}
else{$("#extended-content").html(extended.content);$("#site-search-form .submit").button().click(search);$(".site-search-update .site-update-content .update").button().click(updateContent);$(".site-search-update .site-update-style .update").button().click(updateStyle);}
if(extended.style===false){$("#extended-tabs").tabs("disable",2);}
else{dobrado.extended.styleEditor(extended.style,extended.media);}
if(extended.history===false){$("#extended-tabs").tabs("disable",3);}
......
......@@ -716,6 +716,8 @@ if (!this.dobrado.control) {
if (ui) {
label = ui.item.value;
}
// Always reset the tooltip, will be generated again if user clicks help.
$("#site-template-form .help").tooltip("option", "content", "");
if (label === "") {
$("#site-template-content-textarea").val("");
$("#site-template-description-textarea").val("");
......@@ -847,7 +849,9 @@ if (!this.dobrado.control) {
if (template.description[label]) {
description = template.description[label];
}
$("#site-template-form .help").tooltip({ content: description });
$("#site-template-form .help").tooltip("option", "disabled", false);
$("#site-template-form .help").tooltip("option", "content",
description);
$("#site-template-form .help").tooltip("open");
}
return false;
......@@ -1012,11 +1016,6 @@ if (!this.dobrado.control) {
var extended = JSON.parse(response);
$("#extended-custom").html(extended.custom);
$("button.rebuild-files").button().click(rebuild);
$("#site-search-form .submit").button().click(search);
$(".site-search-update .site-update-content .update").button().
click(updateContent);
$(".site-search-update .site-update-style .update").button().
click(updateStyle);
$("#site-config-form #user-input").change(updateConfig).
keypress(updateConfigEnter);
$("#site-config-form .submit").button().click(siteConfig);
......@@ -1029,6 +1028,11 @@ if (!this.dobrado.control) {
}
else {
$("#extended-content").html(extended.content);
$("#site-search-form .submit").button().click(search);
$(".site-search-update .site-update-content .update").button().
click(updateContent);
$(".site-search-update .site-update-style .update").button().
click(updateStyle);
}
if (extended.style === false) {
$("#extended-tabs").tabs("disable", 2);
......@@ -1048,8 +1052,7 @@ if (!this.dobrado.control) {
$("#site-template-form .remove").button().click(removeTemplate);
$("#site-template-form .help").button({ icons:
{ primary: "ui-icon-help" }, text: false }).
tooltip({ disabled: true }).
click(templateHelp);
tooltip({ disabled: true }).click(templateHelp);
loadTemplates();
});
}
......
......@@ -32,14 +32,14 @@ $us_target = isset($_POST['target']) ? $_POST['target'] : '';
if (strpos($us_source, 'http') !== 0) {
header('HTTP/1.1 400 Bad Request');
echo 'Source URL not found.';
return;
exit;
}
// The target can be a relative url, so only exit here if not provided.
if ($us_target === '') {
header('HTTP/1.1 400 Bad Request');
echo 'Target URL not found.';
return;
exit;
}
$user = new User();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment