1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00

Added option to use a custom plugin folder for media-manager image uploads. ie. writeParms => array('path'=>'plugin');

This commit is contained in:
Cameron 2016-12-06 19:24:48 -08:00
parent b9a331f15f
commit f203ed7bd5
4 changed files with 52 additions and 19 deletions

View File

@ -1103,7 +1103,7 @@ class media_admin_ui extends e_admin_ui
}
$text = "<h4>".IMALAN_145."</h4>";
$text .= '<div id="uploader" data-max-size="'.str_replace('M','mb',$maxFileSize).'" rel="'.e_JS.'plupload/upload.php?for='.$this->getQuery('for').'">
$text .= '<div id="uploader" data-max-size="'.str_replace('M','mb',$maxFileSize).'" rel="'.e_JS.'plupload/upload.php?for='.$this->getQuery('for').'&path='.$this->getQuery('path').'">
<p>'.IMALAN_146.'</p>
</div>';
$text .= '<hr />';

View File

@ -890,16 +890,21 @@ class e_form
$url .= "&amp;w=".$extras['w'];
}
if(vartrue($extras['glyphs']))
if(!empty($extras['glyphs']))
{
$url .= "&amp;glyphs=1";
}
if(vartrue($extras['video']))
if(!empty($extras['video']))
{
$url .= "&amp;video=1";
}
if(!empty($extras['path']) && $extras['path'] == 'plugin')
{
$url .= "&amp;path=".deftrue('e_CURRENT_PLUGIN');
}
if(E107_DBG_BASIC)
{

View File

@ -973,8 +973,7 @@ class e_media
function getPath($mime)
function getPath($mime, $path=null)
{
$mes = e107::getMessage();
@ -988,11 +987,19 @@ class e_media
return FALSE;
}
$dir = $this->mimePaths[$pmime].date("Y-m");
if(!empty($path))
{
$dir = e_MEDIA."plugins/".e107::getParser()->filter($path,'w');
}
else
{
$dir = $this->mimePaths[$pmime].date("Y-m");
}
if(!is_dir($dir))
{
if(!mkdir($dir, 0755))
if(!mkdir($dir, 0755,true))
{
$this->log("Couldn't create folder ($dir).");
@ -1056,15 +1063,34 @@ class e_media
}
public function importFile($file='',$category='_common_image', $oldpath = null, $new_data = array())
/**
* Import a file into the Media Manager
* @param string $file Path to file
* @param string $category media-category to import into
* @param null|array $opts
* @param string $opts['path'] Custom Folder (optional)
* @param array $new_data - Additional media info to save.
* @param string $new_data['media_caption']
* @param string $new_data['media_descrption']
* @return bool|string
*/
public function importFile($file='', $category='_common_image', $opts = null, $new_data = array())
{
$mes = e107::getMessage();
$tp = e107::getParser();
$sql = e107::getDb();
if(is_array($opts))
{
$uploadPath = varset($opts['path']);
$oldpath = null;
}
else
{
$uploadPath = null;
$oldpath = $opts;
}
if(empty($oldpath)) $oldpath = e_IMPORT.$file;
if(!file_exists($oldpath))
@ -1082,11 +1108,12 @@ class e_media
$img_data = $this->mediaData($oldpath); // Basic File Info only
if(!$typePath = $this->getPath($img_data['media_type']))
if(!$typePath = $this->getPath($img_data['media_type'], $uploadPath))
{
$this->log("Line: ".__LINE__." Couldn't generate path from file info:".$oldpath);
$mes->addError("Couldn't generate path from file info:".$oldpath);
return FALSE;
return false;
}
@ -1101,7 +1128,7 @@ class e_media
{
$this->log("Couldn't move file from ".realpath($oldpath)." to ".e_MEDIA.$newpath);
$mes->add("Couldn't move file from ".$oldpath." to ".$newpath, E_MESSAGE_ERROR);
return FALSE;
return false;
};
$img_data['media_url'] = $tp->createConstants($newpath,'rel');
@ -1121,7 +1148,7 @@ class e_media
{
$this->log("Db Insert Failed: ".var_export($img_data,true));
rename($newpath,$oldpath); //move it back.
return FALSE;
return false;
}

View File

@ -187,7 +187,8 @@
// rename($targetDir.$fileName,e_MEDIA."images/2012-05/",$fileName);
if($_GET['for'] != '') // leave in upload directory if no category given.
{
$result = e107::getMedia()->importFile($fileName, $_GET['for']);
$uploadPath = varset($_GET['path'],null);
$result = e107::getMedia()->importFile($fileName, $_GET['for'], array('path'=>$uploadPath));
}