Use globals instead of $a->data

This commit is contained in:
Michael 2021-07-25 17:28:07 +00:00
parent cc8aeb11de
commit d902f6808d
3 changed files with 32 additions and 11 deletions

View File

@ -12,6 +12,8 @@ use Friendica\Core\Hook;
use Friendica\DI; use Friendica\DI;
use Friendica\Util\Strings; use Friendica\Util\Strings;
global $blockem_words;
function blockem_install() function blockem_install()
{ {
Hook::register('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter'); Hook::register('prepare_body_content_filter', 'addon/blockem/blockem.php', 'blockem_prepare_body_content_filter');
@ -141,6 +143,8 @@ function blockem_display_item(App $a, array &$b = null)
function blockem_conversation_start(App $a, array &$b) function blockem_conversation_start(App $a, array &$b)
{ {
global $blockem_words;
if (!local_user()) { if (!local_user()) {
return; return;
} }
@ -148,7 +152,7 @@ function blockem_conversation_start(App $a, array &$b)
$words = DI::pConfig()->get(local_user(), 'blockem', 'words'); $words = DI::pConfig()->get(local_user(), 'blockem', 'words');
if ($words) { if ($words) {
$a->data['blockem'] = explode(',', $words); $blockem_words = explode(',', $words);
} }
DI::page()['htmlhead'] .= <<< EOT DI::page()['htmlhead'] .= <<< EOT
@ -171,6 +175,8 @@ EOT;
function blockem_item_photo_menu(App $a, array &$b) function blockem_item_photo_menu(App $a, array &$b)
{ {
global $blockem_words;
if (!local_user() || $b['item']['self']) { if (!local_user() || $b['item']['self']) {
return; return;
} }
@ -178,8 +184,8 @@ function blockem_item_photo_menu(App $a, array &$b)
$blocked = false; $blocked = false;
$author = $b['item']['author-link']; $author = $b['item']['author-link'];
if (!empty($a->data['blockem'])) { if (!empty($blockem_words)) {
foreach($a->data['blockem'] as $bloke) { foreach($blockem_words as $bloke) {
if (Strings::compareLink($bloke,$author)) { if (Strings::compareLink($bloke,$author)) {
$blocked = true; $blocked = true;
break; break;

View File

@ -18,6 +18,8 @@ use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Util\Strings; use Friendica\Util\Strings;
global $forumdirectory_search;
function forumdirectory_install() function forumdirectory_install()
{ {
Hook::register('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu'); Hook::register('app_menu', 'addon/forumdirectory/forumdirectory.php', 'forumdirectory_app_menu');
@ -42,13 +44,17 @@ function forumdirectory_init(App $a)
function forumdirectory_post(App $a) function forumdirectory_post(App $a)
{ {
global $forumdirectory_search;
if (!empty($_POST['search'])) { if (!empty($_POST['search'])) {
$a->data['search'] = $_POST['search']; $forumdirectory_search = $_POST['search'];
} }
} }
function forumdirectory_content(App $a) function forumdirectory_content(App $a)
{ {
global $forumdirectory_search;
if ((DI::config()->get('system', 'block_public')) && (!local_user()) && (!remote_user())) { if ((DI::config()->get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
notice(DI::l10n()->t('Public access denied.') . EOL); notice(DI::l10n()->t('Public access denied.') . EOL);
return; return;
@ -59,8 +65,8 @@ function forumdirectory_content(App $a)
Nav::setSelected('directory'); Nav::setSelected('directory');
if (!empty($a->data['search'])) { if (!empty($forumdirectory_search)) {
$search = Strings::escapeTags(trim($a->data['search'])); $search = Strings::escapeTags(trim($forumdirectory_search));
} else { } else {
$search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : ''); $search = (!empty($_GET['search']) ? Strings::escapeTags(trim(rawurldecode($_GET['search']))) : '');
} }

View File

@ -14,6 +14,9 @@ use Friendica\Core\Renderer;
use Friendica\DI; use Friendica\DI;
use Friendica\Util\Strings; use Friendica\Util\Strings;
global $js_upload_jsonresponse;
global $js_upload_result;
function js_upload_install() function js_upload_install()
{ {
Hook::register('photo_upload_form', __FILE__, 'js_upload_form'); Hook::register('photo_upload_form', __FILE__, 'js_upload_form');
@ -42,6 +45,8 @@ function js_upload_form(App $a, array &$b)
function js_upload_post_init(App $a, &$b) function js_upload_post_init(App $a, &$b)
{ {
global $js_upload_result, $js_upload_jsonresponse;
// list of valid extensions // list of valid extensions
$allowedExtensions = ['jpeg', 'gif', 'png', 'jpg']; $allowedExtensions = ['jpeg', 'gif', 'png', 'jpg'];
@ -53,7 +58,7 @@ function js_upload_post_init(App $a, &$b)
$result = $uploader->handleUpload(); $result = $uploader->handleUpload();
// to pass data through iframe you will need to encode all html tags // to pass data through iframe you will need to encode all html tags
$a->data['upload_jsonresponse'] = htmlspecialchars(json_encode($result), ENT_NOQUOTES); $js_upload_jsonresponse = htmlspecialchars(json_encode($result), ENT_NOQUOTES);
if (isset($result['error'])) { if (isset($result['error'])) {
Logger::log('mod/photos.php: photos_post(): error uploading photo: ' . $result['error'], Logger::DEBUG); Logger::log('mod/photos.php: photos_post(): error uploading photo: ' . $result['error'], Logger::DEBUG);
@ -61,12 +66,14 @@ function js_upload_post_init(App $a, &$b)
exit(); exit();
} }
$a->data['upload_result'] = $result; $js_upload_result = $result;
} }
function js_upload_post_file(App $a, &$b) function js_upload_post_file(App $a, &$b)
{ {
$result = $a->data['upload_result']; global $js_upload_result;
$result = $js_upload_result;
$b['src'] = $result['path']; $b['src'] = $result['path'];
$b['filename'] = $result['filename']; $b['filename'] = $result['filename'];
@ -76,9 +83,11 @@ function js_upload_post_file(App $a, &$b)
function js_upload_post_end(App $a, &$b) function js_upload_post_end(App $a, &$b)
{ {
global $js_upload_jsonresponse;
Logger::log('upload_post_end'); Logger::log('upload_post_end');
if (!empty($a->data['upload_jsonresponse'])) { if (!empty($js_upload_jsonresponse)) {
echo $a->data['upload_jsonresponse']; echo $js_upload_jsonresponse;
exit(); exit();
} }
} }