2018-07-19 15:52:05 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file src/Model/PermissionSet.php
|
|
|
|
*/
|
|
|
|
namespace Friendica\Model;
|
|
|
|
|
|
|
|
use Friendica\BaseObject;
|
2018-07-20 14:19:26 +02:00
|
|
|
use Friendica\Database\DBA;
|
2018-07-19 15:52:05 +02:00
|
|
|
|
|
|
|
require_once 'include/dba.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief functions for interacting with the permission set of an object (item, photo, event, ...)
|
|
|
|
*/
|
|
|
|
class PermissionSet extends BaseObject
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Fetch the id of a given permission set. Generate a new one when needed
|
|
|
|
*
|
|
|
|
* @param array $postarray The array from an item, picture or event post
|
|
|
|
* @return id
|
|
|
|
*/
|
|
|
|
public static function fetchIDForPost($postarray)
|
|
|
|
{
|
|
|
|
$condition = ['uid' => $postarray['uid'],
|
2018-07-20 00:40:39 +02:00
|
|
|
'allow_cid' => self::sortPermissions(defaults($postarray, 'allow_cid', '')),
|
|
|
|
'allow_gid' => self::sortPermissions(defaults($postarray, 'allow_gid', '')),
|
|
|
|
'deny_cid' => self::sortPermissions(defaults($postarray, 'deny_cid', '')),
|
|
|
|
'deny_gid' => self::sortPermissions(defaults($postarray, 'deny_gid', ''))];
|
2018-07-19 15:52:05 +02:00
|
|
|
|
2018-07-20 14:19:26 +02:00
|
|
|
$set = DBA::selectFirst('permissionset', ['id'], $condition);
|
2018-07-19 15:52:05 +02:00
|
|
|
|
2018-07-21 14:40:21 +02:00
|
|
|
if (!DBA::is_result($set)) {
|
2018-07-20 14:19:26 +02:00
|
|
|
DBA::insert('permissionset', $condition, true);
|
2018-07-19 15:52:05 +02:00
|
|
|
|
2018-07-20 14:19:26 +02:00
|
|
|
$set = DBA::selectFirst('permissionset', ['id'], $condition);
|
2018-07-19 15:52:05 +02:00
|
|
|
}
|
|
|
|
return $set['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function sortPermissions($permissionlist)
|
|
|
|
{
|
|
|
|
$cleaned_list = trim($permissionlist, '<>');
|
|
|
|
|
|
|
|
if (empty($cleaned_list)) {
|
|
|
|
return $permissionlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
$elements = explode('><', $cleaned_list);
|
|
|
|
|
|
|
|
if (count($elements) <= 1) {
|
|
|
|
return $permissionlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
asort($elements);
|
|
|
|
|
|
|
|
return '<' . implode('><', $elements) . '>';
|
|
|
|
}
|
|
|
|
}
|