X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=remote_permissions%2Fremote_permissions.php;h=6fe75f1696983ab908dea5a439195d9f98c3d2e3;hb=af10b60e97b94ba5e8bf60195038c51433966e08;hp=c883c5b89696de73b9fa5a1f777823a9f66a8822;hpb=1454abfdb48b8ba452d897d90f6979bb4f23912c;p=friendica-addons.git
diff --git a/remote_permissions/remote_permissions.php b/remote_permissions/remote_permissions.php
index c883c5b8..6fe75f16 100644
--- a/remote_permissions/remote_permissions.php
+++ b/remote_permissions/remote_permissions.php
@@ -7,22 +7,16 @@
* Status: Unsupported
*/
-use Friendica\Core\Addon;
-use Friendica\Core\Config;
-use Friendica\Core\L10n;
-use Friendica\Core\PConfig;
+use Friendica\Core\Hook;
+use Friendica\Core\Renderer;
use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Util\Strings;
function remote_permissions_install() {
- Addon::registerHook('lockview_content', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_content');
- Addon::registerHook('addon_settings', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings');
- Addon::registerHook('addon_settings_post', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings_post');
-}
-
-function remote_permissions_uninstall() {
- Addon::unregisterHook('lockview_content', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_content');
- Addon::unregisterHook('addon_settings', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings');
- Addon::unregisterHook('addon_settings_post', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings_post');
+ Hook::register('lockview_content', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_content');
+ Hook::register('addon_settings', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings');
+ Hook::register('addon_settings_post', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings_post');
}
function remote_permissions_settings(&$a,&$o) {
@@ -30,37 +24,36 @@ function remote_permissions_settings(&$a,&$o) {
if(! local_user())
return;
- $global = Config::get("remote_perms", "global");
+ $global = DI::config()->get("remote_perms", "global");
if($global == 1)
return;
/* Add our stylesheet to the page so we can make our settings look nice */
- $a->page['htmlhead'] .= '' . "\r\n";
+ DI::page()['htmlhead'] .= '' . "\r\n";
/* Get the current state of our config variable */
- $remote_perms = PConfig::get(local_user(),'remote_perms','show');
+ $remote_perms = DI::pConfig()->get(local_user(),'remote_perms','show');
/* Add some HTML to the existing form */
// $t = file_get_contents("addon/remote_permissions/settings.tpl" );
- $t = get_markup_template("settings.tpl", "addon/remote_permissions/" );
- $o .= replace_macros($t, [
- '$remote_perms_title' => L10n::t('Remote Permissions Settings'),
- '$remote_perms_label' => L10n::t('Allow recipients of your private posts to see the other recipients of the posts'),
+ $t = Renderer::getMarkupTemplate("settings.tpl", "addon/remote_permissions/" );
+ $o .= Renderer::replaceMacros($t, [
+ '$remote_perms_title' => DI::l10n()->t('Remote Permissions Settings'),
+ '$remote_perms_label' => DI::l10n()->t('Allow recipients of your private posts to see the other recipients of the posts'),
'$checked' => (($remote_perms == 1) ? 'checked="checked"' : ''),
- '$submit' => L10n::t('Save Settings')
+ '$submit' => DI::l10n()->t('Save Settings')
]);
}
function remote_permissions_settings_post($a,$post) {
- if(! local_user() || (! x($_POST,'remote-perms-submit')))
+ if(! local_user() || empty($_POST['remote-perms-submit']))
return;
- PConfig::set(local_user(),'remote_perms','show',intval($_POST['remote-perms']));
- info(L10n::t('Remote Permissions settings updated.') . EOL);
+ DI::pConfig()->set(local_user(),'remote_perms','show',intval($_POST['remote-perms']));
}
function remote_permissions_content($a, $item_copy) {
@@ -68,7 +61,7 @@ function remote_permissions_content($a, $item_copy) {
if($item_copy['uid'] != local_user())
return;
- if(Config::get('remote_perms','global') == 0) {
+ if(DI::config()->get('remote_perms','global') == 0) {
// Admin has set Individual choice. We need to find
// the original poster. First, get the contact's info
$r = q("SELECT nick, url FROM contact WHERE id = %d LIMIT 1",
@@ -78,7 +71,7 @@ function remote_permissions_content($a, $item_copy) {
return;
// Find out if the contact lives here
- $baseurl = $a->getBaseURL();
+ $baseurl = DI::baseUrl()->get();
$baseurl = substr($baseurl, strpos($baseurl, '://') + 3);
if(strpos($r[0]['url'], $baseurl) === false)
return;
@@ -91,7 +84,7 @@ function remote_permissions_content($a, $item_copy) {
if(! $r)
return;
- if(PConfig::get($r[0]['uid'],'remote_perms','show') == 0)
+ if(DI::pConfig()->get($r[0]['uid'],'remote_perms','show') == 0)
return;
}
@@ -121,12 +114,14 @@ function remote_permissions_content($a, $item_copy) {
$item = $r[0];
- $allowed_users = expand_acl($item['allow_cid']);
- $allowed_groups = expand_acl($item['allow_gid']);
- $deny_users = expand_acl($item['deny_cid']);
- $deny_groups = expand_acl($item['deny_gid']);
+ $aclFormatter = DI::aclFormatter();
+
+ $allowed_users = $aclFormatter->expand($item['allow_cid']);
+ $allowed_groups = $aclFormatter->expand($item['allow_gid']);
+ $deny_users = $aclFormatter->expand($item['deny_cid']);
+ $deny_groups = $aclFormatter->expand($item['deny_gid']);
- $o = L10n::t('Visible to:') . '
';
+ $o = DI::l10n()->t('Visible to:') . '
';
$allow = [];
$deny = [];
@@ -180,7 +175,7 @@ function remote_permissions_content($a, $item_copy) {
if(! $r)
return;
- $o = L10n::t('Visible to') . ' (' . L10n::t('may only be a partial list') . '):
';
+ $o = DI::l10n()->t('Visible to') . ' (' . DI::l10n()->t('may only be a partial list') . '):
';
foreach($r as $rr)
$allow_names[] = $rr['username'];
@@ -189,23 +184,22 @@ function remote_permissions_content($a, $item_copy) {
// Sort the names alphabetically, case-insensitive
natcasesort($allow_names);
echo $o . implode(', ', $allow_names);
- killme();
+ exit();
}
return;
}
function remote_permissions_addon_admin(&$a, &$o){
- $t = get_markup_template( "admin.tpl", "addon/remote_permissions/" );
- $o = replace_macros($t, [
- '$submit' => L10n::t('Save Settings'),
- '$global' => ['remotepermschoice', L10n::t('Global'), 1, L10n::t('The posts of every user on this server show the post recipients'), Config::get('remote_perms', 'global') == 1],
- '$individual' => ['remotepermschoice', L10n::t('Individual'), 2, L10n::t('Each user chooses whether his/her posts show the post recipients'), Config::get('remote_perms', 'global') == 0]
+ $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/remote_permissions/" );
+ $o = Renderer::replaceMacros($t, [
+ '$submit' => DI::l10n()->t('Save Settings'),
+ '$global' => ['remotepermschoice', DI::l10n()->t('Global'), 1, DI::l10n()->t('The posts of every user on this server show the post recipients'), DI::config()->get('remote_perms', 'global') == 1],
+ '$individual' => ['remotepermschoice', DI::l10n()->t('Individual'), 2, DI::l10n()->t('Each user chooses whether his/her posts show the post recipients'), DI::config()->get('remote_perms', 'global') == 0]
]);
}
function remote_permissions_addon_admin_post(&$a){
- $choice = ((x($_POST,'remotepermschoice')) ? notags(trim($_POST['remotepermschoice'])) : '');
- Config::set('remote_perms','global',($choice == 1 ? 1 : 0));
- info(L10n::t('Settings updated.'). EOL);
+ $choice = (!empty($_POST['remotepermschoice']) ? Strings::escapeTags(trim($_POST['remotepermschoice'])) : '');
+ DI::config()->set('remote_perms','global',($choice == 1 ? 1 : 0));
}