mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 20:30:39 +02:00
mediapicker() enhancements. Now accepts: resize, rename and convert $parms. See PHPDoc for details.
This commit is contained in:
@@ -1285,6 +1285,7 @@ class e_form
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Media Picker
|
* Media Picker
|
||||||
|
*
|
||||||
|
|
||||||
* @param string $name input name
|
* @param string $name input name
|
||||||
* @param string $default default value
|
* @param string $default default value
|
||||||
@@ -1301,8 +1302,11 @@ class e_form
|
|||||||
* - glyph=1 (Enable the Glyphs tab).
|
* - glyph=1 (Enable the Glyphs tab).
|
||||||
* - path=plugin (store in media/plugins/{current-plugin])
|
* - path=plugin (store in media/plugins/{current-plugin])
|
||||||
* - edit=false (disable media-manager popup button)
|
* - edit=false (disable media-manager popup button)
|
||||||
* @example $frm->imagepicker('banner_image', $_POST['banner_image'], '', 'media=banner&w=600');
|
* - 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
|
* @return string html output
|
||||||
|
*@example $frm->imagepicker('banner_image', $_POST['banner_image'], '', 'media=banner&w=600');
|
||||||
*/
|
*/
|
||||||
function mediapicker($name, $default, $parms = '')
|
function mediapicker($name, $default, $parms = '')
|
||||||
{
|
{
|
||||||
@@ -1340,7 +1344,6 @@ class e_form
|
|||||||
$parms['h'] = 190;
|
$parms['h'] = 190;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $width = vartrue($parms['w'], 220);
|
// $width = vartrue($parms['w'], 220);
|
||||||
// $height = vartrue($parms['h'], 190);
|
// $height = vartrue($parms['h'], 190);
|
||||||
// e107::getDebug()->log($parms);
|
// e107::getDebug()->log($parms);
|
||||||
@@ -1426,6 +1429,33 @@ class e_form
|
|||||||
$qry .= "&path=".deftrue('e_CURRENT_PLUGIN');
|
$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
|
// Drag-n-Drop Upload
|
||||||
// @see https://www.dropzonejs.com/#server-side-implementation
|
// @see https://www.dropzonejs.com/#server-side-implementation
|
||||||
|
|
||||||
@@ -3154,6 +3184,7 @@ var_dump($select_options);*/
|
|||||||
if(is_string($options)) parse_str($options, $options);
|
if(is_string($options)) parse_str($options, $options);
|
||||||
|
|
||||||
if(false === $value) $value = '';
|
if(false === $value) $value = '';
|
||||||
|
|
||||||
$options = $this->format_options('option', '', $options);
|
$options = $this->format_options('option', '', $options);
|
||||||
$options['selected'] = $selected; //comes as separate argument just for convenience
|
$options['selected'] = $selected; //comes as separate argument just for convenience
|
||||||
|
|
||||||
|
@@ -2231,9 +2231,15 @@ class e_media
|
|||||||
|
|
||||||
|
|
||||||
$convertToJpeg = e107::getPref('convert_to_jpeg', 0);
|
$convertToJpeg = e107::getPref('convert_to_jpeg', 0);
|
||||||
|
|
||||||
|
if(!empty($_REQUEST['convert']) && $_REQUEST['convert'] === 'jpg')
|
||||||
|
{
|
||||||
|
$convertToJpeg = true;
|
||||||
|
}
|
||||||
|
|
||||||
$fileSize = filesize($filePath);
|
$fileSize = filesize($filePath);
|
||||||
|
|
||||||
if(varset($_GET['for']) !== '_icon' && !empty($convertToJpeg))
|
if(varset($_REQUEST['for']) !== '_icon' && !empty($convertToJpeg))
|
||||||
{
|
{
|
||||||
if($jpegFile = e107::getMedia()->convertImageToJpeg($filePath, true))
|
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);
|
$thumb = e107::getThumb($filePath);
|
||||||
$for = e107::getParser()->filter($_GET['for']);
|
$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);
|
$for = str_replace(array('+','^'),'', $for);
|
||||||
|
|
||||||
$result = e107::getMedia()->importFile($fileName, $for, array('path'=>$uploadPath));
|
$result = e107::getMedia()->importFile($fileName, $for, array('path'=>$uploadPath));
|
||||||
@@ -2261,7 +2285,23 @@ class e_media
|
|||||||
$this->ajaxUploadLog($filePath,$fileName,$fileSize,$result);
|
$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 );
|
$array = array("jsonrpc" => "2.0", "result" => $result, "id" => "id", 'preview' => $preview, 'data'=>$_FILES );
|
||||||
|
|
||||||
return json_encode($array);
|
return json_encode($array);
|
||||||
|
Reference in New Issue
Block a user