68 lines
1.7 KiB
PHP
68 lines
1.7 KiB
PHP
<?php
|
|
/**
|
|
* Simple Machines Forum (SMF)
|
|
*
|
|
* @package SMF
|
|
* @author viviridian
|
|
* @copyright 2020 viviridian
|
|
* @license http://www.simplemachines.org/about/smf/license.php BSD
|
|
*
|
|
* @version 2.0.16
|
|
*/
|
|
|
|
if (!defined('SMF'))
|
|
die('Hacking attempt...');
|
|
|
|
/* Adds a simple api allowing users to post attachments programmatically.
|
|
I'm using this to enable pasting images into posts.
|
|
*/
|
|
|
|
function UploadAttachment()
|
|
{
|
|
global $modSettings, $user_info, $sourcedir;
|
|
|
|
if (!allowedTo('post_attachment') && !allowedTo('post_unapproved_attachments')){
|
|
die(json_encode(array(
|
|
'ok' => false,
|
|
'errors' => array("not allowed")
|
|
)));
|
|
}
|
|
|
|
require_once($sourcedir . '/Subs-Post.php');
|
|
|
|
foreach ($_FILES['attachment']['tmp_name'] as $n => $dummy)
|
|
{
|
|
if ($_FILES['attachment']['name'][$n] == '')
|
|
continue;
|
|
|
|
$attachmentOptions = array(
|
|
'post' => 0,
|
|
'poster' => $user_info['id'],
|
|
'name' => $_FILES['attachment']['name'][$n],
|
|
'tmp_name' => $_FILES['attachment']['tmp_name'][$n],
|
|
'size' => $_FILES['attachment']['size'][$n],
|
|
'approved' => !$modSettings['postmod_active'] || allowedTo('post_attachment'),
|
|
'attachment_type' => 4, // to denote inline-uploaded attachments.
|
|
'skip_thumbnail' => true,
|
|
);
|
|
|
|
if (createAttachment($attachmentOptions))
|
|
{
|
|
// build insertion text for the newly uploaded attachment
|
|
$insert_text = "[img]/index.php?action=dlattach;attach=" . $attachmentOptions['id'] . ";type=inline;hash=" . $attachmentOptions['file_hash'] . "[/img]";
|
|
die(json_encode(array(
|
|
'ok' => true,
|
|
'insert_text' => $insert_text
|
|
)));
|
|
}
|
|
else
|
|
{
|
|
die(json_encode(array(
|
|
'ok' => false,
|
|
'error' => $attachmentOptions['errors'][0]
|
|
)));
|
|
}
|
|
}
|
|
}
|
|
?>
|