]> git.mxchange.org Git - friendica.git/blobdiff - include/security.php
Merge pull request #4246 from zeroadam/Widget-#3878
[friendica.git] / include / security.php
index e6437db3c333b052d848ad1cd71909141a8fa14c..3cdfb4f28d83ab6921d6f3f152def8b886cacbf3 100644 (file)
@@ -5,6 +5,7 @@ use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
+use Friendica\Model\Group;
 
 /**
  * @brief Calculate the hash that is needed for the "Friendica" cookie
@@ -164,7 +165,7 @@ function authenticate_success($user_record, $login_initial = false, $interactive
        }
 }
 
-function can_write_wall(App $a, $owner)
+function can_write_wall($owner)
 {
        static $verified = 0;
 
@@ -173,8 +174,7 @@ function can_write_wall(App $a, $owner)
        }
 
        $uid = local_user();
-
-       if (($uid) && ($uid == $owner)) {
+       if ($uid == $owner) {
                return true;
        }
 
@@ -263,7 +263,7 @@ function permissions_sql($owner_id, $remote_verified = false, $groups = null)
                        );
                        if (DBM::is_result($r)) {
                                $remote_verified = true;
-                               $groups = init_groups_visitor($remote_user);
+                               $groups = Group::getIdsByContactId($remote_user);
                        }
                }
 
@@ -325,7 +325,7 @@ function item_permissions_sql($owner_id, $remote_verified = false, $groups = nul
                        );
                        if (DBM::is_result($r)) {
                                $remote_verified = true;
-                               $groups = init_groups_visitor($remote_user);
+                               $groups = Group::getIdsByContactId($remote_user);
                        }
                }
                if ($remote_verified) {
@@ -425,21 +425,12 @@ function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'f
        }
 }
 
-// Returns an array of group id's this contact is a member of.
-// This array will only contain group id's related to the uid of this
-// DFRN contact. They are *not* neccessarily unique across the entire site.
-
-
-if (! function_exists('init_groups_visitor')) {
-function init_groups_visitor($contact_id) {
-       $groups = array();
-       $r = q("SELECT `gid` FROM `group_member`
-               WHERE `contact-id` = %d ",
-               intval($contact_id)
-       );
-       if (DBM::is_result($r)) {
-               foreach ($r as $rr)
-                       $groups[] = $rr['gid'];
-       }
-       return $groups;
-}}
+/**
+ * @brief Kills the "Friendica" cookie and all session data
+ */
+function nuke_session()
+{
+       new_cookie(-3600); // make sure cookie is deleted on browser close, as a security measure
+       session_unset();
+       session_destroy();
+}