1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

Media-Manager dialog fixes and enhancements

This commit is contained in:
CaMer0n
2012-04-28 01:31:30 +00:00
parent a61b072d44
commit 28710b46b2
5 changed files with 276 additions and 77 deletions

View File

@@ -37,10 +37,8 @@ include_lan(e_LANGUAGEDIR.e_LANGUAGE.'/admin/lan_'.e_PAGE);
$e_sub_cat = 'image';
// require_once("auth.php");
// require_once(e_HANDLER."form_handler.php");
//require_once(e_HANDLER."userclass_class.php");
//require_once(e_HANDLER."message_handler.php");
// $frm = new e_form(); //new form handler
$emessage = eMessage::getInstance();
@@ -329,7 +327,7 @@ class media_admin_ui extends e_admin_ui
$this->cats[$cat] = $row['media_cat_title'];
}
asort($this->cats);
if(varset($_POST['batch_import_selected']))
{
@@ -342,20 +340,96 @@ class media_admin_ui extends e_admin_ui
}
if($this->getQuery('iframe'))
{
$this->getResponse()->setIframeMod();
}
if($this->getQuery('for') && $this->getMediaCategory($this->getQuery('for')))
{
$this->setPosted('media_category', $this->getQuery('for'));
if(!$this->getId())
{
$this->getResponse()->setIframeMod(); // disable header/footer menus etc.
if(!$this->getQuery('for'))
{
$this->getModel()->set('media_category', $this->getQuery('for'));
$this->setPosted('media_category', "_common");
$this->getModel()->set('media_category', "_common");
}
elseif($this->getMediaCategory($this->getQuery('for')))
{
$this->setPosted('media_category', $this->getQuery('for'));
if(!$this->getId())
{
$this->getModel()->set('media_category', $this->getQuery('for'));
}
}
}
//
// if($this->getQuery('for') && $this->getMediaCategory($this->getQuery('for')))
// {
//
// $this->setPosted('media_category', $this->getQuery('for'));
// if(!$this->getId())
// {
// $this->getModel()->set('media_category', $this->getQuery('for'));
// }
// }
//
}
function dialogPage() // Popup dialogPage for Image Selection.
{
// $this->getModel()->setAction('create');
// $this->getUI()->getController()->getRequest()->setAction('create');
//$this->setAction('create');;
if($_POST['etrigger_submit'])
{
$data = $this->beforeCreate($_POST);
e107::getDb()->db_Insert('core_media',$data); // Replace with Generic (needs parm sent)
}
echo $this->imageSelectUpload();
}
function imageSelectUpload()
{
$text = "
<div class='admintabs' id='tab-container'>
<ul class='e-tabs e-hideme' id='core-emote-tabs'>
<li id='tab-select'><a href='#core-media-select'>Choose from Library</a></li>
<li id='tab-upload'><a href='#core-media-upload'>Upload a File</a></li>
</ul>
<fieldset id='core-media-select'>
<legend>Library</legend>
<table cellpadding='0' cellspacing='0' class='adminedit'>
<tbody><tr><td>
<div>Filter: <input type='text' name='non-working-filter-example' value='' /><br />&nbsp;</div>
<div>";
// This should really be replaced with the generic LIST function, but with it's own template for markup.
$text .= e107::getMedia()->mediaSelect($this->getQuery('for'),$this->getQuery('tagid')); // eg. news, news-thumbnail
$text .= "</div>
</td></tr>
</tbody></table>
</fieldset>
<fieldset id='core-media-upload'>
<legend>Upload</legend>";
$this->fields['media_category']['readonly'] = TRUE;
$this->fields['media_url']['noedit'] = TRUE;
$this->fields['media_userclass']['noedit'] = TRUE;
$text .= $this->CreatePage();
$text .= "
</fieldset>
</div>
";
return $text;
}
function importPage()
{
$this->batchImportForm();
@@ -384,6 +458,7 @@ class media_admin_ui extends e_admin_ui
*/
public function beforeCreate($new_data)
{
// print_a($_POST);
// return data to be merged with posted model data
$this->getRequest()->setPosted('media_upload', null);
//$dataFields = $this->getModel()->getDataFields();
@@ -430,7 +505,7 @@ class media_admin_ui extends e_admin_ui
$mes = e107::getMessage();
if(vartrue($_FILES['file_userfile']))
if(vartrue($_FILES['file_userfile'])) // CREATE
{
$pref['upload_storagetype'] = "1";
@@ -439,49 +514,46 @@ class media_admin_ui extends e_admin_ui
$upload = array_shift($uploaded);
if(vartrue($upload['error']))
{
$mes->add($upload['message'], E_MESSAGE_ERROR);
$mes->addError($upload['message']);
return FALSE;
}
if(!$typePath = $this->getPath($upload['type']))
{
$mes->addError("Couldn't generated path from upload data");
return FALSE;
}
$mes->addDebug(print_a($upload,TRUE));
$oldpath = 'temp/'.$upload['name'];
$newpath = $typePath.'/'.$upload['name'];
$oldpath = e_MEDIA."temp/".$upload['name'];
$newpath = $this->checkDupe($oldpath,$typePath.'/'.$upload['name']);
//$info = $fl->get_file_info(e_MEDIA.$oldpath);
/*$upload_data = array( // not saved if 'noedit' is active.
'media_type' => $upload['type'],
'media_datestamp' => time(),
'media_url' => "{e_MEDIA}".$newpath,
'media_size' => $upload['size'],
'media_author' => USERID,
'media_usedby' => '',
'media_tags' => '',
'media_dimensions' => $info['img-width']." x ".$info['img-height']
);*/
// only one upload? Not sure what's the idea here
// we are currently creating one media item
if(!rename(e_MEDIA.$oldpath, e_MEDIA.$newpath))
if(!rename($oldpath, e_MEDIA.$newpath))
{
$mes->add("Couldn't move file from ".$oldpath." to ".$newpath, E_MESSAGE_ERROR);
return FALSE;
};
$img_data = $this->mediaData($newpath);
if(!varset($new_data['media_name']))
$img_data = $this->mediaData($newpath); // Basic File Info only
$img_data['media_name'] = $new_data['name'];
$img_data['media_caption'] = $new_data['media_caption'];
$img_data['media_category'] = $new_data['media_category'];
$img_data['media_description'] = $new_data['media_description'];
$img_data['media_tags'] = $new_data['media_tags'];
$img_data['media_userclass'] = 0;
$img_data['media_author'] = USERID;
if(!varset($img_data['media_name']))
{
$img_data['media_name'] = $upload['name'];
}
}
$mes->addDebug(print_a($img_data,TRUE));
return $img_data;
}
else
else // Update Only ?
{
$img_data = $this->mediaData($new_data['media_url']);
@@ -500,7 +572,9 @@ class media_admin_ui extends e_admin_ui
{
$tp = e107::getParser();
$oldpath = $tp->replaceConstants($new_data['media_url']);
$newpath = $typePath.'/'.$fname;
$newpath = $this->checkDupe($oldpath,$typePath.'/'.$fname);
if(!rename($oldpath, $newpath))
{
$mes->add("Couldn't move file from ".$oldpath." to ".str_replace('../', '', $newpath), E_MESSAGE_ERROR);
@@ -513,11 +587,33 @@ class media_admin_ui extends e_admin_ui
{
$img_data['media_name'] = basename($new_data['media_url']);
}
return $img_data;
}
return $img_data;
}
// Check for existing image path in db and rename if found.
function checkDupe($oldpath,$newpath)
{
$mes = e107::getMessage();
$tp = e107::getParser();
$f = e107::getFile()->get_file_info($oldpath,TRUE);
// $mes->addDebug("checkDupe(): newpath=".$newpath."<br />oldpath=".$oldpath."<br />".print_r($upload,TRUE));
if(file_exists($newpath) || e107::getDb()->db_Select("core_media","media_url = '".$tp->createConstants($newpath,'rel')."' LIMIT 1") )
{
// $mes->addWarning($newpath." already exists and was renamed during import.");
$file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension'];
$newpath = $this->getPath($f['mime']).'/'.$file;
}
return $newpath;
}
function beforeDelete($data, $id) // call before 'delete' is executed. - return false to prevent delete execution (e.g. some dependencies check)
{
return true;
@@ -730,22 +826,21 @@ class media_admin_ui extends e_admin_ui
$mes->add("Couldn't get file info from : ".$oldpath, E_MESSAGE_ERROR);
}
$newpath = $this->getPath($f['mime']).'/'.$file;
$newpath = $this->checkDupe($oldpath,$this->getPath($f['mime']).'/'.$file);
$newname = $tp->toDB($_POST['batch_import_name'][$key]);
$newdiz = $tp->toDB($_POST['batch_import_diz'][$key]);
// echo "oldpath=".$file;
//
// echo "<br />newpath=".$tp->createConstants($newpath,'rel');
// continue;
$f['fname'] = $file;
if(file_exists($newpath) || $sql->db_Select("core_media","media_url = '".$tp->createConstants($newpath,'rel')."' LIMIT 1") )
{
$mes->addWarning($newpath." already exists and was renamed during import.");
$file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension'];
$newpath = $this->getPath($f['mime']).'/'.$file;
}
/*
if(file_exists($newpath) || $sql->db_Select("core_media","media_url = '".$tp->createConstants($newpath,'rel')."' LIMIT 1") )
{
$mes->addWarning($newpath." already exists and was renamed during import.");
$file = $f['pathinfo']['filename']."_.".$f['pathinfo']['extension'];
$newpath = $this->getPath($f['mime']).'/'.$file;
}
*/

View File

@@ -1509,25 +1509,32 @@ class admin_newspost
".$frm->bbarea('news_extended', $val, 'extended', 'helpc')."
<!-- <div class='field-help'>".NWSLAN_83."</div> -->
</td>
</tr>
<tr>
<td>".NWSLAN_66.":</td>
<td>";
$text .= $frm->mediaUrl('news', NWSLAN_69);
$text .= "
</td>
</tr>
<tr>
<td>".NWSLAN_67.":</td>
<td>
";
</tr>";
/*
$text .= "
<tr>
<td>".NWSLAN_66.":</td>
<td>";
$text .= $frm->mediaUrl('news', NWSLAN_69);
$text .= "
</td>
</tr>";
*/
$text .= "
<tr>
<td>".NWSLAN_67.":<br />
".$frm->help(LAN_NEWS_23)."</td>
<td>
";
$text .= $frm->imagepicker('news_thumbnail', $_POST['news_thumbnail'],'','news');
$text .= "
<div class='field-help'>".LAN_NEWS_23."</div>
</td>
</tr>
</tbody>

View File

@@ -249,7 +249,7 @@ $text .= "
</tr>
<tr>
<td class='label'>".PRFLAN_214."</td>
<td class='control'>".$frm->imagepicker('sitelogo',$pref['sitelogo'],'-- No Image --')."</td>
<td class='control'>".$frm->imagepicker('sitelogo',$pref['sitelogo'],'_common')."</td>
</tr>
<tr>
<td class='label'>".PRFLAN_5."</td>

View File

@@ -145,12 +145,20 @@ class e_form
}
// FIXME - Dialog JS no more working, investigate
public function mediaUrl($category = '', $label = '')
public function mediaUrl($category = '', $label = '', $tagid='', $tabs=TRUE)
{
if($category) $category = '&amp;for='.$category;
if(!$label) $label = ' Upload an image or file';
$ret = "<a rel='external' class='e-dialog' href='".e_ADMIN_ABS."image.php?mode=main&amp;action=create{$category}'>".$label."</a>";
if($tagid) $category .= '&amp;tagid='.$tagid;
// $tabs // TODO - option to choose which tabs to display.
//TODO Parse selection data back to parent form.
$url = e_ADMIN_ABS."image.php?mode=main&amp;action=dialog".$category;
$ret = "<a title='Click to Change' rel='external' class='e-dialog' href='".$url."'>".$label."</a>";
if(!e107::getRegistry('core/form/mediaurl'))
{
e107::getJs()->requireCoreLib('core/admin.js')
@@ -165,7 +173,8 @@ class e_form
new e107Widgets.URLDialog(element.href + "&iframe=1", {
id: element["id"] || "e-dialog",
width: 900,
height: 550
height: 600
}).center().activate().show();
});
');
@@ -194,8 +203,50 @@ class e_form
*/
function imagepicker($name, $default, $label = '', $sc_parameters = '')
{
$sql = e107::getDb();
$tp = e107::getParser();
$name_id = $this->name2id($name);
if(is_string($sc_parameters))
{
if(strpos($sc_parameters, '=') === false) $sc_parameters = 'media='.$sc_parameters;
parse_str($sc_parameters, $sc_parameters);
}
$default_thumb = $default;
if($default)
{
if('{' != $default[0])
{
// convert to sc path
$default_thumb = $tp->createConstants($default, 'nice');
$default = $tp->createConstants($default, 'mix');
}
$default_url = $tp->replaceConstants($default, 'abs');
}
else
{
$default = $default_url = e_IMAGE_ABS."generic/blank.gif";
}
//$width = intval(vartrue($sc_parameters['width'], 150));
$ret = "<div class='imgselector-container' style='display:block;width:120px;min-height:100px'>";
$att = 'aw=120&ah=100';
$thpath = isset($sc_parameters['nothumb']) || $hide ? $default : $tp->thumbUrl($default_thumb, $att, true);
$label = "<img id='{$name_id}_prev' src='{$default_url}' alt='{$default_url}' class='image-selector' style='width:120px;height:100px;border:1px dashed black;' />";
$cat = $tp->toDB($sc_parameters['media']);
$ret .= $this->mediaUrl($cat, $label,$name_id);
$ret .= "</div>\n";
$ret .= "<input type='hidden' name='{$name}' id='{$name_id}' value='{$default}' />"; // to be hidden eventually.
// $ret .= $this->text($name,$default); // to be hidden eventually.
return $ret;
// ---------------- OLD DROPDOWN METHOD BELOW -----------------------------
$tp = e107::getParser();
$sql = e107::getDb();
if(is_string($sc_parameters))
{

View File

@@ -247,6 +247,7 @@ class e_media
/**
* Return the total number of Images in a particular category
*
*/
public function countImages($cat)
{
@@ -257,14 +258,26 @@ class e_media
/**
* Return an array of Images in a particular category
* @param string $cat : category name. use + to include _common eg. 'news+'
*/
public function getImages($cat, $from=0, $amount=null)
public function getImages($cat='', $from=0, $amount=null)
{
if(!$cat) return;
$inc = array();
if(strpos($cat,"+") || !$cat)
{
$cat = str_replace("+","",$cat);
$inc[] = "media_category = '_common' ";
}
if($cat)
{
$inc[] = "media_category = '".$cat."' ";
}
// TODO check the category is valid.
// TODO check userclasses.
$ret = array();
$query = "SELECT * FROM #core_media WHERE media_category = '".$cat."' ORDER BY media_name";
$query = "SELECT * FROM #core_media WHERE media_userclass IN (".USERCLASS_LIST.") AND ( ".implode(" OR ",$inc) ;
$query .= " ) ORDER BY media_datestamp DESC";
if($amount)
{
@@ -318,5 +331,38 @@ class e_media
return $text;
}
public function mediaSelect($cat='',$tagid=null,$att=null)
{
$cat = ($cat) ? $cat."+" : "";
$images = $this->getImages($cat);
$att = 'aw=120&ah=100';
$name = $tagid;
$prevId = $name."_prev";
foreach($images as $im)
{
$realPath = e107::getParser()->thumbUrl($im['media_url'], $att);
$diz = e107::getParser()->toAttribute($im['media_title']);
$onclick = "onclick =\"
parent.document.getElementById('{$tagid}').value = '{$im['media_url']}';
parent.document.getElementById('".$prevId."').src = '{$realPath}';
parent.window.close();
return false; \"";
//FIXME Make Window Close automatically when selection is made.
$text .= "<a class='media-select' title=\"".$diz."\" href='#' {$onclick} >";
$text .= "<img src='".e107::getParser()->thumbUrl($im['media_url'], $att)."' alt=\"".$im['media_title']."\" />";
$text .= "</a>";
}
return $text;
}
}