Skip to content

Commit 57ac1d6

Browse files
committed
update for 2.7
1 parent 5b89a17 commit 57ac1d6

7 files changed

Lines changed: 201 additions & 360 deletions

File tree

admin.php

Lines changed: 0 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
1515
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
1616

17-
$allowed_extensions = array('jpg','jpeg','png','gif');
18-
$allowed_mimes = array('image/jpeg', 'image/png', 'image/gif');
19-
2017
$tabsheet = new tabsheet();
2118
$tabsheet->set_id('photos_add');
2219
$tabsheet->select('url_uploader');
@@ -25,180 +22,11 @@
2522
$page['active_menu'] = get_active_menu('photo');
2623

2724

28-
// +-----------------------------------------------------------------------+
29-
// | process form |
30-
// +-----------------------------------------------------------------------+
31-
if (isset($_GET['processed']))
32-
{
33-
$category_id = $_POST['category'];
34-
$image_ids = array();
35-
$page['thumbnails'] = array();
36-
37-
// SINGLE UPLOAD
38-
if ($_GET['upload_mode'] == 'single')
39-
{
40-
$_POST = array_map('trim', $_POST);
41-
42-
// check empty url
43-
if (empty($_POST['file_url']))
44-
{
45-
$page['errors'][] = l10n('File URL is empty');
46-
}
47-
// check remote url
48-
else if (!url_is_remote($_POST['file_url']))
49-
{
50-
$page['errors'][] = l10n('Invalid file URL');
51-
}
52-
// check file extension
53-
else if (!in_array(strtolower(get_extension($_POST['file_url'])), $allowed_extensions))
54-
{
55-
$page['errors'][] = l10n('Invalid file type');
56-
}
57-
// continue...
58-
else
59-
{
60-
$temp_filename = $conf['data_location'].basename($_POST['file_url']);
61-
$file = fopen($temp_filename, 'w+');
62-
$result = fetchRemote($_POST['file_url'], $file);
63-
fclose($file);
64-
65-
// download failed ?
66-
if (!$result)
67-
{
68-
@unlink($temp_filename);
69-
$page['errors'][] = l10n('Unable to download file');
70-
}
71-
// check mime-type
72-
else if (!in_array(get_mime($temp_filename, $allowed_mimes[0]), $allowed_mimes))
73-
{
74-
@unlink($temp_filename);
75-
$page['errors'][] = l10n('Invalid file type');
76-
}
77-
// continue...
78-
else
79-
{
80-
$image_id = add_uploaded_file(
81-
$temp_filename,
82-
basename($temp_filename),
83-
array($category_id),
84-
$_POST['level']
85-
);
86-
87-
$updates = array();
88-
if (!empty($_POST['photo_name']))
89-
{
90-
$updates['name'] = $_POST['photo_name'];
91-
}
92-
if (isset($_POST['url_in_comment']))
93-
{
94-
$url = parse_url($_POST['file_url']);
95-
$url = $url['scheme'].'://'.$url['host'];
96-
$updates['comment'] = '<a href="'. $url . '">'. $url .'</a>';
97-
}
98-
99-
single_update(
100-
IMAGES_TABLE,
101-
$updates,
102-
array('id' => $image_id)
103-
);
104-
105-
$image_ids = array($image_id);
106-
}
107-
}
108-
}
109-
// MULTIPLE UPLOAD
110-
else if ($_GET['upload_mode'] == 'multiple')
111-
{
112-
if (isset($_POST['onUploadError']) and is_array($_POST['onUploadError']) and count($_POST['onUploadError']) > 0)
113-
{
114-
$page['errors'][] = l10n('%d photos not imported', count($_POST['onUploadError']));
115-
foreach ($_POST['onUploadError'] as $error)
116-
{
117-
$page['errors'][] = $error;
118-
}
119-
}
120-
121-
if (isset($_POST['imageIds']) and is_array($_POST['imageIds']) and count($_POST['imageIds']) > 0)
122-
{
123-
$image_ids = $_POST['imageIds'];
124-
}
125-
}
126-
127-
// DISPLAY RESULTS
128-
foreach ($image_ids as $image_id)
129-
{
130-
$query = '
131-
SELECT id, file, path
132-
FROM '.IMAGES_TABLE.'
133-
WHERE id = '.$image_id.'
134-
;';
135-
$image_infos = pwg_db_fetch_assoc(pwg_query($query));
136-
137-
$thumbnail = array(
138-
'file' => $image_infos['file'],
139-
'src' => DerivativeImage::thumb_url($image_infos),
140-
'title' => get_name_from_file($image_infos['file']),
141-
'link' => get_root_url().'admin.php?page=photo-'.$image_id.'&amp;cat_id='.$category_id,
142-
);
143-
144-
$page['thumbnails'][] = $thumbnail;
145-
}
146-
147-
if (!empty($page['thumbnails']))
148-
{
149-
// nb uploaded
150-
$page['infos'][] = l10n('%d photos uploaded', count($page['thumbnails']));
151-
152-
// level
153-
if (0 != $_POST['level'])
154-
{
155-
$page['infos'][] = l10n('Privacy level set to "%s"', l10n(sprintf('Level %d', $_POST['level'])));
156-
}
157-
158-
// new category count
159-
$query = '
160-
SELECT COUNT(*)
161-
FROM '.IMAGE_CATEGORY_TABLE.'
162-
WHERE category_id = '.$category_id.'
163-
;';
164-
list($count) = pwg_db_fetch_row(pwg_query($query));
165-
$category_name = get_cat_display_name_from_id($category_id, 'admin.php?page=album-');
166-
167-
$page['infos'][] = l10n('Album "%s" now contains %d photos', '<em>'.$category_name.'</em>', $count);
168-
169-
$page['batch_link'] = PHOTOS_ADD_BASE_URL.'&batch='.implode(',', $image_ids);
170-
}
171-
}
172-
173-
17425
// +-----------------------------------------------------------------------+
17526
// | prepare form |
17627
// +-----------------------------------------------------------------------+
17728
include(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_prepare.inc.php');
17829

179-
// upload mode
180-
$upload_modes = array('single', 'multiple');
181-
$upload_mode = isset($conf['url_uploader_mode']) ? $conf['url_uploader_mode'] : 'single';
182-
183-
if (isset($_GET['upload_mode']) and $_GET['upload_mode']!=$upload_mode and in_array($_GET['upload_mode'], $upload_modes))
184-
{
185-
$upload_mode = $_GET['upload_mode'];
186-
conf_update_param('url_uploader_mode', $upload_mode);
187-
}
188-
189-
// what is the upload switch mode
190-
$index_of_upload_mode = array_flip($upload_modes);
191-
$upload_mode_index = $index_of_upload_mode[$upload_mode];
192-
$upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ];
193-
194-
$template->assign(array(
195-
'upload_mode' => $upload_mode,
196-
'form_action' => URLUPLOADER_ADMIN.'&amp;upload_mode='.$upload_mode.'&amp;processed=1',
197-
'switch_url' => URLUPLOADER_ADMIN.'&amp;upload_mode='.$upload_switch,
198-
'another_upload_link' => URLUPLOADER_ADMIN.'&amp;upload_mode='.$upload_mode,
199-
));
200-
201-
20230
$template->set_filename('urluploader_content', realpath(URLUPLOADER_PATH . 'template/photos_add.tpl'));
20331

