forked from zikula-modules/Mediashare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.php
187 lines (149 loc) · 5.74 KB
/
common.php
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
// $Id$
//
// Mediashare by Jorn Lind-Nielsen (C) 2003.
//
define('mediashareAccessRequirementView', 1);
define('mediashareAccessRequirementEditAlbum', 2);
define('mediashareAccessRequirementEditMedia', 4);
define('mediashareAccessRequirementAddAlbum', 8);
define('mediashareAccessRequirementAddMedia', 16);
define('mediashareAccessRequirementEditAccess', 128);
define('mediashareAccessRequirementAddSomething', mediashareAccessRequirementAddAlbum | mediashareAccessRequirementAddMedia);
define('mediashareAccessRequirementEditSomething', mediashareAccessRequirementEditAlbum | mediashareAccessRequirementEditMedia | mediashareAccessRequirementAddAlbum | mediashareAccessRequirementAddMedia);
define('mediashareAccessRequirementViewSomething', mediashareAccessRequirementView | mediashareAccessRequirementEditSomething);
/**
* URL helpers
*/
function mediashareGetIntUrl($param, $args, $default)
{
$i = isset($args[$param]) ? $args[$param] : FormUtil::getPassedValue($param);
if ($i == '') {
$i = $default;
}
return (int)$i;
}
function mediashareGetBoolUrl($param, $args, $default)
{
$i = isset($args[$param]) ? $args[$param] : FormUtil::getPassedValue($param);
if ($i == '') {
$i = $default;
} else {
$i = $i == '0' ? false : true;
}
return $i;
}
function mediashareGetStringUrl($param, $args, $default = null)
{
$s = isset($args[$param]) ? $args[$param] : FormUtil::getPassedValue($param);
if ($s == '') {
$s = $default;
}
return $s;
}
/**
* Access control
*/
function mediashareGetAccessAPI()
{
if (file_exists('modules/mediashare/localaccessapi.php')) {
require_once 'modules/mediashare/localaccessapi.php';
} else {
require_once 'modules/mediashare/accessapi.php';
}
return mediashareCreateAccessAPI();
}
function mediashareAccessAlbum($albumId, $access, $viewKey = null)
{
return pnModAPIFunc('mediashare', 'user', 'hasAlbumAccess',
array('albumId' => $albumId,
'access' => $access,
'viewKey' => $viewKey));
}
function mediashareAccessItem($mediaId, $access, $viewKey = null)
{
return pnModAPIFunc('mediashare', 'user', 'hasItemAccess',
array('mediaId' => $mediaId,
'access' => $access,
'viewKey' => $viewKey));
}
function mediashareAccessUserRealName()
{
$accessApi = mediashareGetAccessAPI();
return $accessApi->hasUserRealNameAccess();
}
function mediashareAddAccess(&$render, $album)
{
$albumId = $album['id'];
// Fetch access settings for this album
if (($access = pnModAPIFunc('mediashare', 'user', 'getAlbumAccess', array('albumId' => $albumId))) === false) {
return false;
}
// Fetch access settings for parent album
$parentAccess = 0;
if ($albumId > 1) {
$parentAccess = pnModAPIFunc('mediashare', 'user', 'getAlbumAccess', array('albumId' => $album['parentAlbumId']));
}
if ($parentAccess === false) {
return false;
}
$access = array(
'hasEditAlbumAccess' => ($access & mediashareAccessRequirementEditAlbum) != 0,
'hasEditMediaAccess' => ($access & mediashareAccessRequirementEditMedia) != 0 && $album['allowMediaEdit'],
'hasAddAlbumAccess' => ($access & mediashareAccessRequirementAddAlbum) != 0,
'hasAddMediaAccess' => ($access & mediashareAccessRequirementAddMedia) != 0 && $album['allowMediaEdit'],
'hasEditAccessAccess' => ($access & mediashareAccessRequirementEditAccess) != 0,
'hasAnyEditAccess' => ($access & mediashareAccessRequirementEditSomething) != 0,
'hasParentAccess' => ($parentAccess & mediashareAccessRequirementEditSomething) != 0
);
$render->assign('access', $access);
return true;
}
/**
* Other
*/
function mediashareStripKeywords($keywords)
{
return preg_replace('/[^\w ]/i', '', $keywords);
}
function mediashareEnsureFolderExists($parentFolderID, $folders, $folderOffset)
{
$dom = ZLanguage::getModuleDomain('mediashare');
// End of recursion?
if ($folderOffset == sizeof($folders) - 1) {
return $parentFolderID;
}
$folderTitle = $folders[$folderOffset];
// Get ID of existing folder
$pntable = pnDBGetTables();
$foldersTable = $pntable['mediashare_albums'];
$foldersColumn = $pntable['mediashare_albums_column'];
$sql = "SELECT $foldersColumn[id]
FROM $foldersTable
WHERE $foldersColumn[parentAlbumId] = '" . DataUtil::formatForStore($parentFolderID) . "'
AND $foldersColumn[title] = '" . DataUtil::formatForStore($folderTitle) . "'";
$result = DBUtil::executeSQL($sql);
if ($result === false) {
return LogUtil::registerError(__f('Error in %1$s: %2$s.', array('common.EnsureFolderExists', 'Could not retrieve the folder information.'), $dom), 404);
}
// No ID => folder does not exist. Create it.
if (!$result) {
if (!($folderID = pnModAPIFunc('mediashare', 'edit', 'addAlbum', array('parentAlbumId' => $parentFolderID, 'title' => $folderTitle, 'description' => '', 'keywords' => '', 'summary' => '')))) {
return false;
}
} else {
$folderID = DBUtil::marshallObjects($result, array('id'));
$folderID = (int)$folderID[0]['id'];
}
// Recursive to ensure sub-folders exists
return mediashareEnsureFolderExists($folderID, $folders, $folderOffset + 1);
}
// Convert media item reference to name of virtual file system manager
function mediashareGetVFSHandlerName($fileref)
{
if (substr($fileref, 0, 6) == 'vfsdb/') {
return 'db'; // Stored in database
} else {
return 'fsdirect'; // Stored in local file system
}
}