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

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
@ -678,9 +679,11 @@ class App {
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,6 +1093,7 @@ class App {
* @param string $name * @param string $name
*/ */
function register_template_engine($class, $name = '') { function register_template_engine($class, $name = '') {
/// @TODO Really === and not just == ?
if ($name === "") { 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'];
@ -1111,6 +1115,7 @@ class App {
* @return object Template Engine instance * @return object Template Engine instance
*/ */
function template_engine($name = '') { function template_engine($name = '') {
/// @TODO really type-check included?
if ($name !== "") { if ($name !== "") {
$template_engine = $name; $template_engine = $name;
} else { } else {
@ -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);
@ -2175,7 +2181,6 @@ function current_theme(){
} }
/// @TODO No final return statement? /// @TODO No final return statement?
} }
/** /**
@ -2258,8 +2263,9 @@ 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;
} }
@ -2275,6 +2281,7 @@ 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)) {
/// @TODO maybe not compare against null, use is_null()
if ($name == null) { if ($name == null) {
$ret .= build_querystring($val, $key); $ret .= build_querystring($val, $key);
} else { } else {
@ -2282,7 +2289,9 @@ function build_querystring($params, $name=null) {
} }
} else { } else {
$val = urlencode($val); $val = urlencode($val);
/// @TODO maybe not compare against null, use is_null()
if ($name != null) { if ($name != null) {
/// @TODO two string concated, can be merged to one
$ret .= $name . "[$key]" . "=$val&"; $ret .= $name . "[$key]" . "=$val&";
} else { } else {
$ret .= "$key=$val&"; $ret .= "$key=$val&";
@ -2304,6 +2313,7 @@ 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;
@ -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);