20432
// template vars

include/functions.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function urluploader_tabsheet_before_select($sheets, $id)
1212
$sheets =
1313
array_slice($sheets, 0, 1) +
1414
array('url_uploader' => array(
15-
'caption' => '<span class="icon-link"></span>' . l10n('URL Uploader'),
15+
'caption' => '<span class="icon-link"></span>URL Uploader',
1616
'url' => URLUPLOADER_ADMIN,
1717
)) +
1818
array_slice($sheets, 1);

include/ws_functions.inc.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,31 @@ function ws_images_addRemote($params, &$service)
122122
);
123123

124124
$query = '
125-
SELECT id, path
125+
SELECT id, path, name
126126
FROM '.IMAGES_TABLE.'
127127
WHERE id = '.$image_id.'
128128
;';
129129
$image_infos = pwg_db_fetch_assoc(pwg_query($query));
130+
131+
$query = '
132+
SELECT
133+
COUNT(*) AS nb_photos
134+
FROM '.IMAGE_CATEGORY_TABLE.'
135+
WHERE category_id = '.$params['category'].'
136+
;';
137+
$category_infos = pwg_db_fetch_assoc(pwg_query($query));
138+
139+
$category_name = get_cat_display_name_from_id($params['category'], null);
130140

131141
return array(
132142
'image_id' => $image_id,
133143
'url' => make_picture_url($url_params),
134-
'thumbnail_url' => preg_replace('#^'.PHPWG_ROOT_PATH.'#', './', DerivativeImage::thumb_url($image_infos)),
144+
'src' => DerivativeImage::thumb_url($image_infos),
145+
'name' => $image_infos['name'],
146+
'category' => array(
147+
'id' => $params['category'],
148+
'nb_photos' => $category_infos['nb_photos'],
149+
'label' => $category_name,
150+
),
135151
);
136152
}

language/en_UK/plugin.lang.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
$lang['Pending'] = 'Pending';
88
$lang['Delete this item'] = 'Delete this item';
99
$lang['File URL'] = 'File URL';
10-
$lang['Want to upload many files? Try the <a href="%s">multiple uploader</a> instead.'] = 'Want to upload many files? Try the <a href="%s">multiple uploader</a> instead.';
11-
$lang['Multiple uploader doesn\'t work? Try the <a href="%s">single uploader</a> instead.'] = 'Multiple uploader doesn\'t work? Try the <a href="%s">single uploader</a> instead.';
1210
$lang['One link by line, separate photo name and url with a &laquo; | &raquo;. Photo name is optional.'] = 'One link by line, separate photo name and url with a &laquo; | &raquo;. Photo name is optional.';
1311
$lang['Add links'] = 'Add links';
1412
$lang['Add website URL in photo description'] = 'Add website URL in photo description';

language/fr_FR/plugin.lang.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
$lang['Pending'] = 'En attente';
88
$lang['Delete this item'] = 'Supprimer ce lien';
99
$lang['File URL'] = 'URL du fichier';
10-
$lang['Want to upload many files? Try the <a href="%s">multiple uploader</a> instead.'] = 'Vous voulez télécharger plus de fichiers ? Essayez le <a href="%s">formulaire multiple</a>.';
11-
$lang['Multiple uploader doesn\'t work? Try the <a href="%s">single uploader</a> instead.'] = 'Le formulaire multiple ne fonctionne pas ? Essayez le <a href="%s">formulaire simple</a>.';
1210
$lang['One link by line, separate photo name and url with a &laquo; | &raquo;. Photo name is optional.'] = 'Un seul lien par ligne, séparez le nom et l\'URL par un &laquo; | &raquo;. Le nom de la photo est optionel.';
1311
$lang['Add links'] = 'Ajouter les liens';
1412
$lang['Add website URL in photo description'] = 'Ajouter l\'URL du site web dans la description de la photo';

0 commit comments

Comments
 (0)