mirror of
https://github.com/e107inc/e107.git
synced 2025-01-17 12:48:24 +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:
parent
b9a331f15f
commit
f203ed7bd5
@ -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 />';
|
||||
|
@ -890,16 +890,21 @@ class e_form
|
||||
$url .= "&w=".$extras['w'];
|
||||
}
|
||||
|
||||
if(vartrue($extras['glyphs']))
|
||||
if(!empty($extras['glyphs']))
|
||||
{
|
||||
$url .= "&glyphs=1";
|
||||
}
|
||||
|
||||
if(vartrue($extras['video']))
|
||||
if(!empty($extras['video']))
|
||||
{
|
||||
$url .= "&video=1";
|
||||
}
|
||||
|
||||
if(!empty($extras['path']) && $extras['path'] == 'plugin')
|
||||
{
|
||||
$url .= "&path=".deftrue('e_CURRENT_PLUGIN');
|
||||
}
|
||||
|
||||
if(E107_DBG_BASIC)
|
||||
{
|
||||
|
||||
|
@ -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).");
|
||||
@ -1054,19 +1061,38 @@ class e_media
|
||||
$insert = "\n\n".date('r')."\n".$message;
|
||||
file_put_contents(e_LOG."mediaUpload.log",$insert,FILE_APPEND | LOCK_EX);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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))
|
||||
{
|
||||
// Check it hasn't been imported already.
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user