mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
This commit is contained in:
parent
5d08706201
commit
a9350fc335
5 changed files with 100 additions and 16 deletions
|
@ -1505,7 +1505,8 @@ if (typeof gtag !== \"function\") {
|
|||
public static function canStream()
|
||||
{
|
||||
self::recreateLoginFromCookie();
|
||||
return !empty($_SESSION['user']['isAdmin']) || !empty($_SESSION['user']['canStream']);
|
||||
|
||||
return !empty($_SESSION['user']['isAdmin']) || !empty($_SESSION['user']['canStream']) || AVideoPlugin::userCanLivestream($_SESSION['user']['id']);
|
||||
}
|
||||
|
||||
public static function externalOptions($id)
|
||||
|
@ -2525,7 +2526,7 @@ if (typeof gtag !== \"function\") {
|
|||
if (self::isLogged() && !empty($_SESSION['user']['canUpload'])) {
|
||||
return true;
|
||||
}
|
||||
return self::isAdmin();
|
||||
return self::isAdmin() || AVideoPlugin::userCanUpload(User::getId());
|
||||
}
|
||||
|
||||
public static function canViewChart()
|
||||
|
|
|
@ -1531,6 +1531,38 @@ class AVideoPlugin
|
|||
return $resp;
|
||||
}
|
||||
|
||||
public static function userCanLivestream($users_id)
|
||||
{
|
||||
if (empty($users_id)) {
|
||||
return false;
|
||||
}
|
||||
$resp = false;
|
||||
$plugins = Plugin::getAllEnabled();
|
||||
foreach ($plugins as $value) {
|
||||
self::YPTstart();
|
||||
$p = static::loadPlugin($value['dirName']);
|
||||
if (is_object($p)) {
|
||||
$can = $p->userCanLivestream($users_id);
|
||||
if (!empty($can)) {
|
||||
if ($can < 0) {
|
||||
if (!empty($users_id)) {
|
||||
_error_log("userCanLivestream: DENIED The plugin {$value['dirName']} said the user ({$users_id}) can NOT upload a video ");
|
||||
}
|
||||
$resp = false;
|
||||
}
|
||||
if ($can > 0) {
|
||||
if (!empty($users_id)) {
|
||||
_error_log("userCanLivestream: SUCCESS The plugin {$value['dirName']} said the user ({$users_id}) can upload a video ");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
self::YPTend("{$value['dirName']}::" . __FUNCTION__);
|
||||
}
|
||||
return $resp;
|
||||
}
|
||||
|
||||
public static function userCanWatchVideo($users_id, $videos_id)
|
||||
{
|
||||
global $userCanWatchVideoFunction;
|
||||
|
|
|
@ -10,6 +10,7 @@ if (empty($isLive)) {
|
|||
} else {
|
||||
$liveInfo = Live::getInfo($isLive['key'], $isLive['live_servers_id']);
|
||||
}
|
||||
|
||||
if (User::canStream()) {
|
||||
if (empty($obj->doNotShowGoLiveButton)) {
|
||||
?>
|
||||
|
|
|
@ -14,6 +14,8 @@ class Permissions extends PluginAbstract {
|
|||
const PERMISSION_CACHE = 40;
|
||||
const PERMISSION_SITEMAP = 50;
|
||||
const PERMISSION_LOG = 60;
|
||||
const PERMISSION_CAN_UPLOAD_VIDEOS = 70;
|
||||
const PERMISSION_CAN_LIVESTREAM = 80;
|
||||
|
||||
public function getDescription() {
|
||||
$desc = "Permissions will allow you to add intermediate permisson to usergroups without need to make them Admin, "
|
||||
|
@ -105,15 +107,8 @@ class Permissions extends PluginAbstract {
|
|||
return false;
|
||||
}
|
||||
|
||||
static function hasPermission($type, $pluginName) {
|
||||
static function hasPermission($type, $pluginName, $users_id = 0) {
|
||||
global $hasPermission;
|
||||
if (!User::isLogged()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (User::isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (empty($hasPermission)) {
|
||||
$hasPermission = [];
|
||||
|
@ -121,11 +116,22 @@ class Permissions extends PluginAbstract {
|
|||
if (empty($hasPermission[$pluginName])) {
|
||||
$hasPermission[$pluginName] = [];
|
||||
}
|
||||
if (isset($hasPermission[$pluginName][$type])) {
|
||||
return $hasPermission[$pluginName][$type];
|
||||
if(empty($users_id)){
|
||||
if (!User::isLogged()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (User::isAdmin()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isset($hasPermission[$pluginName][$type])) {
|
||||
return $hasPermission[$pluginName][$type];
|
||||
}
|
||||
$users_id = User::getId();
|
||||
}
|
||||
$hasPermission[$pluginName][$type] = false;
|
||||
$groups = UserGroups::getUserGroups(User::getId());
|
||||
$groups = UserGroups::getUserGroups($users_id);
|
||||
foreach ($groups as $value) {
|
||||
$permissions = Users_groups_permissions::getAllFromUserGorup($value['id']);
|
||||
if (!empty($permissions[$pluginName]) && in_array($type, $permissions[$pluginName])) {
|
||||
|
@ -144,6 +150,28 @@ class Permissions extends PluginAbstract {
|
|||
return self::hasPermission(Permissions::PERMISSION_FULLACCESSVIDEOS, 'Permissions');
|
||||
}
|
||||
|
||||
public function userCanUpload($users_id) {
|
||||
if(empty($users_id)){
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(self::hasPermission(Permissions::PERMISSION_CAN_UPLOAD_VIDEOS, 'Permissions', $users_id)){
|
||||
return 1;// Yes
|
||||
}
|
||||
return 0;// I dont know
|
||||
}
|
||||
|
||||
public function userCanLivestream($users_id) {
|
||||
if(empty($users_id)){
|
||||
return -1; // NO HE CANT
|
||||
}
|
||||
|
||||
if(self::hasPermission(Permissions::PERMISSION_CAN_LIVESTREAM, 'Permissions', $users_id)){
|
||||
return 1;// Yes
|
||||
}
|
||||
return 0;// I dont know
|
||||
}
|
||||
|
||||
static function canModerateVideos() {
|
||||
return self::hasPermission(Permissions::PERMISSION_INACTIVATEVIDEOS, 'Permissions') || self::canAdminVideos();
|
||||
}
|
||||
|
@ -180,17 +208,30 @@ class Permissions extends PluginAbstract {
|
|||
*/
|
||||
function getPermissionsOptions() {
|
||||
$permissions = [];
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_COMMENTS, __('Comments Admin'), __('Users with this option will be able to edit and delete comments in any video'), 'Permissions');
|
||||
// Video permissions
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_FULLACCESSVIDEOS, __('Videos Admin'), __('Just like admin, this user will have permission to edit and delete videos from any user, including videos from admin'), 'Permissions');
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_INACTIVATEVIDEOS, __('Videos Moderator'), __('This is a level below the (Videos Admin), this type of user can change the video publicity (Active, Inactive, Unlisted)'), 'Permissions');
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_CAN_UPLOAD_VIDEOS, __('Upload Videos'), __('Users with this option will be able to upload videos'), 'Permissions');
|
||||
|
||||
// Comments permissions
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_COMMENTS, __('Comments Admin'), __('Users with this option will be able to edit and delete comments in any video'), 'Permissions');
|
||||
|
||||
// User and User Group permissions
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_USERS, __('Users Admin'), __('This type of user can edit users, can add or remove users into user groups, but cannot make them admins'), 'Permissions');
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_USERGROUPS, __('Users Groups Admin'), __('Can edit and delete user groups'), 'Permissions');
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_CACHE, __('Cache Manager'), __('This will give the option to can clear cache (Site and first page)'), 'Permissions');
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_SITEMAP, __('Sitemap'), __('This will give the option to generate SiteMap'), 'Permissions');
|
||||
|
||||
// Livestream permission
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_CAN_LIVESTREAM, __('Live Stream'), __('Users with this option will be able to live stream'), 'Permissions');
|
||||
|
||||
// Cache, Log, and Sitemap permissions
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_CACHE, __('Cache Manager'), __('This will give the option to clear cache (Site and first page)'), 'Permissions');
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_SITEMAP, __('Sitemap'), __('This will give the option to generate a SiteMap'), 'Permissions');
|
||||
$permissions[] = new PluginPermissionOption(Permissions::PERMISSION_LOG, __('Log'), __('This will give the option to see the log file menu'), 'Permissions');
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
|
||||
static function getPluginPermissions($plugins_id) {
|
||||
global $getPluginPermissions;
|
||||
if(empty($getPluginPermissions)){
|
||||
|
|
|
@ -575,6 +575,15 @@ abstract class PluginAbstract {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $users_id
|
||||
* @return 0 = I dont know, -1 = can not upload, 1 = can upload
|
||||
*/
|
||||
public function userCanLivestream($users_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $users_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue