-
Notifications
You must be signed in to change notification settings - Fork 4
/
arts.php
173 lines (150 loc) · 6.27 KB
/
arts.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
<?php
/* vim:set softtabstop=4 shiftwidth=4 expandtab: */
/**
*
* LICENSE: GNU Affero General Public License, version 3 (AGPLv3)
* Copyright 2001 - 2015 Ampache.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
require_once 'lib/init.php';
require_once AmpConfig::get('prefix') . UI::find_template('header.inc.php');
$object_type = $_GET['object_type'];
$object_id = $_GET['object_id'];
if (!Core::is_library_item($object_type)) {
UI::access_denied();
exit;
}
$burl = '';
if (isset($_GET['burl'])) {
$burl = base64_decode($_GET['burl']);
}
$item = new $object_type($object_id);
// If not a content manager user then kick em out
if (!Access::check('interface', 50) && (!Access::check('interface', 25) || $item->get_user_owner() != $GLOBALS['user']->id)) {
UI::access_denied();
exit;
}
/* Switch on Action */
switch ($_REQUEST['action']) {
case 'clear_art':
$art = new Art($object_id, $object_type);
$art->reset();
show_confirmation(T_('Art Cleared'), T_('Art information has been removed from the database'), $burl);
break;
// Upload art
case 'upload_art':
// we didn't find anything
if (empty($_FILES['file']['tmp_name'])) {
show_confirmation(T_('Art Not Located'), T_('Art could not be located at this time. This may be due to write access error, or the file is not received correctly.'), $burl);
break;
}
// Pull the image information
$data = array('file'=>$_FILES['file']['tmp_name']);
$image_data = Art::get_from_source($data, $object_type);
// If we got something back insert it
if ($image_data) {
$art = new Art($object_id, $object_type);
$art->insert($image_data,$_FILES['file']['type']);
show_confirmation(T_('Art Inserted'), '', $burl);
}
// Else it failed
else {
show_confirmation(T_('Art Not Located'), T_('Art could not be located at this time. This may be due to write access error, or the file is not received correctly.'), $burl);
}
break;
case 'find_art':
// Prevent the script from timing out
set_time_limit(0);
$item->format();
$art = new Art($object_id, $object_type);
$images = array();
$cover_url = array();
// If we've got an upload ignore the rest and just insert it
if (!empty($_FILES['file']['tmp_name'])) {
$path_info = pathinfo($_FILES['file']['name']);
$upload['file'] = $_FILES['file']['tmp_name'];
$upload['mime'] = 'image/' . $path_info['extension'];
$image_data = Art::get_from_source($upload, $object_type);
if ($image_data) {
$art->insert($image_data,$upload['0']['mime']);
show_confirmation(T_('Art Inserted'), '', $burl);
break;
} // if image data
} // if it's an upload
$keywords = $item->get_keywords();
$keyword = '';
$options = array();
foreach ($keywords as $key => $word) {
if (isset($_REQUEST['option_' . $key])) {
$word['value'] = $_REQUEST['option_' . $key];
}
$options[$key] = $word['value'];
if ($word['important']) {
if (!empty($word['value'])) {
$keyword .= ' ' . $word['value'];
}
}
}
$options['keyword'] = trim($keyword);
// Attempt to find the art.
$images = $art->gather($options);
if (!empty($_REQUEST['cover'])) {
$path_info = pathinfo($_REQUEST['cover']);
$cover_url[0]['url'] = scrub_in($_REQUEST['cover']);
$cover_url[0]['mime'] = 'image/' . $path_info['extension'];
}
$images = array_merge($cover_url, $images);
// If we've found anything then go for it!
if (count($images)) {
// We don't want to store raw's in here so we need to strip them out into a separate array
foreach ($images as $index=>$image) {
if ($image['raw']) {
unset($images[$index]['raw']);
}
} // end foreach
// Store the results for further use
$_SESSION['form']['images'] = $images;
require_once AmpConfig::get('prefix') . UI::find_template('show_arts.inc.php');
}
// Else nothing
else {
show_confirmation(T_('Art Not Located'), T_('Art could not be located at this time. This may be due to write access error, or the file is not received correctly.'), $burl);
}
require_once AmpConfig::get('prefix') . UI::find_template('show_get_art.inc.php');
break;
case 'select_art':
/* Check to see if we have the image url still */
$image_id = $_REQUEST['image'];
// Prevent the script from timing out
set_time_limit(0);
$image = Art::get_from_source($_SESSION['form']['images'][$image_id], 'album');
$mime = $_SESSION['form']['images'][$image_id]['mime'];
// Special case for albums, I'm not sure if we should keep it, remove it or find a generic way
if ($object_type == 'album') {
$album = new $object_type($object_id);
$album_groups = $album->get_group_disks_ids();
foreach ($album_groups as $a_id) {
$art = new Art($a_id, $object_type);
$art->insert($image, $mime);
}
} else {
$art = new Art($object_id, $object_type);
$art->insert($image, $mime);
}
header("Location:" . $burl);
break;
}
UI::show_footer();