2016-09-01 23:13:23 +02:00
|
|
|
<?php
|
|
|
|
/*****************************************************************************
|
|
|
|
* UploadMedia.php
|
|
|
|
* Contains the media uploading controller
|
|
|
|
*
|
|
|
|
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
class UploadMedia extends HTMLController
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
// Ensure it's just admins at this point.
|
|
|
|
if (!Registry::get('user')->isAdmin())
|
|
|
|
throw new NotAllowedException();
|
|
|
|
|
2016-09-04 14:15:38 +02:00
|
|
|
if (!isset($_REQUEST['tag']))
|
|
|
|
throw new UserFacingException('No album tag provided.');
|
|
|
|
|
|
|
|
$tag = Tag::fromId($_REQUEST['tag']);
|
|
|
|
|
|
|
|
$page = new MediaUploader($tag);
|
|
|
|
parent::__construct('Upload new photos - ' . SITE_TITLE);
|
2016-09-01 23:13:23 +02:00
|
|
|
$this->page->adopt($page);
|
|
|
|
|
|
|
|
// Are we saving something?
|
2016-09-04 14:15:38 +02:00
|
|
|
if (!empty($_FILES['uploads']))
|
2016-09-01 23:13:23 +02:00
|
|
|
{
|
2016-09-04 14:15:38 +02:00
|
|
|
$files = isset($_FILES['uploads'][0]) ? $_FILES['uploads'] : [$_FILES['uploads']];
|
|
|
|
$new_ids = [];
|
|
|
|
foreach ($files as $num => $uploaded_file)
|
2016-09-01 23:13:23 +02:00
|
|
|
{
|
|
|
|
if (empty($uploaded_file))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
$asset = Asset::createNew([
|
2016-09-04 14:15:38 +02:00
|
|
|
'filename_to_copy' => $uploaded_file['tmp_name'],
|
|
|
|
'preferred_filename' => $uploaded_file['name'],
|
2016-09-04 15:18:30 +02:00
|
|
|
'preferred_subdir' => $tag->slug,
|
2016-09-01 23:13:23 +02:00
|
|
|
]);
|
|
|
|
|
2016-09-04 14:15:38 +02:00
|
|
|
$new_ids[] = $asset->getId();
|
|
|
|
$asset->linkTags([$tag->id_tag]);
|
2016-09-04 14:55:23 +02:00
|
|
|
|
|
|
|
$tag->id_asset_thumb = $asset->getId();
|
|
|
|
$tag->save();
|
2016-09-01 23:13:23 +02:00
|
|
|
}
|
|
|
|
|
2016-09-04 14:15:38 +02:00
|
|
|
if (isset($_REQUEST['format']) && $_REQUEST['format'] === 'json')
|
|
|
|
{
|
|
|
|
echo json_encode(['success' => true, 'new_ids' => $new_ids]);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
header('Location: ' . BASEURL . '/uploadmedia/');
|
|
|
|
exit;
|
|
|
|
}
|
2016-09-01 23:13:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|