]> git.mxchange.org Git - friendica-addons.git/blobdiff - remote_permissions/remote_permissions.php
add __FILE__
[friendica-addons.git] / remote_permissions / remote_permissions.php
index 94bdf5c11ea0d89a8a7320cf9882287e015759c9..5adfc028559d726fce1b5442ef21ea66a3359b1b 100644 (file)
@@ -4,23 +4,27 @@
  * Description: Allow the recipients of private posts to see who else can see the post by clicking the lock icon
  * Version: 1.0
  * Author: Zach <https://f.shmuz.in/profile/techcity>
- *
+ * Status: Unsupported
  */
-use Friendica\Core\Addon;
+
 use Friendica\Core\Config;
+use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\PConfig;
+use Friendica\Core\Renderer;
+use Friendica\Database\DBA;
+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');
+       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_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::unregister('lockview_content', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_content');
+       Hook::unregister('addon_settings', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings');
+       Hook::unregister('addon_settings_post', 'addon/remote_permissions/remote_permissions.php', 'remote_permissions_settings_post');
 }
 
 function remote_permissions_settings(&$a,&$o) {
@@ -34,7 +38,7 @@ function remote_permissions_settings(&$a,&$o) {
 
        /* Add our stylesheet to the page so we can make our settings look nice */
 
-       $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->get_baseurl() . '/addon/remote_permissions/settings.css' . '" media="all" />' . "\r\n";
+       $a->page['htmlhead'] .= '<link rel="stylesheet"  type="text/css" href="' . $a->getBaseURL() . '/addon/remote_permissions/settings.css' . '" media="all" />' . "\r\n";
 
        /* Get the current state of our config variable */
 
@@ -43,8 +47,8 @@ function remote_permissions_settings(&$a,&$o) {
        /* 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, [
+       $t = Renderer::getMarkupTemplate("settings.tpl", "addon/remote_permissions/" );
+       $o .= Renderer::replaceMacros($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'),
                '$checked' => (($remote_perms == 1) ? 'checked="checked"' : ''),
@@ -54,7 +58,7 @@ function remote_permissions_settings(&$a,&$o) {
 }
 
 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']));
@@ -76,7 +80,7 @@ function remote_permissions_content($a, $item_copy) {
                        return;
 
                // Find out if the contact lives here
-               $baseurl = $a->get_baseurl();
+               $baseurl = $a->getBaseURL();
                $baseurl = substr($baseurl, strpos($baseurl, '://') + 3);
                if(strpos($r[0]['url'], $baseurl) === false)
                        return;
@@ -84,7 +88,7 @@ function remote_permissions_content($a, $item_copy) {
                // The contact lives here. Get his/her user info
                $nick = $r[0]['nick'];
                $r = q("SELECT uid FROM user WHERE nickname = '%s' LIMIT 1",
-                      dbesc($nick)
+                      DBA::escape($nick)
                );
                if(! $r)
                        return;
@@ -104,15 +108,15 @@ function remote_permissions_content($a, $item_copy) {
                if($item_copy['uri'] === $item_copy['parent-uri']) {
                        // Lockview for a top-level post
                        $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s' AND type = 'wall' LIMIT 1",
-                                  dbesc($item_copy['uri'])
+                                  DBA::escape($item_copy['uri'])
                        );
                }
                else {
                        // Lockview for a comment
                        $r = q("SELECT allow_cid, allow_gid, deny_cid, deny_gid FROM item WHERE uri = '%s'
                                AND parent = ( SELECT id FROM item WHERE uri = '%s' AND type = 'wall' ) LIMIT 1",
-                                  dbesc($item_copy['uri']),
-                                  dbesc($item_copy['parent-uri'])
+                                  DBA::escape($item_copy['uri']),
+                                  DBA::escape($item_copy['parent-uri'])
                        );
                }
                if($r) {
@@ -130,7 +134,7 @@ function remote_permissions_content($a, $item_copy) {
 
                        if(count($allowed_groups)) {
                                $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )",
-                                       dbesc(implode(', ', $allowed_groups))
+                                       DBA::escape(implode(', ', $allowed_groups))
                                );
                                foreach($r as $rr)
                                        $allow[] = $rr['contact-id'];
@@ -139,7 +143,7 @@ function remote_permissions_content($a, $item_copy) {
 
                        if(count($deny_groups)) {
                                $r = q("SELECT DISTINCT `contact-id` FROM group_member WHERE gid IN ( %s )",
-                                       dbesc(implode(', ', $deny_groups))
+                                       DBA::escape(implode(', ', $deny_groups))
                                );
                                foreach($r as $rr)
                                        $deny[] = $rr['contact-id'];
@@ -149,7 +153,7 @@ function remote_permissions_content($a, $item_copy) {
                        if($allow)
                        {
                                $r = q("SELECT name FROM contact WHERE id IN ( %s )",
-                                          dbesc(implode(', ', array_diff($allow, $deny)))
+                                          DBA::escape(implode(', ', array_diff($allow, $deny)))
                                );
                                foreach($r as $rr)
                                        $allow_names[] = $rr['name'];
@@ -162,8 +166,8 @@ function remote_permissions_content($a, $item_copy) {
                        // will have different URIs than the original. We can match the GUID for
                        // those
                        $r = q("SELECT `uid` FROM item WHERE uri = '%s' OR guid = '%s'",
-                                  dbesc($item_copy['uri']),
-                              dbesc($item_copy['guid'])
+                                  DBA::escape($item_copy['uri']),
+                              DBA::escape($item_copy['guid'])
                        );
                        if(! $r)
                                return;
@@ -173,7 +177,7 @@ function remote_permissions_content($a, $item_copy) {
                                $allow[] = $rr['uid'];
 
                        $r = q("SELECT username FROM user WHERE uid IN ( %s )",
-                               dbesc(implode(', ', $allow))
+                               DBA::escape(implode(', ', $allow))
                        );
                        if(! $r)
                                return;
@@ -187,15 +191,15 @@ 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, [
+       $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/remote_permissions/" );
+       $o = Renderer::replaceMacros($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]
@@ -203,7 +207,7 @@ function remote_permissions_addon_admin(&$a, &$o){
 }
 
 function remote_permissions_addon_admin_post(&$a){
-       $choice =       ((x($_POST,'remotepermschoice'))                ? notags(trim($_POST['remotepermschoice']))     : '');
+       $choice =       (!empty($_POST['remotepermschoice'])            ? Strings::escapeTags(trim($_POST['remotepermschoice']))        : '');
        Config::set('remote_perms','global',($choice == 1 ? 1 : 0));
        info(L10n::t('Settings updated.'). EOL);
 }