1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02: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 = "<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> <p>'.IMALAN_146.'</p>
</div>'; </div>';
$text .= '<hr />'; $text .= '<hr />';

View File

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

View File

@@ -973,8 +973,7 @@ class e_media
function getPath($mime, $path=null)
function getPath($mime)
{ {
$mes = e107::getMessage(); $mes = e107::getMessage();
@@ -988,11 +987,19 @@ class e_media
return FALSE; 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(!is_dir($dir))
{ {
if(!mkdir($dir, 0755)) if(!mkdir($dir, 0755,true))
{ {
$this->log("Couldn't create folder ($dir)."); $this->log("Couldn't create folder ($dir).");
@@ -1054,19 +1061,38 @@ class e_media
$insert = "\n\n".date('r')."\n".$message; $insert = "\n\n".date('r')."\n".$message;
file_put_contents(e_LOG."mediaUpload.log",$insert,FILE_APPEND | LOCK_EX); file_put_contents(e_LOG."mediaUpload.log",$insert,FILE_APPEND | LOCK_EX);
} }
/**
* Import a file into the Media Manager
* @param string $file Path to file
public function importFile($file='',$category='_common_image', $oldpath = null, $new_data = array()) * @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(); $mes = e107::getMessage();
$tp = e107::getParser(); $tp = e107::getParser();
$sql = e107::getDb(); $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(empty($oldpath)) $oldpath = e_IMPORT.$file;
if(!file_exists($oldpath)) if(!file_exists($oldpath))
{ {
// Check it hasn't been imported already. // Check it hasn't been imported already.
@@ -1082,11 +1108,12 @@ class e_media
$img_data = $this->mediaData($oldpath); // Basic File Info only $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); $this->log("Line: ".__LINE__." Couldn't generate path from file info:".$oldpath);
$mes->addError("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); $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); $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'); $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)); $this->log("Db Insert Failed: ".var_export($img_data,true));
rename($newpath,$oldpath); //move it back. 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); // rename($targetDir.$fileName,e_MEDIA."images/2012-05/",$fileName);
if($_GET['for'] != '') // leave in upload directory if no category given. 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));
} }