1
1
Fork 0

Some rewrites:

- max_proccesses_reach() and maxload_reached() (why no _ behind max?) are called
  both way, static and with object reference.
- this is strongly discouraged and should be avoided as its support (in PHP) may
  be dropped in future releases.
- used $a = get_app(); to encapsulate code (even when the function does
  currently the same, it may be changed later)

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2016-12-13 10:16:36 +01:00
parent 47c60aa486
commit 293436e5fd
27 changed files with 69 additions and 67 deletions

View file

@ -1294,10 +1294,6 @@ class App {
*/
function max_processes_reached() {
// Is the function called statically?
if (!is_object($this))
return(self::$a->max_processes_reached());
if ($this->is_backend()) {
$process = "backend";
$max_processes = get_config('system', 'max_processes_backend');
@ -1329,10 +1325,6 @@ class App {
*/
function maxload_reached() {
// Is the function called statically?
if (!is_object($this))
return(self::$a->maxload_reached());
if ($this->is_backend()) {
$process = "backend";
$maxsysload = intval(get_config('system', 'maxloadavg'));
@ -1479,14 +1471,14 @@ function system_unavailable() {
function clean_urls() {
global $a;
$a = get_app();
// if($a->config['system']['clean_urls'])
return true;
// return false;
}
function z_path() {
global $a;
$a = get_app();
$base = $a->get_baseurl();
if(! clean_urls())
$base .= '/?q=';
@ -1501,7 +1493,7 @@ function z_path() {
* @return string
*/
function z_root() {
global $a;
$a = get_app();
return $a->get_baseurl();
}
@ -1903,7 +1895,7 @@ function info($s) {
* @return int
*/
function get_max_import_size() {
global $a;
$a = get_app();
return ((x($a->config,'max_import_size')) ? $a->config['max_import_size'] : 0 );
}
@ -2100,7 +2092,7 @@ function current_theme(){
* @return string
*/
function current_theme_url() {
global $a;
$a = get_app();
$t = current_theme();

View file

@ -30,7 +30,7 @@ class Config {
* @return void
*/
public static function load($family) {
global $a;
$a = get_app();
$r = q("SELECT `v`, `k` FROM `config` WHERE `cat` = '%s' ORDER BY `cat`, `k`, `id`", dbesc($family));
if (count($r)) {
@ -72,7 +72,7 @@ class Config {
*/
public static function get($family, $key, $default_value = null, $refresh = false) {
global $a;
$a = get_app();
if (!$refresh) {
// Looking if the whole family isn't set
@ -123,7 +123,7 @@ class Config {
* @return mixed Stored $value or false if the database update failed
*/
public static function set($family, $key, $value) {
global $a;
$a = get_app();
$stored = self::get($family, $key);
@ -171,7 +171,7 @@ class Config {
*/
public static function delete($family, $key) {
global $a;
$a = get_app();
if (x($a->config[$family],$key)) {
unset($a->config[$family][$key]);
}

View file

@ -28,7 +28,7 @@ class PConfig {
* @return void
*/
public static function load($uid, $family) {
global $a;
$a = get_app();
$r = q("SELECT `v`,`k` FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d ORDER BY `cat`, `k`, `id`",
dbesc($family),
intval($uid)
@ -65,7 +65,7 @@ class PConfig {
*/
public static function get($uid, $family, $key, $default_value = null, $refresh = false) {
global $a;
$a = get_app();
if (!$refresh) {
// Looking if the whole family isn't set
@ -120,7 +120,7 @@ class PConfig {
*/
public static function set($uid, $family, $key, $value) {
global $a;
$a = get_app();
$stored = self::get($uid, $family, $key);
@ -171,7 +171,7 @@ class PConfig {
*/
public static function delete($uid,$family,$key) {
global $a;
$a = get_app();
if (x($a->config[$uid][$family], $key)) {
unset($a->config[$uid][$family][$key]);

View file

@ -232,7 +232,7 @@ class Probe {
if ($data["photo"] != "")
$data["baseurl"] = matching_url(normalise_link($data["baseurl"]), normalise_link($data["photo"]));
else
$data["photo"] = App::get_baseurl().'/images/person-175.jpg';
$data["photo"] = $a->get_baseurl().'/images/person-175.jpg';
if (!isset($data["name"]) OR ($data["name"] == "")) {
if (isset($data["nick"]))

View file

@ -409,12 +409,12 @@
$arr['$user'] = $user_info;
$arr['$rss'] = array(
'alternate' => $user_info['url'],
'self' => App::get_baseurl(). "/". $a->query_string,
'base' => App::get_baseurl(),
'self' => $a->get_baseurl(). "/". $a->query_string,
'base' => $a->get_baseurl(),
'updated' => api_date(null),
'atom_updated' => datetime_convert('UTC','UTC','now',ATOM_TIME),
'language' => $user_info['language'],
'logo' => App::get_baseurl()."/images/friendica-32.png",
'logo' => $a->get_baseurl()."/images/friendica-32.png",
);
return $arr;
@ -693,7 +693,7 @@
'follow_request_sent' => false,
'statusnet_blocking' => false,
'notifications' => false,
//'statusnet_profile_url' => App::get_baseurl()."/contacts/".$uinfo[0]['cid'],
//'statusnet_profile_url' => $a->get_baseurl()."/contacts/".$uinfo[0]['cid'],
'statusnet_profile_url' => $uinfo[0]['url'],
'uid' => intval($uinfo[0]['uid']),
'cid' => intval($uinfo[0]['cid']),
@ -1078,8 +1078,8 @@
if ($r) {
$phototypes = Photo::supportedTypes();
$ext = $phototypes[$r[0]['type']];
$_REQUEST['body'] .= "\n\n".'[url='.App::get_baseurl().'/photos/'.$r[0]['nickname'].'/image/'.$r[0]['resource-id'].']';
$_REQUEST['body'] .= '[img]'.App::get_baseurl()."/photo/".$r[0]['resource-id']."-".$r[0]['scale'].".".$ext."[/img][/url]";
$_REQUEST['body'] .= "\n\n".'[url='.$a->get_baseurl().'/photos/'.$r[0]['nickname'].'/image/'.$r[0]['resource-id'].']';
$_REQUEST['body'] .= '[img]'.$a->get_baseurl()."/photo/".$r[0]['resource-id']."-".$r[0]['scale'].".".$ext."[/img][/url]";
}
}
@ -1777,7 +1777,7 @@
$start = $page*$count;
// Ugly code - should be changed
$myurl = App::get_baseurl() . '/profile/'. $a->user['nickname'];
$myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
$myurl = substr($myurl,strpos($myurl,'://')+3);
//$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
$myurl = str_replace('www.','',$myurl);
@ -2302,7 +2302,7 @@
$text = preg_replace_callback(
"|data:image/([^;]+)[^=]+=*|m",
function($match) use ($item) {
return App::get_baseurl()."/display/".$item['guid'];
return $a->get_baseurl()."/display/".$item['guid'];
},
$text);
return $text;
@ -2690,7 +2690,7 @@
$name = $a->config['sitename'];
$server = $a->get_hostname();
$logo = App::get_baseurl() . '/images/friendica-64.png';
$logo = $a->get_baseurl() . '/images/friendica-64.png';
$email = $a->config['admin_email'];
$closed = (($a->config['register_policy'] == REGISTER_CLOSED) ? 'true' : 'false');
$private = (($a->config['system']['block_public']) ? 'true' : 'false');
@ -2698,7 +2698,7 @@
if($a->config['api_import_size'])
$texlimit = string($a->config['api_import_size']);
$ssl = (($a->config['system']['have_ssl']) ? 'true' : 'false');
$sslserver = (($ssl === 'true') ? str_replace('http:','https:',App::get_baseurl()) : '');
$sslserver = (($ssl === 'true') ? str_replace('http:','https:',$a->get_baseurl()) : '');
$config = array(
'site' => array('name' => $name,'server' => $server, 'theme' => 'default', 'path' => '',
@ -3075,7 +3075,7 @@
$photo['album'] = $rr['album'];
$photo['filename'] = $rr['filename'];
$photo['type'] = $rr['type'];
$thumb = App::get_baseurl()."/photo/".$rr['resource-id']."-".$rr['scale'].".".$typetoext[$rr['type']];
$thumb = $a->get_baseurl()."/photo/".$rr['resource-id']."-".$rr['scale'].".".$typetoext[$rr['type']];
if ($type == "xml")
$data['photo'][] = array("@attributes" => $photo, "1" => $thumb);
@ -3124,11 +3124,11 @@
for ($k=intval($data['photo']['minscale']); $k<=intval($data['photo']['maxscale']); $k++)
$data['photo']['links'][$k.":link"]["@attributes"] = array("type" => $data['photo']['type'],
"scale" => $k,
"href" => App::get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']]);
"href" => $a->get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']]);
} else {
$data['photo']['link'] = array();
for ($k=intval($data['photo']['minscale']); $k<=intval($data['photo']['maxscale']); $k++) {
$data['photo']['link'][$k] = App::get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']];
$data['photo']['link'][$k] = $a->get_baseurl()."/photo/".$data['photo']['resource-id']."-".$k.".".$typetoext[$data['photo']['type']];
}
}
unset($data['photo']['resource-id']);

View file

@ -146,7 +146,7 @@ class exAuth {
* @param array $aCommand The command array
*/
private function isuser($aCommand) {
global $a;
$a = get_app();
// Check if there is a username
if (!isset($aCommand[1])) {
@ -214,7 +214,7 @@ class exAuth {
* @param array $aCommand The command array
*/
private function auth($aCommand) {
global $a;
$a = get_app();
// check user authentication
if (sizeof($aCommand) != 4) {

View file

@ -42,7 +42,7 @@ function cron_run(&$argv, &$argc){
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run") {
if (App::maxload_reached())
if ($a->maxload_reached())
return;
if (App::is_already_running('cron', 'include/cron.php', 540))
return;

View file

@ -25,7 +25,7 @@ function cronhooks_run(&$argv, &$argc){
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run") {
if (App::maxload_reached())
if ($a->maxload_reached())
return;
if (App::is_already_running('cronhooks', 'include/cronhooks.php', 1140))
return;

View file

@ -35,7 +35,7 @@ class dba {
public $error = false;
function __construct($server, $user, $pass, $db, $install = false) {
global $a;
$a = get_app();
$stamp1 = microtime(true);
@ -139,7 +139,7 @@ class dba {
}
public function q($sql, $onlyquery = false) {
global $a;
$a = get_app();
if (!$this->db || !$this->connected) {
return false;

View file

@ -44,7 +44,7 @@ class dba {
public $error = false;
function __construct($server,$user,$pass,$db,$install = false) {
global $a;
$a = get_app();
# work around, to store the database - configuration in DDDBL
$objDataObjectPool = new \DDDBL\DataObjectPool('Database-Definition');
@ -99,7 +99,7 @@ class dba {
}
public function q($sql, $onlyquery = false) {
global $a;
$a = get_app();
$strHandler = (true === $onlyquery) ? 'PDOStatement' : 'MULTI';

View file

@ -57,7 +57,7 @@ function delivery_run(&$argv, &$argc){
continue;
}
if (App::maxload_reached())
if ($a->maxload_reached())
return;
// It's ours to deliver. Remove it from the queue.

View file

@ -1443,6 +1443,7 @@ class dfrn {
* @param array $importer Record of the importer user mixed with contact of the content
*/
private function process_suggestion($xpath, $suggestion, $importer) {
$a = get_app();
logger("Processing suggestions");
@ -1524,7 +1525,7 @@ class dfrn {
"to_email" => $importer["email"],
"uid" => $importer["importer_uid"],
"item" => $suggest,
"link" => App::get_baseurl()."/notifications/intros",
"link" => $a->get_baseurl()."/notifications/intros",
"source_name" => $importer["name"],
"source_link" => $importer["url"],
"source_photo" => $importer["photo"],
@ -1791,6 +1792,8 @@ class dfrn {
* @param int $posted_id The record number of item record that was just posted
*/
private function do_poke($item, $importer, $posted_id) {
$a = get_app();
$verb = urldecode(substr($item["verb"],strpos($item["verb"], "#")+1));
if(!$verb)
return;
@ -1810,7 +1813,7 @@ class dfrn {
}
}
if($Blink && link_compare($Blink,App::get_baseurl()."/profile/".$importer["nickname"])) {
if($Blink && link_compare($Blink,$a->get_baseurl()."/profile/".$importer["nickname"])) {
// send a notification
notification(array(
@ -1821,7 +1824,7 @@ class dfrn {
"to_email" => $importer["email"],
"uid" => $importer["importer_uid"],
"item" => $item,
"link" => App::get_baseurl()."/display/".urlencode(get_item_guid($posted_id)),
"link" => $a->get_baseurl()."/display/".urlencode(get_item_guid($posted_id)),
"source_name" => stripslashes($item["author-name"]),
"source_link" => $item["author-link"],
"source_photo" => ((link_compare($item["author-link"],$importer["url"]))

View file

@ -26,7 +26,7 @@ function discover_poco_run(&$argv, &$argc){
// Don't check this stuff if the function is called by the poller
if (App::callstack() != "poller_run")
if (App::maxload_reached())
if ($a->maxload_reached())
return;
if(($argc > 2) && ($argv[1] == "dirsearch")) {

View file

@ -648,6 +648,7 @@ function notification($params) {
* @param str $defaulttype (Optional) Forces a notification with this type.
*/
function check_item_notification($itemid, $uid, $defaulttype = "") {
$a = get_app();
$notification_data = array("uid" => $uid, "profiles" => array());
call_hooks('check_item_notification', $notification_data);
@ -666,7 +667,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
$profiles[] = $owner[0]["url"];
// Notifications from Diaspora are often with an URL in the Diaspora format
$profiles[] = App::get_baseurl()."/u/".$user[0]["nickname"];
$profiles[] = $a->get_baseurl()."/u/".$user[0]["nickname"];
$profiles2 = array();
@ -720,7 +721,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
$params["to_email"] = $user[0]["email"];
$params["item"] = $item[0];
$params["parent"] = $item[0]["parent"];
$params["link"] = App::get_baseurl().'/display/'.urlencode($item[0]["guid"]);
$params["link"] = $a->get_baseurl().'/display/'.urlencode($item[0]["guid"]);
$params["otype"] = 'item';
$params["source_name"] = $item[0]["author-name"];
$params["source_link"] = $item[0]["author-link"];

View file

@ -590,7 +590,7 @@ function process_events ($arr) {
$is_first = ($d !== $last_date);
$last_date = $d;
$edit = ((! $rr['cid']) ? array(App::get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null);
$edit = ((! $rr['cid']) ? array($a->get_baseurl().'/events/event/'.$rr['id'],t('Edit event'),'','') : null);
$title = strip_tags(html_entity_decode(bbcode($rr['summary']),ENT_QUOTES,'UTF-8'));
if(! $title) {
list($title, $_trash) = explode("<br",bbcode($rr['desc']),2);

View file

@ -1,6 +1,6 @@
<?php
function create_files_from_item($itemid) {
global $a;
$a = get_app();
$messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `file`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));

View file

@ -149,6 +149,8 @@ function oembed_fetch_url($embedurl, $no_rich_type = false){
}
function oembed_format_object($j){
$a = get_app();
require_once("mod/proxy.php");
$embedurl = $j->embedurl;
@ -165,7 +167,7 @@ function oembed_format_object($j){
$th=120; $tw = $th*$tr;
$tpl=get_markup_template('oembed_video.tpl');
$ret.=replace_macros($tpl, array(
'$baseurl' => App::get_baseurl(),
'$baseurl' => $a->get_baseurl(),
'$embedurl'=>$embedurl,
'$escapedhtml'=>base64_encode($jhtml),
'$tw'=>$tw,
@ -255,12 +257,14 @@ function oembed_format_object($j){
* @see oembed_format_object()
*/
function oembed_iframe($src, $width, $height) {
$a = get_app();
if (!$height || strstr($height,'%')) {
$height = '200';
}
$width = '100%';
$s = App::get_baseurl() . '/oembed/'.base64url_encode($src);
$s = $a->get_baseurl() . '/oembed/'.base64url_encode($src);
return '<iframe onload="resizeIframe(this);" class="embed_rich" height="' . $height . '" width="' . $width . '" src="' . $s . '" allowfullscreen scrolling="no" frameborder="no">' . t('Embedded content') . '</iframe>';
}

View file

@ -98,7 +98,7 @@ if(! function_exists('load_translation_table')) {
* @param string $lang language code to load
*/
function load_translation_table($lang) {
global $a;
$a = get_app();
$a->strings = array();
// load enabled plugins strings

View file

@ -39,7 +39,7 @@ function poller_run($argv, $argc){
return;
}
if (App::maxload_reached()) {
if ($a->maxload_reached()) {
return;
}

View file

@ -1728,6 +1728,8 @@ function update_gcontact_from_probe($url) {
* @param int $uid User ID
*/
function update_gcontact_for_user($uid) {
$a = get_app();
$r = q("SELECT `profile`.`locality`, `profile`.`region`, `profile`.`country-name`,
`profile`.`name`, `profile`.`about`, `profile`.`gender`,
`profile`.`pub_keywords`, `profile`.`dob`, `profile`.`photo`,
@ -1744,7 +1746,7 @@ function update_gcontact_for_user($uid) {
// The "addr" field was added in 3.4.3 so it can be empty for older users
if ($r[0]["addr"] != "")
$addr = $r[0]["nickname"].'@'.str_replace(array("http://", "https://"), "", App::get_baseurl());
$addr = $r[0]["nickname"].'@'.str_replace(array("http://", "https://"), "", $a->get_baseurl());
else
$addr = $r[0]["addr"];
@ -1754,7 +1756,7 @@ function update_gcontact_for_user($uid) {
"notify" => $r[0]["notify"], "url" => $r[0]["url"],
"hide" => ($r[0]["hidewall"] OR !$r[0]["net-publish"]),
"nick" => $r[0]["nickname"], "addr" => $addr,
"connect" => $addr, "server_url" => App::get_baseurl(),
"connect" => $addr, "server_url" => $a->get_baseurl(),
"generation" => 1, "network" => NETWORK_DFRN);
update_gcontact($gcontact);

View file

@ -1,6 +1,6 @@
<?php
function create_tags_from_item($itemid) {
global $a;
$a = get_app();
$profile_base = $a->get_baseurl();
$profile_data = parse_url($profile_base);

View file

@ -699,7 +699,7 @@ $LOGGER_LEVELS = array();
* @param int $level
*/
function logger($msg, $level = 0) {
global $a;
$a = get_app();
global $db;
global $LOGGER_LEVELS;

View file

@ -63,7 +63,7 @@ function fbrowser_content($a){
);
function _map_files1($rr){
global $a;
$a = get_app();
$types = Photo::supportedTypes();
$ext = $types[$rr['type']];
@ -110,7 +110,8 @@ function fbrowser_content($a){
intval(local_user())
);
function _map_files2($rr){ global $a;
function _map_files2($rr){
$a = get_app();
list($m1,$m2) = explode("/",$rr['filetype']);
$filetype = ( (file_exists("images/icons/$m1.png"))?$m1:"zip");

View file

@ -27,7 +27,7 @@ function fetch_init($a){
$parts = parse_url($r[0]["author-link"]);
$host = $parts["scheme"]."://".$parts["host"];
if (normalise_link($host) != normalise_link(App::get_baseurl())) {
if (normalise_link($host) != normalise_link($a->get_baseurl())) {
$location = $host."/fetch/".$a->argv[1]."/".urlencode($guid);
header("HTTP/1.1 301 Moved Permanently");

View file

@ -31,7 +31,7 @@ function p_init($a){
$parts = parse_url($r[0]["author-link"]);
$host = $parts["scheme"]."://".$parts["host"];
if (normalise_link($host) != normalise_link(App::get_baseurl())) {
if (normalise_link($host) != normalise_link($a->get_baseurl())) {
$location = $host."/p/".urlencode($guid).".xml";
header("HTTP/1.1 301 Moved Permanently");

View file

@ -21,8 +21,7 @@ class BaseObject {
if(self::$app)
return self::$app;
global $a;
self::$app = $a;
self::$app = get_app();
return self::$app;
}

View file

@ -127,7 +127,7 @@ class Conversation extends BaseObject {
* _ false on failure
*/
public function get_template_data($conv_responses) {
global $a;
$a = get_app();
$result = array();
$i = 0;