replaced some tabs -> spaces + added curly braces #3254

Signed-off-by: Roland Haeder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2017-03-23 20:48:48 +01:00
parent f173322539
commit f5227c016d
No known key found for this signature in database
GPG Key ID: B72F8185C6C7BD78
1 changed files with 71 additions and 50 deletions

121
boot.php
View File

@ -669,6 +669,7 @@ class App {
if (x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) if (x($_SERVER,'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443)
$this->hostname .= ':' . $_SERVER['SERVER_PORT']; $this->hostname .= ':' . $_SERVER['SERVER_PORT'];
}
/* /*
* Figure out if we are running at the top of a domain * Figure out if we are running at the top of a domain
* or in a sub-directory and adjust accordingly * or in a sub-directory and adjust accordingly
@ -677,10 +678,12 @@ class App {
$path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\'); $path = trim(dirname($_SERVER['SCRIPT_NAME']),'/\\');
if (isset($path) && strlen($path) && ($path != $this->path)) if (isset($path) && strlen($path) && ($path != $this->path))
$this->path = $path; $this->path = $path;
}
} }
if ($hostname != "") if ($hostname != "") {
$this->hostname = $hostname; $this->hostname = $hostname;
}
if (is_array($_SERVER["argv"]) && $_SERVER["argc"]>1 && substr(end($_SERVER["argv"]), 0, 4)=="http" ) { if (is_array($_SERVER["argv"]) && $_SERVER["argc"]>1 && substr(end($_SERVER["argv"]), 0, 4)=="http" ) {
$this->set_baseurl(array_pop($_SERVER["argv"]) ); $this->set_baseurl(array_pop($_SERVER["argv"]) );
@ -1090,11 +1093,12 @@ class App {
* @param string $name * @param string $name
*/ */
function register_template_engine($class, $name = '') { function register_template_engine($class, $name = '') {
if ($name===""){ /// @TODO Really === and not just == ?
if ($name === "") {
$v = get_class_vars( $class ); $v = get_class_vars( $class );
if (x($v,"name")) $name = $v['name']; if (x($v,"name")) $name = $v['name'];
} }
if ($name===""){ if ($name === "") {
echo "template engine <tt>$class</tt> cannot be registered without a name.\n"; echo "template engine <tt>$class</tt> cannot be registered without a name.\n";
killme(); killme();
} }
@ -1110,8 +1114,9 @@ class App {
* @param strin $name Template engine name * @param strin $name Template engine name
* @return object Template Engine instance * @return object Template Engine instance
*/ */
function template_engine($name = ''){ function template_engine($name = '') {
if ($name!=="") { /// @TODO really type-check included?
if ($name !== "") {
$template_engine = $name; $template_engine = $name;
} else { } else {
$template_engine = 'smarty3'; $template_engine = 'smarty3';
@ -1276,27 +1281,26 @@ class App {
* @return bool Is it a known backend? * @return bool Is it a known backend?
*/ */
function is_backend() { function is_backend() {
static $backend = array( $backend = array();
"_well_known", $backend[] = "_well_known";
"api", $backend[] = "api";
"dfrn_notify", $backend[] = "dfrn_notify";
"fetch", $backend[] = "fetch";
"hcard", $backend[] = "hcard";
"hostxrd", $backend[] = "hostxrd";
"nodeinfo", $backend[] = "nodeinfo";
"noscrape", $backend[] = "noscrape";
"p", $backend[] = "p";
"poco", $backend[] = "poco";
"post", $backend[] = "post";
"proxy", $backend[] = "proxy";
"pubsub", $backend[] = "pubsub";
"pubsubhubbub", $backend[] = "pubsubhubbub";
"receive", $backend[] = "receive";
"rsd_xml", $backend[] = "rsd_xml";
"salmon", $backend[] = "salmon";
"statistics_json", $backend[] = "statistics_json";
"xrd", $backend[] = "xrd";
);
if (in_array($this->module, $backend)) { if (in_array($this->module, $backend)) {
return(true); return(true);
@ -1404,6 +1408,7 @@ class App {
} else { } else {
proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__))); proc_close(proc_open($cmdline." &",array(),$foo,dirname(__FILE__)));
} }
} }
/** /**
@ -1777,8 +1782,9 @@ function get_guid($size=16, $prefix = "") {
$prefix = hash("crc32", $a->get_hostname()); $prefix = hash("crc32", $a->get_hostname());
} }
while (strlen($prefix) < ($size - 13)) while (strlen($prefix) < ($size - 13)) {
$prefix .= mt_rand(); $prefix .= mt_rand();
}
if ($size >= 24) { if ($size >= 24) {
$prefix = substr($prefix, 0, $size - 22); $prefix = substr($prefix, 0, $size - 22);
@ -1822,7 +1828,7 @@ function login($register = false, $hiddens=false) {
$tpl = get_markup_template("logout.tpl"); $tpl = get_markup_template("logout.tpl");
} else { } else {
$a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"),array( $a->page['htmlhead'] .= replace_macros(get_markup_template("login_head.tpl"),array(
'$baseurl' => $a->get_baseurl(true) '$baseurl' => $a->get_baseurl(true)
)); ));
$tpl = get_markup_template("login.tpl"); $tpl = get_markup_template("login.tpl");
@ -1912,11 +1918,11 @@ function public_contact() {
if (x($_SESSION, 'my_address')) { if (x($_SESSION, 'my_address')) {
// Local user // Local user
$public_contact_id = intval(get_contact($_SESSION['my_address'], 0)); $public_contact_id = intval(get_contact($_SESSION['my_address'], 0));
} else if (x($_SESSION, 'visitor_home')) { } elseif (x($_SESSION, 'visitor_home')) {
// Remote user // Remote user
$public_contact_id = intval(get_contact($_SESSION['visitor_home'], 0)); $public_contact_id = intval(get_contact($_SESSION['visitor_home'], 0));
} }
} else if (!x($_SESSION, 'authenticated')) { } elseif (!x($_SESSION, 'authenticated')) {
$public_contact_id = false; $public_contact_id = false;
} }
@ -2175,7 +2181,6 @@ function current_theme(){
} }
/// @TODO No final return statement? /// @TODO No final return statement?
} }
/** /**
@ -2257,9 +2262,10 @@ function is_site_admin() {
$adminlist = explode(",", str_replace(" ", "", $a->config['admin_email'])); $adminlist = explode(",", str_replace(" ", "", $a->config['admin_email']));
//if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email'])) //if(local_user() && x($a->user,'email') && x($a->config,'admin_email') && ($a->user['email'] === $a->config['admin_email']))
if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist)) if (local_user() && x($a->user,'email') && x($a->config,'admin_email') && in_array($a->user['email'], $adminlist)) {
return true; return true;
}
return false; return false;
} }
@ -2271,21 +2277,24 @@ function is_site_admin() {
* *
* @return string * @return string
*/ */
function build_querystring($params, $name=null) { function build_querystring($params, $name = null) {
$ret = ""; $ret = "";
foreach ($params as $key=>$val) { foreach ($params as $key => $val) {
if (is_array($val)) { if (is_array($val)) {
if ($name==null) { /// @TODO maybe not compare against null, use is_null()
if ($name == null) {
$ret .= build_querystring($val, $key); $ret .= build_querystring($val, $key);
} else { } else {
$ret .= build_querystring($val, $name."[$key]"); $ret .= build_querystring($val, $name."[$key]");
} }
} else { } else {
$val = urlencode($val); $val = urlencode($val);
if ($name!=null) { /// @TODO maybe not compare against null, use is_null()
$ret.=$name."[$key]"."=$val&"; if ($name != null) {
/// @TODO two string concated, can be merged to one
$ret .= $name . "[$key]" . "=$val&";
} else { } else {
$ret.= "$key=$val&"; $ret .= "$key=$val&";
} }
} }
} }
@ -2303,7 +2312,8 @@ function explode_querystring($query) {
} }
$args = explode('&', substr($query, $arg_st)); $args = explode('&', substr($query, $arg_st));
foreach ($args as $k=>$arg) { foreach ($args as $k => $arg) {
/// @TODO really compare type-safe here?
if ($arg === '') { if ($arg === '') {
unset($args[$k]); unset($args[$k]);
} }
@ -2332,7 +2342,9 @@ function curPageURL() {
if ($_SERVER["HTTPS"] == "on") { if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s"; $pageURL .= "s";
} }
$pageURL .= "://"; $pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") { if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else { } else {
@ -2344,6 +2356,7 @@ function curPageURL() {
function random_digits($digits) { function random_digits($digits) {
$rn = ''; $rn = '';
for ($i = 0; $i < $digits; $i++) { for ($i = 0; $i < $digits; $i++) {
/// @TODO rand() is different to mt_rand() and maybe lesser "random"
$rn .= rand(0,9); $rn .= rand(0,9);
} }
return $rn; return $rn;
@ -2366,9 +2379,9 @@ function get_cachefile($file, $writemode = true) {
return(""); return("");
} }
$subfolder = $cache."/".substr($file, 0, 2); $subfolder = $cache . "/" . substr($file, 0, 2);
$cachepath = $subfolder."/".$file; $cachepath = $subfolder . "/" . $file;
if ($writemode) { if ($writemode) {
if (!is_dir($subfolder)) { if (!is_dir($subfolder)) {
@ -2377,6 +2390,7 @@ function get_cachefile($file, $writemode = true) {
} }
} }
/// @TODO no need to put braces here
return($cachepath); return($cachepath);
} }
@ -2497,8 +2511,10 @@ function get_temppath() {
if (($temppath != "") AND App::directory_usable($temppath)) { if (($temppath != "") AND App::directory_usable($temppath)) {
// To avoid any interferences with other systems we create our own directory // To avoid any interferences with other systems we create our own directory
$new_temppath .= "/".$a->get_hostname(); $new_temppath .= "/".$a->get_hostname();
if (!is_dir($new_temppath)) if (!is_dir($new_temppath)) {
/// @TODO There is a mkdir()+chmod() upwards, maybe generalize this (+ configurable) into a function/method?
mkdir($new_temppath); mkdir($new_temppath);
}
if (App::directory_usable($new_temppath)) { if (App::directory_usable($new_temppath)) {
// The new path is usable, we are happy // The new path is usable, we are happy
@ -2519,6 +2535,7 @@ function get_temppath() {
function set_template_engine(App $a, $engine = 'internal') { function set_template_engine(App $a, $engine = 'internal') {
/// @note This function is no longer necessary, but keep it as a wrapper to the class method /// @note This function is no longer necessary, but keep it as a wrapper to the class method
/// to avoid breaking themes again unnecessarily /// to avoid breaking themes again unnecessarily
/// @TODO maybe output a warning here so the theme developer can see it? PHP won't show such warnings like Java does.
$a->set_template_engine($engine); $a->set_template_engine($engine);
} }
@ -2617,20 +2634,24 @@ function infinite_scroll_data($module) {
AND ($module == "network") AND ($_GET["mode"] != "minimal")) { AND ($module == "network") AND ($_GET["mode"] != "minimal")) {
// get the page number // get the page number
if (is_string($_GET["page"])) if (is_string($_GET["page"])) {
$pageno = $_GET["page"]; $pageno = $_GET["page"];
else } else {
$pageno = 1; $pageno = 1;
}
$reload_uri = ""; $reload_uri = "";
// try to get the uri from which we load the content // try to get the uri from which we load the content
foreach ($_GET AS $param => $value) foreach ($_GET AS $param => $value) {
if (($param != "page") AND ($param != "q")) if (($param != "page") AND ($param != "q")) {
$reload_uri .= "&".$param."=".urlencode($value); $reload_uri .= "&" . $param . "=" . urlencode($value);
}
}
if (($a->page_offset != "") AND !strstr($reload_uri, "&offset=")) if (($a->page_offset != "") AND !strstr($reload_uri, "&offset=")) {
$reload_uri .= "&offset=".urlencode($a->page_offset); $reload_uri .= "&offset=" . urlencode($a->page_offset);
}
$arr = array("pageno" => $pageno, "reload_uri" => $reload_uri); $arr = array("pageno" => $pageno, "reload_uri" => $reload_uri);