Merge pull request #5 from mmn/master

Settings file should be an example, and API.php cleanup
This commit is contained in:
Hannes Mannerheim 2014-02-23 19:59:19 +01:00
commit a8a932c375
2 changed files with 27 additions and 30 deletions

47
API.php
View File

@ -34,10 +34,14 @@
· · · ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */ · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
include 'settings.php'; require_once('settings.php');
header("Content-type: application/json; charset=utf-8"); header("Content-type: application/json; charset=utf-8");
if(substr($apiroot,-1) != '/') { $apiroot .= '/'; } // add slash if missing
// add slash if missing
if(substr($apiroot,-1) != '/') {
$apiroot .= '/';
}
// post requests // post requests
if(isset($_POST['postRequest'])) { if(isset($_POST['postRequest'])) {
@ -51,39 +55,34 @@ if(isset($_POST['postRequest'])) {
session_write_close(); // fix problem with curling to local session_write_close(); // fix problem with curling to local
$reply=curl_exec($ch); $reply=curl_exec($ch);
curl_close($ch); curl_close($ch);
session_start();
// force ssl on our domain
if($forcessl) {
$reply = str_replace('http://'.$siterootdomain,'https://'.$siterootdomain,$reply);
}
print $reply;
}
// get requests // get requests
elseif(isset($_POST['getRequest'])) { } elseif(isset($_POST['getRequest'])) {
$ch=curl_init(); $ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $apiroot.$_POST['getRequest']); curl_setopt($ch, CURLOPT_URL, $apiroot.$_POST['getRequest']);
if(isset($_POST['username'])) { if(isset($_POST['username'])) {
curl_setopt($ch, CURLOPT_USERPWD, $_POST['username'].":".$_POST['password']); curl_setopt($ch, CURLOPT_USERPWD, $_POST['username'].":".$_POST['password']);
} }
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
session_write_close(); session_write_close();
$reply=curl_exec($ch); $reply=curl_exec($ch);
curl_close($ch); curl_close($ch);
session_start(); } else {
// 400 Bad request, since neither postRequest or getRequest were included
// force ssl on our domain http_response_code(400);
if($forcessl) { exit;
$reply = str_replace('http:\/\/'.$siterootdomain,'https:\/\/'.$siterootdomain,$reply); }
}
session_start();
print $reply;
} // force ssl on our domain
if($forcessl) {
$reply = str_replace('http://'.$siterootdomain,'https://'.$siterootdomain, $reply);
}
echo $reply;
/* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · /* · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
@ -92,4 +91,4 @@ elseif(isset($_POST['getRequest'])) {
· \\\\_\ /_//// . · \\\\_\ /_//// .
· \____) (____/ · · \____) (____/ ·
· · · ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */?> · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */?>

View File

@ -36,13 +36,13 @@
// SITE TITLE // SITE TITLE
$sitetitle = 'Quitter'; $sitetitle = 'qvitter front-end';
// SITE DOMAIN // SITE DOMAIN
$siterootdomain = 'quitter.se'; // no http:// or https:// and no ending slash $siterootdomain = 'qvitter.example.com'; // no http:// or https:// and no ending slash
// API ROOT // API ROOT (GNU social instance)
$apiroot = 'http://quitter.se/api/'; $apiroot = 'https://social.example.com/api/';
// DEFAULT BACKGROUND COLOR // DEFAULT BACKGROUND COLOR
$defaultbackgroundcolor = '#f4f4f4'; $defaultbackgroundcolor = '#f4f4f4';
@ -73,5 +73,3 @@ $qvitterpath = ''; // WITH trailing slash!!
· \____) (____/ · · \____) (____/ ·
· · · ·
· · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */ · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · */
?>