This repository was archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpnsource_browser.php
More file actions
165 lines (130 loc) · 5.44 KB
/
pnsource_browser.php
File metadata and controls
165 lines (130 loc) · 5.44 KB
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
<?php
// $Id$
//
// Mediashare by Jorn Lind-Nielsen (C)
//
require_once 'modules/mediashare/common-edit.php';
require_once 'modules/mediashare/pnincludes/elfisk_common.php';
function mediashare_source_browser_view(&$args)
{
$albumId = mediashareGetIntUrl('aid', $args, 0);
if (isset($_POST['saveButton'])) {
return mediashareSourceBrowserUpload($args);
}
if (isset($_POST['moreButton']) || isset($_POST['continueButton'])) {
// After upload - update items and then continue to next page
if (!mediashareSourceBrowserUpdate()) {
return false;
}
}
if (isset($_POST['cancelButton']) || isset($_POST['continueButton'])) {
return pnRedirect(pnModURL('mediashare', 'edit', 'view', array('aid' => $albumId)));
}
if (isset($_POST['moreButton'])) {
return pnRedirect(pnModURL('mediashare', 'edit', 'addmedia', array('aid' => $albumId, 'source' => 'browser')));
}
// FIXME Required for globals??
// pnModAPILoad('mediashare', 'edit');
$uploadInfo = pnModAPIFunc('mediashare', 'source_browser', 'getUploadInfo');
$render = & pnRender::getInstance('mediashare', false);
$render->assign('imageNum', 10);
$render->assign('uploadFields', array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
$render->assign('post_max_size', $uploadInfo['post_max_size']);
$render->assign('upload_max_filesize', $uploadInfo['upload_max_filesize']);
return $render->fetch('mediashare_source_browser_view.html');
}
function mediashareSourceBrowserUpload(&$args)
{
if (!SecurityUtil::confirmAuthKey()) {
return LogUtil::registerAuthidError();
}
$dom = ZLanguage::getModuleDomain('mediashare');
$albumId = mediashareGetIntUrl('aid', $args, 0);
// Check access
if (!mediashareAccessAlbum($albumId, mediashareAccessRequirementAddMedia, '')) {
return LogUtil::registerPermissionError();
}
// Get parent album information
if (!($album = pnModAPIFunc('mediashare', 'user', 'getAlbum', array('albumId' => $albumId)))) {
return false;
}
// Start fetching media items
$imageNum = (int)FormUtil::getPassedValue('imagenum');
$statusSet = array();
for ($i = 1; $i <= $imageNum; ++$i)
{
$uploadInfo = $_FILES["upload$i"];
$width = FormUtil::getPassedValue("width$i");
$height = FormUtil::getPassedValue("height$i");
if (isset($uploadInfo['error']) && $uploadInfo['error'] != 0 && $uploadInfo['name'] != '') {
$statusSet[] = array('ok' => false, 'message' => $uploadInfo['name'] . ': ' . mediashareUploadErrorMsg($uploadInfo['error']));
} else if ($uploadInfo['size'] > 0) {
$result = pnModAPIFunc('mediashare', 'source_browser', 'addMediaItem', array(
'albumId' => $albumId,
'uploadFilename' => $uploadInfo['tmp_name'],
'fileSize' => $uploadInfo['size'],
'filename' => $uploadInfo['name'],
'mimeType' => $uploadInfo['type'],
'title' => null,
'keywords' => null,
'description' => null,
'width' => $width,
'height' => $height));
if ($result === false) {
$status = array('ok' => false, 'message' => LogUtil::getErrorMessagesText());
} else {
$status = array('ok' => true, 'message' => $result['message'], 'mediaId' => $result['mediaId']);
}
$statusSet = array_merge($statusSet, array($status));
}
}
// Quick count of uploaded images + getting IDs for further editing
$editMediaIds = array();
$acceptedImageNum = 0;
foreach ($statusSet as $status)
{
if ($status['ok']) {
++$acceptedImageNum;
$editMediaIds[] = $status['mediaId'];
}
}
$album['imageCount'] += $acceptedImageNum; // Update for showing only
if ($acceptedImageNum == 0) {
$statusSet[] = array('ok' => false, 'message' => __('No media items', $dom));
}
if (($items = pnModAPIFunc('mediashare', 'user', 'getMediaItems', array('mediaIdList' => $editMediaIds))) === false) {
return false;
}
$render = & pnRender::getInstance('mediashare', false);
$render->assign('statusSet', $statusSet);
$render->assign('items', $items);
return $render->fetch('mediashare_source_browser_uploadet.html');
}
// Second page in upload sequence
// user has entered media titles and such like, and it needs to be updated
function mediashareSourceBrowserUpdate()
{
if (!SecurityUtil::confirmAuthKey()) {
return LogUtil::registerAuthidError();
}
$mediaIds = FormUtil::getPassedValue('mediaId');
foreach ($mediaIds as $mediaId)
{
$mediaId = (int)$mediaId;
$title = FormUtil::getPassedValue("title-$mediaId");
$keywords = FormUtil::getPassedValue("keywords-$mediaId");
$description = FormUtil::getPassedValue("description-$mediaId");
// Check access
if (!mediashareAccessItem($mediaId, mediashareAccessRequirementEditMedia, '')) {
return LogUtil::registerPermissionError();
}
$args = array('mediaId' => $mediaId,
'title' => $title,
'keywords' => $keywords,
'description' => $description);
if (!pnModAPIFunc('mediashare', 'edit', 'updateItem', $args)) {
return false;
}
}
return true;
}