mirror of
https://github.com/e107inc/e107.git
synced 2025-04-22 13:41:52 +02:00
mediapicker() enhancements. Now accepts: resize, rename and convert $parms. See PHPDoc for details.
This commit is contained in:
parent
a200d312d8
commit
bd45d497d8
e107_handlers
@ -1285,6 +1285,7 @@ class e_form
|
||||
|
||||
/**
|
||||
* Media Picker
|
||||
*
|
||||
|
||||
* @param string $name input name
|
||||
* @param string $default default value
|
||||
@ -1300,9 +1301,12 @@ class e_form
|
||||
* - audio=1 (Enable the Audio tab)
|
||||
* - glyph=1 (Enable the Glyphs tab).
|
||||
* - path=plugin (store in media/plugins/{current-plugin])
|
||||
* - edit=false (disable media-manager popup button)
|
||||
* @example $frm->imagepicker('banner_image', $_POST['banner_image'], '', 'media=banner&w=600');
|
||||
* - edit=false (disable media-manager popup button)
|
||||
* - rename (string) rename file to this value after upload. (don't forget the extension)
|
||||
* - resize array with numberic x values. (array 'w'=>x, 'h'=>x) - resize the uploaded image before importing during upload.
|
||||
* - convert=jpg (override pref and convert uploaded image to jpeg format. )
|
||||
* @return string html output
|
||||
*@example $frm->imagepicker('banner_image', $_POST['banner_image'], '', 'media=banner&w=600');
|
||||
*/
|
||||
function mediapicker($name, $default, $parms = '')
|
||||
{
|
||||
@ -1340,7 +1344,6 @@ class e_form
|
||||
$parms['h'] = 190;
|
||||
}
|
||||
|
||||
|
||||
// $width = vartrue($parms['w'], 220);
|
||||
// $height = vartrue($parms['h'], 190);
|
||||
// e107::getDebug()->log($parms);
|
||||
@ -1426,6 +1429,33 @@ class e_form
|
||||
$qry .= "&path=".deftrue('e_CURRENT_PLUGIN');
|
||||
}
|
||||
|
||||
if(!empty($parms['rename']))
|
||||
{
|
||||
$qry .= "&rename=".$parms['rename'];
|
||||
}
|
||||
|
||||
if(!empty($parms['convert']))
|
||||
{
|
||||
$qry .= "&convert=".$parms['convert'];
|
||||
}
|
||||
|
||||
if(isset($parms['w']))
|
||||
{
|
||||
$qry .= "&w=".(int) $parms['w'];
|
||||
}
|
||||
|
||||
if(isset($parms['h']))
|
||||
{
|
||||
$qry .= "&h=".(int) $parms['h'];
|
||||
}
|
||||
|
||||
if(!empty($parms['resize']))
|
||||
{
|
||||
$resize = array('resize'=>$parms['resize']);
|
||||
$qry .= "&".http_build_query($resize);
|
||||
}
|
||||
|
||||
|
||||
// Drag-n-Drop Upload
|
||||
// @see https://www.dropzonejs.com/#server-side-implementation
|
||||
|
||||
@ -2910,7 +2940,7 @@ class e_form
|
||||
if(!is_array($selected)) $selected = explode(",",$selected);
|
||||
|
||||
}
|
||||
|
||||
|
||||
$text = $this->select_open($name, $options)."\n";
|
||||
|
||||
if(isset($options['default']))
|
||||
@ -3154,6 +3184,7 @@ var_dump($select_options);*/
|
||||
if(is_string($options)) parse_str($options, $options);
|
||||
|
||||
if(false === $value) $value = '';
|
||||
|
||||
$options = $this->format_options('option', '', $options);
|
||||
$options['selected'] = $selected; //comes as separate argument just for convenience
|
||||
|
||||
@ -3673,7 +3704,7 @@ var_dump($select_options);*/
|
||||
foreach ($options as $option => $optval)
|
||||
{
|
||||
$optval = trim($optval);
|
||||
switch ($option)
|
||||
switch ($option)
|
||||
{
|
||||
|
||||
case 'id':
|
||||
|
@ -2231,9 +2231,15 @@ class e_media
|
||||
|
||||
|
||||
$convertToJpeg = e107::getPref('convert_to_jpeg', 0);
|
||||
|
||||
if(!empty($_REQUEST['convert']) && $_REQUEST['convert'] === 'jpg')
|
||||
{
|
||||
$convertToJpeg = true;
|
||||
}
|
||||
|
||||
$fileSize = filesize($filePath);
|
||||
|
||||
if(varset($_GET['for']) !== '_icon' && !empty($convertToJpeg))
|
||||
if(varset($_REQUEST['for']) !== '_icon' && !empty($convertToJpeg))
|
||||
{
|
||||
if($jpegFile = e107::getMedia()->convertImageToJpeg($filePath, true))
|
||||
{
|
||||
@ -2244,10 +2250,28 @@ class e_media
|
||||
|
||||
}
|
||||
|
||||
if(!empty($_GET['for'])) // leave in upload directory if no category given.
|
||||
if(!empty($_REQUEST['resize']))
|
||||
{
|
||||
$uploadPath = varset($_GET['path'],null);
|
||||
$for = e107::getParser()->filter($_GET['for']);
|
||||
$thumb = e107::getThumb($filePath);
|
||||
$w = (int) $_REQUEST['resize']['w'];
|
||||
$h = (int) $_REQUEST['resize']['h'];
|
||||
$thumb->adaptiveResize($w,$h)->save($filePath);
|
||||
}
|
||||
|
||||
if(!empty($_REQUEST['rename']))
|
||||
{
|
||||
$newPath = $targetDir.basename($_REQUEST['rename']);
|
||||
if(!rename($filePath, $newPath))
|
||||
{
|
||||
return '{"jsonrpc" : "2.0", "error" : {"code": 105, "message": "Unable to rename '.$filePath.' to '.$newPath.'"}, "id" : "id"}';
|
||||
}
|
||||
$fileName = basename($newPath);
|
||||
}
|
||||
|
||||
if(!empty($_REQUEST['for'])) // leave in upload directory if no category given.
|
||||
{
|
||||
$uploadPath = varset($_REQUEST['path'],null);
|
||||
$for = e107::getParser()->filter($_REQUEST['for']);
|
||||
$for = str_replace(array('+','^'),'', $for);
|
||||
|
||||
$result = e107::getMedia()->importFile($fileName, $for, array('path'=>$uploadPath));
|
||||
@ -2261,7 +2285,23 @@ class e_media
|
||||
$this->ajaxUploadLog($filePath,$fileName,$fileSize,$result);
|
||||
|
||||
|
||||
$preview = $this->previewTag($result);
|
||||
|
||||
// file_put_contents(e_LOG."mediatmp.log", print_r($previewArr,true));
|
||||
|
||||
$opts = array();
|
||||
|
||||
// set correct size for preview image.
|
||||
if(isset($_REQUEST['w']))
|
||||
{
|
||||
$opts['w'] = (int) $_REQUEST['w'];
|
||||
}
|
||||
|
||||
if(isset($_REQUEST['h']))
|
||||
{
|
||||
$opts['h'] = (int) $_REQUEST['h'];
|
||||
}
|
||||
|
||||
$preview = $this->previewTag($result,$opts);
|
||||
$array = array("jsonrpc" => "2.0", "result" => $result, "id" => "id", 'preview' => $preview, 'data'=>$_FILES );
|
||||
|
||||
return json_encode($array);
|
||||
|
Loading…
x
Reference in New Issue
Block a user