Skip to content

Commit

Permalink
update for 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Dec 15, 2014
1 parent 5b89a17 commit 57ac1d6
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 360 deletions.
172 changes: 0 additions & 172 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');

$allowed_extensions = array('jpg','jpeg','png','gif');
$allowed_mimes = array('image/jpeg', 'image/png', 'image/gif');

$tabsheet = new tabsheet();
$tabsheet->set_id('photos_add');
$tabsheet->select('url_uploader');
Expand All @@ -25,180 +22,11 @@
$page['active_menu'] = get_active_menu('photo');


// +-----------------------------------------------------------------------+
// | process form |
// +-----------------------------------------------------------------------+
if (isset($_GET['processed']))
{
$category_id = $_POST['category'];
$image_ids = array();
$page['thumbnails'] = array();

// SINGLE UPLOAD
if ($_GET['upload_mode'] == 'single')
{
$_POST = array_map('trim', $_POST);

// check empty url
if (empty($_POST['file_url']))
{
$page['errors'][] = l10n('File URL is empty');
}
// check remote url
else if (!url_is_remote($_POST['file_url']))
{
$page['errors'][] = l10n('Invalid file URL');
}
// check file extension
else if (!in_array(strtolower(get_extension($_POST['file_url'])), $allowed_extensions))
{
$page['errors'][] = l10n('Invalid file type');
}
// continue...
else
{
$temp_filename = $conf['data_location'].basename($_POST['file_url']);
$file = fopen($temp_filename, 'w+');
$result = fetchRemote($_POST['file_url'], $file);
fclose($file);

// download failed ?
if (!$result)
{
@unlink($temp_filename);
$page['errors'][] = l10n('Unable to download file');
}
// check mime-type
else if (!in_array(get_mime($temp_filename, $allowed_mimes[0]), $allowed_mimes))
{
@unlink($temp_filename);
$page['errors'][] = l10n('Invalid file type');
}
// continue...
else
{
$image_id = add_uploaded_file(
$temp_filename,
basename($temp_filename),
array($category_id),
$_POST['level']
);

$updates = array();
if (!empty($_POST['photo_name']))
{
$updates['name'] = $_POST['photo_name'];
}
if (isset($_POST['url_in_comment']))
{
$url = parse_url($_POST['file_url']);
$url = $url['scheme'].'://'.$url['host'];
$updates['comment'] = '<a href="'. $url . '">'. $url .'</a>';
}

single_update(
IMAGES_TABLE,
$updates,
array('id' => $image_id)
);

$image_ids = array($image_id);
}
}
}
// MULTIPLE UPLOAD
else if ($_GET['upload_mode'] == 'multiple')
{
if (isset($_POST['onUploadError']) and is_array($_POST['onUploadError']) and count($_POST['onUploadError']) > 0)
{
$page['errors'][] = l10n('%d photos not imported', count($_POST['onUploadError']));
foreach ($_POST['onUploadError'] as $error)
{
$page['errors'][] = $error;
}
}

if (isset($_POST['imageIds']) and is_array($_POST['imageIds']) and count($_POST['imageIds']) > 0)
{
$image_ids = $_POST['imageIds'];
}
}

// DISPLAY RESULTS
foreach ($image_ids as $image_id)
{
$query = '
SELECT id, file, path
FROM '.IMAGES_TABLE.'
WHERE id = '.$image_id.'
;';
$image_infos = pwg_db_fetch_assoc(pwg_query($query));

$thumbnail = array(
'file' => $image_infos['file'],
'src' => DerivativeImage::thumb_url($image_infos),
'title' => get_name_from_file($image_infos['file']),
'link' => get_root_url().'admin.php?page=photo-'.$image_id.'&amp;cat_id='.$category_id,
);

$page['thumbnails'][] = $thumbnail;
}

if (!empty($page['thumbnails']))
{
// nb uploaded
$page['infos'][] = l10n('%d photos uploaded', count($page['thumbnails']));

// level
if (0 != $_POST['level'])
{
$page['infos'][] = l10n('Privacy level set to "%s"', l10n(sprintf('Level %d', $_POST['level'])));
}

// new category count
$query = '
SELECT COUNT(*)
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$category_id.'
;';
list($count) = pwg_db_fetch_row(pwg_query($query));
$category_name = get_cat_display_name_from_id($category_id, 'admin.php?page=album-');

$page['infos'][] = l10n('Album "%s" now contains %d photos', '<em>'.$category_name.'</em>', $count);

$page['batch_link'] = PHOTOS_ADD_BASE_URL.'&batch='.implode(',', $image_ids);
}
}


