aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Lib/Permcat.php
blob: 525e55091a5f759bd79e2b60eb7fb2d7cfb17ef1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php

namespace Zotlabs\Lib;

use \Zotlabs\Access as Zaccess;

class Permcat {

	private $permcats = [];

	public function __construct($channel_id) {

		$name = 'default';
		$localname = t('default','permcat');
		
		$perms = Zaccess\Permissions::FilledAutoPerms($channel_id);
		if(! $perms) {
			$role = get_pconfig($channel_id,'system','permissions_role');
			if($role) {
				$x = Zaccess\PermissionRoles::role_perms($role);
				$perms = Zaccess\Permissions::FilledPerms($x['perms_connect']);
			}
			if(! $perms) {
				$perms = Zaccess\Permissions::FilledPerms([]);
			}
		}

		$this->permcats[] = [
			'name'      => $name,
			'localname' => $localname,
			'perms'     => Zaccess\Permissions::Operms($perms)
		];


		$p = $this->load_permcats($channel_id);
		if($p) {
			for($x = 0; $x < count($p); $x++) {
				$this->permcats[] = [
					'name'      => $p[$x][0],
					'localname' => $p[$x][1],
					'perms'     => Zaccess\Permissions::Operms(Zaccess\Permissions::FilledPerms($p[$x][2]))
				];
			}
		}
	}


	public function listing() {
		return $this->permcats;
	}

	public function fetch($name) {
		if($name && $this->permcats) {
			foreach($this->permcats as $permcat) {
				if(strcasecmp($permcat['name'],$name) === 0) {
					return $permcat;
				}
			}
		}
		return ['error' => true];
	}

	public function load_permcats($uid) {

		$permcats = [
			[ 'follower', t('follower','permcat'),
				[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
				  'post_like' ]
			],

			[ 'contributor', t('contributor','permcat'),
				[ 'view_stream','view_profile','view_contacts','view_storage','view_pages','view_wiki',
				  'post_wall','post_comments','write_wiki','post_like','tag_deliver','chat' ]
			],
			[ 'trusted', t('trusted','permcat'),
				[ 'view_stream','view_profile','view_contacts','view_storage','view_pages',
				  'write_storage','post_wall','write_pages','write_wiki','post_comments','post_like','tag_deliver',
				  'chat', 'republish' ]
			],
			[ 'moderator', t('moderator','permcat'),
				[ 'view_stream','view_profile','view_contacts','view_storage','view_pages',
				  'write_storage','post_wall','write_pages','write_wiki','post_comments','post_like','tag_deliver',
				  'chat', 'republish' ]
			]
		];

		if($uid) {
			$x = q("select * from pconfig where uid = %d and cat = 'permcat'",
				intval($uid)
			);
			if($x) {
				foreach($x as $xv) {
					$permcats[] = [ $xv['k'], $xv['k'], $xv['v'] ];
				}
			}
		}					

		call_hooks('permcats',$permcats);

		return $permcats;

	}

	static public function update($channel_id, $name,$permarr) {
		PConfig::Set($channel_id,'permcat',$name,$permarr);
	}

	static public function delete($channel_id,$name) {
		PConfig::Delete($channel_id,'permcat',$name);
	}


}