mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-06 08:47:45 +02:00
[feature/plupload/integration] Integration of Plupload
This commit is a highly-refactored and up-to-date version of Fyorl's work which was part of his Google Summer of Code 2012 project "Attachment Improvements". PHPBB3-10929
This commit is contained in:
@@ -385,8 +385,18 @@ function posting_gen_topic_types($forum_id, $cur_topic_type = POST_NORMAL)
|
||||
/**
|
||||
* Upload Attachment - filedata is generated here
|
||||
* Uses upload class
|
||||
*
|
||||
* @param string $form_name The form name of the file upload input
|
||||
* @param int $forum_id The id of the forum
|
||||
* @param bool $local Whether the file is local or not
|
||||
* @param string $local_storage The path to the local file
|
||||
* @param bool $is_message Whether it is a PM or not
|
||||
* @param \filespec $local_filedata A filespec object created for the local file
|
||||
* @param \phpbb\plupload\plupload $plupload The plupload object if one is being used
|
||||
*
|
||||
* @return object filespec
|
||||
*/
|
||||
function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false)
|
||||
function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false, \phpbb\plupload\plupload $plupload = null)
|
||||
{
|
||||
global $auth, $user, $config, $db, $cache;
|
||||
global $phpbb_root_path, $phpEx;
|
||||
@@ -414,7 +424,7 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage
|
||||
$extensions = $cache->obtain_attach_extensions((($is_message) ? false : (int) $forum_id));
|
||||
$upload->set_allowed_extensions(array_keys($extensions['_allowed_']));
|
||||
|
||||
$file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : $upload->form_upload($form_name);
|
||||
$file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : $upload->form_upload($form_name, $plupload);
|
||||
|
||||
if ($file->init_error)
|
||||
{
|
||||
@@ -469,6 +479,11 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage
|
||||
{
|
||||
$file->remove();
|
||||
|
||||
if ($plupload && $plupload->is_active())
|
||||
{
|
||||
$plupload->emit_error(104, 'ATTACHED_IMAGE_NOT_IMAGE');
|
||||
}
|
||||
|
||||
// If this error occurs a user tried to exploit an IE Bug by renaming extensions
|
||||
// Since the image category is displaying content inline we need to catch this.
|
||||
trigger_error($user->lang['ATTACHED_IMAGE_NOT_IMAGE']);
|
||||
|
@@ -43,11 +43,17 @@ class filespec
|
||||
|
||||
var $upload = '';
|
||||
|
||||
/**
|
||||
* The plupload object
|
||||
* @var \phpbb\plupload\plupload
|
||||
*/
|
||||
protected $plupload;
|
||||
|
||||
/**
|
||||
* File Class
|
||||
* @access private
|
||||
*/
|
||||
function filespec($upload_ary, $upload_namespace)
|
||||
function filespec($upload_ary, $upload_namespace, \phpbb\plupload\plupload $plupload = null)
|
||||
{
|
||||
if (!isset($upload_ary))
|
||||
{
|
||||
@@ -80,6 +86,7 @@ class filespec
|
||||
|
||||
$this->local = (isset($upload_ary['local_mode'])) ? true : false;
|
||||
$this->upload = $upload_namespace;
|
||||
$this->plupload = $plupload;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,12 +168,14 @@ class filespec
|
||||
*/
|
||||
function is_uploaded()
|
||||
{
|
||||
if (!$this->local && !is_uploaded_file($this->filename))
|
||||
$is_plupload = $this->plupload && $this->plupload->is_active();
|
||||
|
||||
if (!$this->local && !$is_plupload && !is_uploaded_file($this->filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->local && !file_exists($this->filename))
|
||||
if (($this->local || $is_plupload) && !file_exists($this->filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -564,16 +573,28 @@ class fileupload
|
||||
* Upload file from users harddisk
|
||||
*
|
||||
* @param string $form_name Form name assigned to the file input field (if it is an array, the key has to be specified)
|
||||
* @param \phpbb\plupload\plupload $plupload The plupload object
|
||||
*
|
||||
* @return object $file Object "filespec" is returned, all further operations can be done with this object
|
||||
* @access public
|
||||
*/
|
||||
function form_upload($form_name)
|
||||
function form_upload($form_name, \phpbb\plupload\plupload $plupload = null)
|
||||
{
|
||||
global $user, $request;
|
||||
|
||||
$upload = $request->file($form_name);
|
||||
unset($upload['local_mode']);
|
||||
$file = new filespec($upload, $this);
|
||||
|
||||
if ($plupload)
|
||||
{
|
||||
$result = $plupload->handle_upload($form_name);
|
||||
if (is_array($result))
|
||||
{
|
||||
$upload = array_merge($upload, $result);
|
||||
}
|
||||
}
|
||||
|
||||
$file = new filespec($upload, $this, $plupload);
|
||||
|
||||
if ($file->init_error)
|
||||
{
|
||||
|
@@ -1049,6 +1049,12 @@ class parse_message extends bbcode_firstpass
|
||||
|
||||
var $mode;
|
||||
|
||||
/**
|
||||
* The plupload object used for dealing with attachments
|
||||
* @var \phpbb\plupload\plupload
|
||||
*/
|
||||
protected $plupload;
|
||||
|
||||
/**
|
||||
* Init - give message here or manually
|
||||
*/
|
||||
@@ -1440,6 +1446,11 @@ class parse_message extends bbcode_firstpass
|
||||
|
||||
if ($preview || $refresh || sizeof($error))
|
||||
{
|
||||
if (isset($this->plupload) && $this->plupload->is_active())
|
||||
{
|
||||
$json_response = new \phpbb\json_response();
|
||||
}
|
||||
|
||||
// Perform actions on temporary attachments
|
||||
if ($delete_file)
|
||||
{
|
||||
@@ -1484,13 +1495,17 @@ class parse_message extends bbcode_firstpass
|
||||
|
||||
// Reindex Array
|
||||
$this->attachment_data = array_values($this->attachment_data);
|
||||
if (isset($this->plupload) && $this->plupload->is_active())
|
||||
{
|
||||
$json_response->send($this->attachment_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (($add_file || $preview) && $upload_file)
|
||||
{
|
||||
if ($num_attachments < $cfg['max_attachments'] || $auth->acl_gets('m_', 'a_', $forum_id))
|
||||
{
|
||||
$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message);
|
||||
$filedata = upload_attachment($form_name, $forum_id, false, '', $is_message, false, $this->plupload);
|
||||
$error = array_merge($error, $filedata['error']);
|
||||
|
||||
if (!sizeof($error))
|
||||
@@ -1521,12 +1536,32 @@ class parse_message extends bbcode_firstpass
|
||||
$this->attachment_data = array_merge(array(0 => $new_entry), $this->attachment_data);
|
||||
$this->message = preg_replace('#\[attachment=([0-9]+)\](.*?)\[\/attachment\]#e', "'[attachment='.(\\1 + 1).']\\2[/attachment]'", $this->message);
|
||||
$this->filename_data['filecomment'] = '';
|
||||
|
||||
if (isset($this->plupload) && $this->plupload->is_active())
|
||||
{
|
||||
// Send the client the attachment data to maintain state
|
||||
$json_response->send($this->attachment_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$error[] = $user->lang('TOO_MANY_ATTACHMENTS', (int) $cfg['max_attachments']);
|
||||
}
|
||||
|
||||
if (!empty($error) && isset($this->plupload) && $this->plupload->is_active())
|
||||
{
|
||||
// If this is a plupload (and thus ajax) request, give the
|
||||
// client the first error we have
|
||||
$json_response->send(array(
|
||||
'jsonrpc' => '2.0',
|
||||
'id' => 'id',
|
||||
'error' => array(
|
||||
'code' => 105,
|
||||
'message' => current($error),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1687,4 +1722,16 @@ class parse_message extends bbcode_firstpass
|
||||
|
||||
$poll['poll_max_options'] = ($poll['poll_max_options'] < 1) ? 1 : (($poll['poll_max_options'] > $config['max_poll_options']) ? $config['max_poll_options'] : $poll['poll_max_options']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter function for passing the plupload object
|
||||
*
|
||||
* @param \phpbb\plupload\plupload $plupload The plupload object
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function set_plupload(\phpbb\plupload\plupload $plupload)
|
||||
{
|
||||
$this->plupload = $plupload;
|
||||
}
|
||||
}
|
||||
|
@@ -21,9 +21,10 @@ if (!defined('IN_PHPBB'))
|
||||
*/
|
||||
function compose_pm($id, $mode, $action, $user_folders = array())
|
||||
{
|
||||
global $template, $db, $auth, $user;
|
||||
global $template, $db, $auth, $user, $cache;
|
||||
global $phpbb_root_path, $phpEx, $config;
|
||||
global $request;
|
||||
global $phpbb_container;
|
||||
|
||||
// Damn php and globals - i know, this is horrible
|
||||
// Needed for handle_message_list_actions()
|
||||
@@ -385,6 +386,8 @@ function compose_pm($id, $mode, $action, $user_folders = array())
|
||||
}
|
||||
|
||||
$message_parser = new parse_message();
|
||||
$plupload = $phpbb_container->get('plupload');
|
||||
$message_parser->set_plupload($plupload);
|
||||
|
||||
$message_parser->message = ($action == 'reply') ? '' : $message_text;
|
||||
unset($message_text);
|
||||
@@ -1099,6 +1102,11 @@ function compose_pm($id, $mode, $action, $user_folders = array())
|
||||
// Show attachment box for adding attachments if true
|
||||
$allowed = ($auth->acl_get('u_pm_attach') && $config['allow_pm_attach'] && $form_enctype);
|
||||
|
||||
if ($allowed)
|
||||
{
|
||||
$plupload->configure($cache, $template, $s_action, false);
|
||||
}
|
||||
|
||||
// Attachment entry
|
||||
posting_gen_attachment_entry($attachment_data, $filename_data, $allowed);
|
||||
|
||||
|
Reference in New Issue
Block a user