// +-----------------------------------------------------------------------+
// | prepare form |
// +-----------------------------------------------------------------------+
include(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_prepare.inc.php');

// upload mode
$upload_modes = array('single', 'multiple');
$upload_mode = isset($conf['url_uploader_mode']) ? $conf['url_uploader_mode'] : 'single';

if (isset($_GET['upload_mode']) and $_GET['upload_mode']!=$upload_mode and in_array($_GET['upload_mode'], $upload_modes))
{
$upload_mode = $_GET['upload_mode'];
conf_update_param('url_uploader_mode', $upload_mode);
}

// what is the upload switch mode
$index_of_upload_mode = array_flip($upload_modes);
$upload_mode_index = $index_of_upload_mode[$upload_mode];
$upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ];

$template->assign(array(
'upload_mode' => $upload_mode,
'form_action' => URLUPLOADER_ADMIN.'&amp;upload_mode='.$upload_mode.'&amp;processed=1',
'switch_url' => URLUPLOADER_ADMIN.'&amp;upload_mode='.$upload_switch,
'another_upload_link' => URLUPLOADER_ADMIN.'&amp;upload_mode='.$upload_mode,
));


$template->set_filename('urluploader_content', realpath(URLUPLOADER_PATH . 'template/photos_add.tpl'));

// template vars
Expand Down
2 changes: 1 addition & 1 deletion include/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function urluploader_tabsheet_before_select($sheets, $id)
$sheets =
array_slice($sheets, 0, 1) +
array('url_uploader' => array(
'caption' => '<span class="icon-link"></span>' . l10n('URL Uploader'),
'caption' => '<span class="icon-link"></span>URL Uploader',
'url' => URLUPLOADER_ADMIN,
)) +
array_slice($sheets, 1);
Expand Down
20 changes: 18 additions & 2 deletions include/ws_functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,31 @@ function ws_images_addRemote($params, &$service)
);

$query = '
SELECT id, path
SELECT id, path, name
FROM '.IMAGES_TABLE.'
WHERE id = '.$image_id.'
;';
$image_infos = pwg_db_fetch_assoc(pwg_query($query));

$query = '
SELECT
COUNT(*) AS nb_photos
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE category_id = '.$params['category'].'
;';
$category_infos = pwg_db_fetch_assoc(pwg_query($query));

$category_name = get_cat_display_name_from_id($params['category'], null);

return array(
'image_id' => $image_id,
'url' => make_picture_url($url_params),
'thumbnail_url' => preg_replace('#^'.PHPWG_ROOT_PATH.'#', './', DerivativeImage::thumb_url($image_infos)),
'src' => DerivativeImage::thumb_url($image_infos),
'name' => $image_infos['name'],
'category' => array(
'id' => $params['category'],
'nb_photos' => $category_infos['nb_photos'],
'label' => $category_name,
),
);
}
2 changes: 0 additions & 2 deletions language/en_UK/plugin.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
$lang['Pending'] = 'Pending';
$lang['Delete this item'] = 'Delete this item';
$lang['File URL'] = 'File URL';
$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.';
$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.';
$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.';
$lang['Add links'] = 'Add links';
$lang['Add website URL in photo description'] = 'Add website URL in photo description';
Expand Down
2 changes: 0 additions & 2 deletions language/fr_FR/plugin.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
$lang['Pending'] = 'En attente';
$lang['Delete this item'] = 'Supprimer ce lien';
$lang['File URL'] = 'URL du fichier';
$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>.';
$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>.';
$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.';
$lang['Add links'] = 'Ajouter les liens';
$lang['Add website URL in photo description'] = 'Ajouter l\'URL du site web dans la description de la photo';
Expand Down
Loading

0 comments on commit 57ac1d6

Please sign in to comment.