X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=boot.php;h=cdb1b35edb8d2bdec0d0f080cd401055cba7d07b;hb=6a3815e751b013d2fba1e1de6df89566f971e39c;hp=786ebdee68a0595215b5189863c632fd98e4ecd2;hpb=511c761fec572a093e833541968635ca011cb71e;p=friendica.git
diff --git a/boot.php b/boot.php
index 786ebdee68..cdb1b35edb 100644
--- a/boot.php
+++ b/boot.php
@@ -2,12 +2,20 @@
set_time_limit(0);
-define ( 'BUILD_ID', 1008 );
+define ( 'BUILD_ID', 1017 );
define ( 'DFRN_PROTOCOL_VERSION', '2.0' );
define ( 'EOL', "
\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );
+// log levels
+
+define ( 'LOGGER_NORMAL', 0 );
+define ( 'LOGGER_TRACE', 1 );
+define ( 'LOGGER_DEBUG', 2 );
+define ( 'LOGGER_DATA', 3 );
+define ( 'LOGGER_ALL', 4 );
+
// registration policy
define ( 'REGISTER_CLOSED', 0 );
@@ -52,9 +60,13 @@ define ( 'NAMESPACE_DFRN' , 'http://purl.org/macgirvin/dfrn/1.0' );
define ( 'NAMESPACE_THREAD' , 'http://purl.org/syndication/thread/1.0' );
define ( 'NAMESPACE_TOMB' , 'http://purl.org/atompub/tombstones/1.0' );
define ( 'NAMESPACE_ACTIVITY', 'http://activitystrea.ms/spec/1.0/' );
-define ( 'NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/1.0/');
-define ( 'NAMESPACE_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env');
-define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe');
+define ( 'NAMESPACE_ACTIVITY_SCHEMA', 'http://activitystrea.ms/schema/1.0/' );
+define ( 'NAMESPACE_MEDIA', 'http://purl.org/syndication/atommedia' );
+define ( 'NAMESPACE_SALMON_ME', 'http://salmon-protocol.org/ns/magic-env' );
+define ( 'NAMESPACE_OSTATUSSUB', 'http://ostatus.org/schema/1.0/subscribe' );
+define ( 'NAMESPACE_GEORSS', 'http://www.georss.org/georss' );
+define ( 'NAMESPACE_POCO', 'http://portablecontacts.net/spec/1.0' );
+define ( 'NAMESPACE_FEED', 'http://schemas.google.com/g/2010#updates-from' );
// activity stream defines
@@ -63,8 +75,11 @@ define ( 'ACTIVITY_DISLIKE', NAMESPACE_DFRN . '/dislike' );
define ( 'ACTIVITY_OBJ_HEART', NAMESPACE_DFRN . '/heart' );
define ( 'ACTIVITY_FRIEND', NAMESPACE_ACTIVITY_SCHEMA . 'make-friend' );
+define ( 'ACTIVITY_FOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'follow' );
+define ( 'ACTIVITY_UNFOLLOW', NAMESPACE_ACTIVITY_SCHEMA . 'unfollow' );
define ( 'ACTIVITY_POST', NAMESPACE_ACTIVITY_SCHEMA . 'post' );
define ( 'ACTIVITY_UPDATE', NAMESPACE_ACTIVITY_SCHEMA . 'update' );
+define ( 'ACTIVITY_TAG', NAMESPACE_ACTIVITY_SCHEMA . 'tag' );
define ( 'ACTIVITY_OBJ_COMMENT', NAMESPACE_ACTIVITY_SCHEMA . 'comment' );
define ( 'ACTIVITY_OBJ_NOTE', NAMESPACE_ACTIVITY_SCHEMA . 'note' );
@@ -115,6 +130,7 @@ class App {
private $db;
private $curl_code;
+ private $curl_headers;
function __construct() {
@@ -122,17 +138,17 @@ class App {
$this->page = array();
$this->pager= array();
- $this->scheme = ((isset($_SERVER['HTTPS'])
- && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
- $this->hostname = str_replace('www.','',
- $_SERVER['SERVER_NAME']);
- set_include_path("include/$this->hostname"
- . PATH_SEPARATOR . 'include'
- . PATH_SEPARATOR . '.' );
+ $this->scheme = ((isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'])) ? 'https' : 'http' );
+
+ if(x($_SERVER,'SERVER_NAME'))
+ $this->hostname = $_SERVER['SERVER_NAME'];
- if(substr($_SERVER['QUERY_STRING'],0,2) == "q=")
+ set_include_path("include/$this->hostname" . PATH_SEPARATOR . 'include' . PATH_SEPARATOR . '.' );
+
+ if((x($_SERVER,'QUERY_STRING')) && substr($_SERVER['QUERY_STRING'],0,2) === "q=")
$_SERVER['QUERY_STRING'] = substr($_SERVER['QUERY_STRING'],2);
- $this->cmd = trim($_GET['q'],'/');
+ if(x($_GET,'q'))
+ $this->cmd = trim($_GET['q'],'/');
$this->argv = explode('/',$this->cmd);
@@ -147,6 +163,7 @@ class App {
if($this->cmd === '.well-known/host-meta')
require_once('include/hostxrd.php');
+
$this->pager['page'] = ((x($_GET,'page')) ? $_GET['page'] : 1);
$this->pager['itemspage'] = 50;
$this->pager['start'] = ($this->pager['page'] * $this->pager['itemspage']) - $this->pager['itemspage'];
@@ -157,9 +174,7 @@ class App {
if(strlen($this->baseurl))
return $this->baseurl;
- $this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname
- . ((isset($this->path) && strlen($this->path))
- ? '/' . $this->path : '' );
+ $this->baseurl = (($ssl) ? 'https' : $this->scheme) . "://" . $this->hostname . ((isset($this->path) && strlen($this->path)) ? '/' . $this->path : '' );
return $this->baseurl;
}
@@ -177,7 +192,7 @@ class App {
}
function set_path($p) {
- $this->path = ltrim(trim($p),'/');
+ $this->path = trim(trim($p),'/');
}
function get_path() {
@@ -209,6 +224,15 @@ class App {
return $this->curl_code;
}
+ function set_curl_headers($headers) {
+ $this->curl_headers = $headers;
+ }
+
+ function get_curl_headers() {
+ return $this->curl_headers;
+ }
+
+
}}
// retrieve the App structure
@@ -332,10 +356,10 @@ function load_translation_table($lang) {
if(! function_exists('t')) {
function t($s) {
-
+
$a = get_app();
- if($a->strings[$s])
+ if(x($a->strings,$s))
return $a->strings[$s];
return $s;
}}
@@ -344,15 +368,19 @@ function t($s) {
// results.
if(! function_exists('fetch_url')) {
-function fetch_url($url,$binary = false) {
+function fetch_url($url,$binary = false, &$redirects = 0) {
$ch = curl_init($url);
- if(! $ch) return false;
+ if(($redirects > 8) || (! $ch))
+ return false;
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
- curl_setopt($ch, CURLOPT_MAXREDIRS,8);
+ curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
+
+ $curl_time = intval(get_config('system','curl_timeout'));
+ if($curl_time)
+ curl_setopt($ch, CURLOPT_TIMEOUT, $curl_time);
+
// by default we will allow self-signed certs
// but you can override this
@@ -371,26 +399,53 @@ function fetch_url($url,$binary = false) {
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$s = curl_exec($ch);
- $info = curl_getinfo($ch);
+
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ $header = substr($s,0,strpos($s,"\r\n\r\n"));
+ if(stristr($header,'100') && (strlen($header) < 30)) {
+ // 100 Continue has two headers, get the real one
+ $s = substr($s,strlen($header)+4);
+ $header = substr($s,0,strpos($s,"\r\n\r\n"));
+ }
+ if($http_code == 301 || $http_code == 302 || $http_code == 303) {
+ $matches = array();
+ preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
+ $url = trim(array_pop($matches));
+ $url_parsed = parse_url($url);
+ if (isset($url_parsed)) {
+ $redirects++;
+ return fetch_url($url,$binary,$redirects);
+ }
+ }
$a = get_app();
- $a->set_curl_code($info['http_code']);
+ $a->set_curl_code($http_code);
+ $body = substr($s,strlen($header)+4);
+ $a->set_curl_headers($header);
+
curl_close($ch);
- return($s);
+ return($body);
}}
// post request to $url. $params is an array of post variables.
if(! function_exists('post_url')) {
-function post_url($url,$params) {
+function post_url($url,$params, $headers = null, &$redirects = 0) {
$ch = curl_init($url);
- if(! $ch) return false;
+ if(($redirects > 8) || (! $ch))
+ return false;
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
- curl_setopt($ch, CURLOPT_MAXREDIRS,8);
+ curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
+
+ $curl_time = intval(get_config('system','curl_timeout'));
+ if($curl_time)
+ curl_setopt($ch, CURLOPT_TIMEOUT, $curl_time);
+
+ if(is_array($headers))
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+
$check_cert = get_config('system','verifyssl');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false));
$prx = get_config('system','proxy');
@@ -403,11 +458,31 @@ function post_url($url,$params) {
}
$s = curl_exec($ch);
- $info = curl_getinfo($ch);
+
+ $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ $header = substr($s,0,strpos($s,"\r\n\r\n"));
+ if(stristr($header,'100') && (strlen($header) < 30)) {
+ // 100 Continue has two headers, get the real one
+ $s = substr($s,strlen($header)+4);
+ $header = substr($s,0,strpos($s,"\r\n\r\n"));
+ }
+ if($http_code == 301 || $http_code == 302 || $http_code == 303) {
+ $matches = array();
+ preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
+ $url = trim(array_pop($matches));
+ $url_parsed = parse_url($url);
+ if (isset($url_parsed)) {
+ $redirects++;
+ return post_url($url,$binary,$headers,$redirects);
+ }
+ }
$a = get_app();
- $a->set_curl_code($info['http_code']);
+ $a->set_curl_code($http_code);
+ $body = substr($s,strlen($header)+4);
+ $a->set_curl_headers($header);
+
curl_close($ch);
- return($s);
+ return($body);
}}
// random hash, 64 chars
@@ -553,8 +628,10 @@ function goaway($s) {
if(! function_exists('xml_status')) {
function xml_status($st, $message = '') {
- if(strlen($message))
- $xml_message = "\t