/
classlistfrompolicy.ctpl
158 lines (150 loc) · 5.18 KB
/
classlistfrompolicy.ctpl
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
function &classListFromPolicy( &$policy )
{
$canCreateClassIDListPart = array();
$hasClassIDLimitation = false;
/*START:code-template::is-node*/
$object = false;
/*END:code-template::is-node*/
if ( isset( $policy['Class'] ) )
{
$canCreateClassIDListPart =& $policy['Class'];
$hasClassIDLimitation = true;
}
if ( isset( $policy['User_Section'] ) )
{
/*START:code-template::is-node*/
if ( $object === false )
$object =& $this->attribute( 'object' );
if ( !in_array( $object->attribute( 'section_id' ), $policy['Section'] ) )
/*END:code-template::is-node*/
/*START:code-template::is-object*/
if ( !in_array( $this->attribute( 'section_id' ), $policy['User_Section'] ) )
/*END:code-template::is-object*/
{
return array();
}
}
if ( isset( $policy['User_Subtree'] ) )
{
$allowed = false;
/*START:code-template::is-node*/
if ( $object === false )
$object =& $this->attribute( 'object' );
$assignedNodes =& $object->attribute( 'assigned_nodes' );
/*END:code-template::is-node*/
/*START:code-template::is-object*/
$assignedNodes =& $this->attribute( 'assigned_nodes' );
/*END:code-template::is-object*/
foreach ( $assignedNodes as $assignedNode )
{
$path =& $assignedNode->attribute( 'path_string' );
foreach ( $policy['User_Subtree'] as $subtreeString )
{
if ( strstr( $path, $subtreeString ) )
{
$allowed = true;
break;
}
}
}
if( !$allowed )
{
return array();
}
}
if ( isset( $policy['Section'] ) )
{
/*START:code-template::is-node*/
if ( $object === false )
$object =& $this->attribute( 'object' );
if ( !in_array( $object->attribute( 'section_id' ), $policy['Section'] ) )
/*END:code-template::is-node*/
/*START:code-template::is-object*/
if ( !in_array( $this->attribute( 'section_id' ), $policy['Section'] ) )
/*END:code-template::is-object*/
{
return array();
}
}
if ( isset( $policy['ParentClass'] ) )
{
/*START:code-template::is-node*/
if ( $object === false )
$object =& $this->attribute( 'object' );
if ( !in_array( $object->attribute( 'contentclass_id' ), $policy['ParentClass'] ) )
/*END:code-template::is-node*/
/*START:code-template::is-object*/
if ( !in_array( $this->attribute( 'contentclass_id' ), $policy['ParentClass'] ) )
/*END:code-template::is-object*/
{
return array();
}
}
if ( isset( $policy['Assigned'] ) )
{
/*START:code-template::is-node*/
if ( $object === false )
$object =& $this->attribute( 'object' );
if ( $object->attribute( 'owner_id' ) != $user->attribute( 'contentobject_id' ) )
/*END:code-template::is-node*/
/*START:code-template::is-object*/
if ( $this->attribute( 'owner_id' ) != $user->attribute( 'contentobject_id' ) )
/*END:code-template::is-object*/
{
return array();
}
}
$allowedNode = false;
if ( isset( $policy['Node'] ) )
{
$allowed = false;
foreach( $policy['Node'] as $nodeID )
{
$mainNodeID = $this->attribute( 'main_node_id' );
$node =& eZContentObjectTreeNode::fetch( $nodeID );
if ( $mainNodeID == $node->attribute( 'main_node_id' ) )
{
$allowed = true;
$allowedNode = true;
break;
}
}
if ( !$allowed && !isset( $policy['Subtree'] ) )
{
return array();
}
}
if ( isset( $policy['Subtree'] ) )
{
$allowed = false;
/*START:code-template::is-node*/
if ( $object === false )
$object =& $this->attribute( 'object' );
$assignedNodes =& $object->attribute( 'assigned_nodes' );
/*END:code-template::is-node*/
/*START:code-template::is-object*/
$assignedNodes =& $this->attribute( 'assigned_nodes' );
/*END:code-template::is-object*/
foreach ( $assignedNodes as $assignedNode )
{
$path =& $assignedNode->attribute( 'path_string' );
foreach ( $policy['Subtree'] as $subtreeString )
{
if ( strstr( $path, $subtreeString ) )
{
$allowed = true;
break;
}
}
}
if ( !$allowed && !$allowedNode )
{
return array();
}
}
if ( $hasClassIDLimitation )
{
return $canCreateClassIDListPart;
}
return '*';
}