mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-20 12:58:46 +01:00
* Tracker/ProjectManager: images dragged into new (not yet saved) entries where not accessible by other users
This commit is contained in:
parent
e611d52f8e
commit
00b7d2242f
@ -45,7 +45,7 @@ class etemplate_widget_file extends etemplate_widget
|
|||||||
*/
|
*/
|
||||||
public static function ajax_upload() {
|
public static function ajax_upload() {
|
||||||
$response = egw_json_response::get();
|
$response = egw_json_response::get();
|
||||||
$request_id = str_replace(' ', '+', rawurldecode($_REQUEST['request_id']));
|
$request_id = urldecode($_REQUEST['request_id']);
|
||||||
$widget_id = $_REQUEST['widget_id'];
|
$widget_id = $_REQUEST['widget_id'];
|
||||||
if(!self::$request = etemplate_request::read($request_id)) {
|
if(!self::$request = etemplate_request::read($request_id)) {
|
||||||
$response->error("Could not read session");
|
$response->error("Could not read session");
|
||||||
@ -94,8 +94,9 @@ class etemplate_widget_file extends etemplate_widget
|
|||||||
$response->data($file_data);
|
$response->data($file_data);
|
||||||
|
|
||||||
// Check for a callback, call it if there is one
|
// Check for a callback, call it if there is one
|
||||||
foreach($_FILES as $field => $file) {
|
foreach($_FILES as $field => $file)
|
||||||
if($element = $template->getElementById($field))
|
{
|
||||||
|
if(($element = $template->getElementById($field)))
|
||||||
{
|
{
|
||||||
$callback = $element->attrs['callback'];
|
$callback = $element->attrs['callback'];
|
||||||
if(!$callback) $callback = $template->getElementAttribute($field, 'callback');
|
if(!$callback) $callback = $template->getElementAttribute($field, 'callback');
|
||||||
@ -112,6 +113,8 @@ class etemplate_widget_file extends etemplate_widget
|
|||||||
*/
|
*/
|
||||||
protected static function process_uploaded_file($field, Array &$file, $mime, Array &$file_data)
|
protected static function process_uploaded_file($field, Array &$file, $mime, Array &$file_data)
|
||||||
{
|
{
|
||||||
|
unset($field); // not used
|
||||||
|
|
||||||
// Chunks get mangled a little
|
// Chunks get mangled a little
|
||||||
if($file['name'] == 'blob')
|
if($file['name'] == 'blob')
|
||||||
{
|
{
|
||||||
@ -177,7 +180,7 @@ class etemplate_widget_file extends etemplate_widget
|
|||||||
* gather all the parts of the file together
|
* gather all the parts of the file together
|
||||||
*
|
*
|
||||||
* From Resumable samples - http://resumablejs.com/
|
* From Resumable samples - http://resumablejs.com/
|
||||||
* @param string $dir - the temporary directory holding all the parts of the file
|
* @param string $temp_dir - the temporary directory holding all the parts of the file
|
||||||
* @param string $fileName - the original file name
|
* @param string $fileName - the original file name
|
||||||
* @param string $chunkSize - each chunk size (in bytes)
|
* @param string $chunkSize - each chunk size (in bytes)
|
||||||
* @param string $totalSize - original file size (in bytes)
|
* @param string $totalSize - original file size (in bytes)
|
||||||
|
@ -98,9 +98,9 @@ class etemplate_widget_link extends etemplate_widget
|
|||||||
$options['type'] = $type ? $type : $options['type'];
|
$options['type'] = $type ? $type : $options['type'];
|
||||||
if(!$options['num_rows']) $options['num_rows'] = 1000;
|
if(!$options['num_rows']) $options['num_rows'] = 1000;
|
||||||
$links = egw_link::query($app, $pattern, $options);
|
$links = egw_link::query($app, $pattern, $options);
|
||||||
$links = array_combine(array_map(create_function('$k', 'return (string)" ".$k;'), array_keys($links)), $links);
|
$linksc = array_combine(array_map(create_function('$k', 'return (string)" ".$k;'), array_keys($links)), $links);
|
||||||
$response = egw_json_response::get();
|
$response = egw_json_response::get();
|
||||||
$response->data($links);
|
$response->data($linksc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,8 +217,8 @@ class etemplate_widget_link extends etemplate_widget
|
|||||||
$link = egw_link::get_link((int)$link_id);
|
$link = egw_link::get_link((int)$link_id);
|
||||||
if($link && $link['app'] == egw_link::VFS_APPNAME)
|
if($link && $link['app'] == egw_link::VFS_APPNAME)
|
||||||
{
|
{
|
||||||
$file = egw_link::list_attached($link['app2'],$link['id2']);
|
$files = egw_link::list_attached($link['app2'],$link['id2']);
|
||||||
$file = $file[(int)$link_id];
|
$file = $files[(int)$link_id];
|
||||||
$path = egw_link::vfs_path($link['app2'],$link['id2'],$file['id']);
|
$path = egw_link::vfs_path($link['app2'],$link['id2'],$file['id']);
|
||||||
$result = egw_vfs::proppatch($path, array(array('name' => 'comment', 'val' => $comment)));
|
$result = egw_vfs::proppatch($path, array(array('name' => 'comment', 'val' => $comment)));
|
||||||
}
|
}
|
||||||
@ -299,6 +299,12 @@ class etemplate_widget_link extends etemplate_widget
|
|||||||
{
|
{
|
||||||
$value = $value_in =& self::get_array($content, $form_name);
|
$value = $value_in =& self::get_array($content, $form_name);
|
||||||
|
|
||||||
|
// keep values added into request by other ajax-functions, eg. files draged into htmlarea (etemplate_widget_vfs)
|
||||||
|
if (!$value['to_id'])
|
||||||
|
{
|
||||||
|
$value['to_id'] = $expand['cont'][$this->id]['to_id'];
|
||||||
|
}
|
||||||
|
|
||||||
// Link widgets can share IDs, make sure to preserve values from others
|
// Link widgets can share IDs, make sure to preserve values from others
|
||||||
$already = self::get_array($validated,$form_name);
|
$already = self::get_array($validated,$form_name);
|
||||||
if($already != null)
|
if($already != null)
|
||||||
@ -312,7 +318,7 @@ class etemplate_widget_link extends etemplate_widget
|
|||||||
// Do we have enough information to link automatically?
|
// Do we have enough information to link automatically?
|
||||||
if(is_array($value) && $value['to_id'])
|
if(is_array($value) && $value['to_id'])
|
||||||
{
|
{
|
||||||
$result = egw_link::link($value['to_app'], $value['to_id'], $link['app'], $link['id']);
|
egw_link::link($value['to_app'], $value['to_id'], $link['app'], $link['id']);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -349,7 +355,7 @@ class etemplate_widget_link extends etemplate_widget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$valid =& self::get_array($validated, $form_name, true);
|
$valid =& self::get_array($validated, $form_name, true);
|
||||||
$valid = $value;
|
if (true) $valid = $value;
|
||||||
//error_log($this);
|
//error_log($this);
|
||||||
//error_log(" " . array2string($valid));
|
//error_log(" " . array2string($valid));
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ class etemplate_widget_vfs extends etemplate_widget_file
|
|||||||
$path = egw_link::vfs_path($app,$id,'',true);
|
$path = egw_link::vfs_path($app,$id,'',true);
|
||||||
if (!empty($relpath)) $path .= '/'.$relpath;
|
if (!empty($relpath)) $path .= '/'.$relpath;
|
||||||
|
|
||||||
$value = array();
|
if (true) $value = array();
|
||||||
|
|
||||||
// Single file, already existing
|
// Single file, already existing
|
||||||
if (substr($path,-1) != '/' && egw_vfs::file_exists($path) && !egw_vfs::is_dir($path))
|
if (substr($path,-1) != '/' && egw_vfs::file_exists($path) && !egw_vfs::is_dir($path))
|
||||||
@ -105,9 +105,10 @@ class etemplate_widget_vfs extends etemplate_widget_file
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function ajax_upload() {
|
public static function ajax_upload()
|
||||||
|
{
|
||||||
parent::ajax_upload();
|
parent::ajax_upload();
|
||||||
foreach($_FILES as $field => $file)
|
foreach($_FILES as $file)
|
||||||
{
|
{
|
||||||
self::store_file($_REQUEST['path'] ? $_REQUEST['path'] : $_REQUEST['widget_id'], $file);
|
self::store_file($_REQUEST['path'] ? $_REQUEST['path'] : $_REQUEST['widget_id'], $file);
|
||||||
}
|
}
|
||||||
@ -118,7 +119,7 @@ class etemplate_widget_vfs extends etemplate_widget_file
|
|||||||
*/
|
*/
|
||||||
public static function ajax_htmlarea_upload()
|
public static function ajax_htmlarea_upload()
|
||||||
{
|
{
|
||||||
$request_id = str_replace(' ', '+', rawurldecode($_REQUEST['request_id']));
|
$request_id = urldecode($_REQUEST['request_id']);
|
||||||
$widget_id = $_REQUEST['widget_id'];
|
$widget_id = $_REQUEST['widget_id'];
|
||||||
if(!self::$request = etemplate_request::read($request_id))
|
if(!self::$request = etemplate_request::read($request_id))
|
||||||
{
|
{
|
||||||
@ -130,10 +131,6 @@ class etemplate_widget_vfs extends etemplate_widget_file
|
|||||||
// Can't use callback
|
// Can't use callback
|
||||||
$error = lang("Could not get template for file upload, callback skipped");
|
$error = lang("Could not get template for file upload, callback skipped");
|
||||||
}
|
}
|
||||||
/*elseif (!($widget = $template->getElementById($widget_id)))
|
|
||||||
{
|
|
||||||
$error = "Widget '$widget_id' not found!";
|
|
||||||
}*/
|
|
||||||
elseif (!isset($_FILES['upload']))
|
elseif (!isset($_FILES['upload']))
|
||||||
{
|
{
|
||||||
$error = lang('No _FILES[upload] found!');
|
$error = lang('No _FILES[upload] found!');
|
||||||
@ -142,6 +139,17 @@ class etemplate_widget_vfs extends etemplate_widget_file
|
|||||||
{
|
{
|
||||||
$data = self::$request->content[$widget_id];
|
$data = self::$request->content[$widget_id];
|
||||||
$path = self::store_file($path = self::get_vfs_path($data['to_app'].':'.$data['to_id']).'/', $_FILES['upload']);
|
$path = self::store_file($path = self::get_vfs_path($data['to_app'].':'.$data['to_id']).'/', $_FILES['upload']);
|
||||||
|
|
||||||
|
// store temp. vfs-path like links to be able to move it to correct location after entry is stored
|
||||||
|
if (!$data['to_id'] || is_array($data['to_id']))
|
||||||
|
{
|
||||||
|
egw_link::link($data['to_app'], $data['to_id'], egw_link::VFS_APPNAME, array(
|
||||||
|
'name' => $_FILES['upload']['name'],
|
||||||
|
'type' => $_FILES['upload']['type'],
|
||||||
|
'tmp_name' => egw_vfs::PREFIX.$path,
|
||||||
|
));
|
||||||
|
self::$request->content = array_merge(self::$request->content, array($widget_id => $data));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// switch regular JSON response handling off
|
// switch regular JSON response handling off
|
||||||
egw_json_request::isJSONRequest(false);
|
egw_json_request::isJSONRequest(false);
|
||||||
@ -161,6 +169,55 @@ class etemplate_widget_vfs extends etemplate_widget_file
|
|||||||
common::egw_exit();
|
common::egw_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix source/url of dragged in images in html
|
||||||
|
*
|
||||||
|
* @param string $app
|
||||||
|
* @param int|string $id
|
||||||
|
* @param array $links
|
||||||
|
* @param string& $html
|
||||||
|
* @return boolean true if something was fixed and $html needs to be stored
|
||||||
|
*/
|
||||||
|
static function fix_html_dragins($app, $id, array $links, &$html)
|
||||||
|
{
|
||||||
|
$replace = $remove_dir = array();
|
||||||
|
foreach($links as $link)
|
||||||
|
{
|
||||||
|
$matches = null;
|
||||||
|
if (is_array($link) && preg_match('|^'.preg_quote(egw_vfs::PREFIX,'|').'('.preg_quote(self::get_temp_dir($app, ''), '|').'[^/]+)/|', $link['id']['tmp_name'], $matches))
|
||||||
|
{
|
||||||
|
$replace[substr($link['id']['tmp_name'], strlen(egw_vfs::PREFIX))] =
|
||||||
|
egw_link::vfs_path($app, $id, egw_vfs::basename($link['id']['tmp_name']), true);
|
||||||
|
|
||||||
|
if (!in_array($matches[1], $remove_dir)) $remove_dir[] = $matches[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($replace)
|
||||||
|
{
|
||||||
|
$html = strtr($old = $html, $replace);
|
||||||
|
// remove all dirs
|
||||||
|
foreach($remove_dir as $dir)
|
||||||
|
{
|
||||||
|
egw_vfs::remove($dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isset($old) && $old != $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a temp. directory for htmlarea uploads: /home/$user/.tmp/$app_$postfix
|
||||||
|
*
|
||||||
|
* @param string $app app-name
|
||||||
|
* @param string $postfix =null default random id
|
||||||
|
* @return string vfs path
|
||||||
|
*/
|
||||||
|
static function get_temp_dir($app, $postfix=null)
|
||||||
|
{
|
||||||
|
if (!isset($postfix)) $postfix = md5(time().session_id());
|
||||||
|
|
||||||
|
return '/home/'.$GLOBALS['egw_info']['user']['account_lid'].'/.tmp/'.$app.'_'.$postfix;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ajax callback to receive an incoming file
|
* Ajax callback to receive an incoming file
|
||||||
*
|
*
|
||||||
@ -169,7 +226,8 @@ class etemplate_widget_vfs extends etemplate_widget_file
|
|||||||
* When the form is submitted, the information for all files uploaded is available in the returned
|
* When the form is submitted, the information for all files uploaded is available in the returned
|
||||||
* $content array and the application should deal with the file.
|
* $content array and the application should deal with the file.
|
||||||
*/
|
*/
|
||||||
public static function store_file($path, $file) {
|
public static function store_file($path, $file)
|
||||||
|
{
|
||||||
$name = $_REQUEST['widget_id'];
|
$name = $_REQUEST['widget_id'];
|
||||||
|
|
||||||
// Find real path
|
// Find real path
|
||||||
@ -232,30 +290,30 @@ class etemplate_widget_vfs extends etemplate_widget_file
|
|||||||
{
|
{
|
||||||
case 'vfs-upload':
|
case 'vfs-upload':
|
||||||
if(!is_array($value)) $value = array();
|
if(!is_array($value)) $value = array();
|
||||||
// Check & skip files that made it asyncronously
|
/* Check & skip files that made it asyncronously
|
||||||
list($app,$id,$relpath) = explode(':',$this->id,3);
|
list($app,$id,$relpath) = explode(':',$this->id,3);
|
||||||
//...
|
//...
|
||||||
foreach($value as $tmp => $file)
|
foreach($value as $tmp => $file)
|
||||||
{
|
{
|
||||||
if(egw_vfs::file_exists(self::get_vfs_path($id) . $relpath)) {}
|
if(egw_vfs::file_exists(self::get_vfs_path($id) . $relpath)) {}
|
||||||
}
|
}*/
|
||||||
parent::validate($cname, $content, $validated);
|
parent::validate($cname, $content, $validated);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$valid = $value;
|
if (true) $valid = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change an ID like app:id:relative/path to an actual VFS location
|
* Change an ID like app:id:relative/path to an actual VFS location
|
||||||
*/
|
*/
|
||||||
public static function get_vfs_path($path) {
|
public static function get_vfs_path($path)
|
||||||
|
{
|
||||||
list($app,$id,$relpath) = explode(':',$path,3);
|
list($app,$id,$relpath) = explode(':',$path,3);
|
||||||
if (empty($id) || $id == 'undefined')
|
if (empty($id) || $id == 'undefined')
|
||||||
{
|
{
|
||||||
static $tmppath = array(); // static var, so all vfs-uploads get created in the same temporary dir
|
static $tmppath = array(); // static var, so all vfs-uploads get created in the same temporary dir
|
||||||
if (!isset($tmppath[$app])) $tmppath[$app] = '/home/'.$GLOBALS['egw_info']['user']['account_lid'].'/.'.$app.'_'.md5(time().session_id());
|
if (!isset($tmppath[$app])) $tmppath[$app] = self::get_temp_dir ($app);
|
||||||
$path = $tmppath[$app];
|
$path = $tmppath[$app];
|
||||||
unset($cell['onchange']); // no onchange, if we have to use a temporary dir
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user