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

Media-Manager importing of files

This commit is contained in:
CaMer0n 2012-05-25 11:30:49 +00:00
parent 06df7308bb
commit e9811d8b8f
7 changed files with 170 additions and 100 deletions

View File

@ -53,6 +53,12 @@ class media_admin extends e_admin_dispatcher
'ui' => 'media_form_ui', 'ui' => 'media_form_ui',
'uipath' => null 'uipath' => null
), ),
'dialog' => array(
'controller' => 'media_admin_ui',
'path' => null,
'ui' => 'media_form_ui',
'uipath' => null
),
'cat' => array( 'cat' => array(
'controller' => 'media_cat_ui', 'controller' => 'media_cat_ui',
'path' => null, 'path' => null,
@ -197,8 +203,20 @@ class media_form_ui extends e_admin_form_ui
asort($this->cats);*/ asort($this->cats);*/
} }
function options()
{
//return print_a($_GET,true);
$tagid = $_GET['tagid'];
$path = $this->getController()->getListModel()->get('media_url');
$preview = basename($path);
$text .= "<input type='button' value='Select' class='button e-media-select e-dialog-close' data-target='{$tagid}' data-path='{$path}' data-preview='{$preview}' title=\"".$diz."\" style='float:left' href='#' />";
// $text .= "SELECT";
// $text .= "</a>\n\n";
return $text;
}
@ -337,6 +355,27 @@ class media_admin_ui extends e_admin_ui
$this->updateSettings(); $this->updateSettings();
} }
if($this->getQuery('mode') == 'dialog')
{
$cat = $_GET['for'];
$this->listQry = "SELECT m.*,u.user_id,u.user_name FROM #core_media AS m LEFT JOIN #user AS u ON m.media_author = u.user_id WHERE media_category = '".$cat."' "; // without any Order or Limit.
unset($this->fields['checkboxes']);
$this->fields['options']['type'] = 'method';
$this->fields['media_userclass']['nolist'] = true;
$this->fields['media_dimentions']['nolist'] = true;
$this->fields['media_description']['nolist'] = true;
$this->fields['media_type']['nolist'] = true;
foreach($this->fields as $k=>$v)
{
$this->fields[$k]['filter'] = false;
}
}
if($this->getQuery('iframe')) if($this->getQuery('iframe'))
{ {
if($this->getQuery('bbcode')) if($this->getQuery('bbcode'))
@ -397,6 +436,17 @@ class media_admin_ui extends e_admin_ui
function dialogPage() // Popup dialogPage for Image Selection. function dialogPage() // Popup dialogPage for Image Selection.
{ {
$cat = $this->getQuery('for');
$file = (substr($cat,-5) == "_file") ? TRUE : FALSE;
if($file)
{
echo $this->getUI()->getList();
return;
}
// $this->getModel()->setAction('create'); // $this->getModel()->setAction('create');
// $this->getUI()->getController()->getRequest()->setAction('create'); // $this->getUI()->getController()->getRequest()->setAction('create');
@ -404,8 +454,8 @@ class media_admin_ui extends e_admin_ui
if($_POST['etrigger_submit']) if($_POST['etrigger_submit'])
{ {
$data = $this->beforeCreate($_POST); // $data = $this->beforeCreate($_POST);
e107::getDb()->db_Insert('core_media',$data); // Replace with Generic (needs parm sent) // e107::getDb()->db_Insert('core_media',$data); // Replace with Generic (needs parm sent)
} }
echo $this->imageSelectUpload(); echo $this->imageSelectUpload();
} }
@ -467,8 +517,8 @@ class media_admin_ui extends e_admin_ui
$this->fields['media_url']['noedit'] = TRUE; $this->fields['media_url']['noedit'] = TRUE;
$this->fields['media_userclass']['noedit'] = TRUE; $this->fields['media_userclass']['noedit'] = TRUE;
// $text .= $this->uploadPage(); // To test upload script with plupload $text .= $this->uploadPage(); // To test upload script with plupload
$text .= $this->CreatePage(); // comment me out to test plupload // $text .= $this->CreatePage(); // comment me out to test plupload
$text .= " $text .= "
</fieldset>"; </fieldset>";

View File

@ -1119,6 +1119,36 @@ function update_706_to_800($type='')
$med->import('download_thumb',e_FILE.'downloadthumbs'); $med->import('download_thumb',e_FILE.'downloadthumbs');
} }
$dl_files = $fl->get_files(e_DOWNLOAD, "","standard",5);
$public_files = $fl->get_files(e_FILE.'public');
if((count($dl_files) || count($public_files)) && !$sql->db_Select_gen("SELECT * FROM `#core_media` WHERE `media_category` = 'download_file' "))
{
if ($just_check) return update_needed('Import Download and Public Files into Media Manager');
// check for file-types;
if (is_readable(e_ADMIN.'filetypes.php'))
{
$a_types = strtolower(trim(file_get_contents(e_ADMIN.'filetypes.php')));
$srch = array("png","jpg","jpeg","gif");
$a_types = str_replace($srch,"",$a_types); // filter-out images.
} else
{
$a_types = 'zip, gz, pdf';
}
$a_types = explode(',', $a_types);
foreach ($a_types as $f_type) {
$allowed_types[] = trim(str_replace('.', '', $f_type));
}
$fmask = '[a-zA-z0-9_-]+\.('.implode('|',$allowed_types).')$';
$med->import('download_file',e_DOWNLOAD, $fmask);
$med->import('_common_file',e_FILE.'public', $fmask);
}
$count = $sql->db_Select_gen("SELECT * FROM `#core_media_cat` WHERE media_cat_owner='_icon' "); $count = $sql->db_Select_gen("SELECT * FROM `#core_media_cat` WHERE media_cat_owner='_icon' ");

View File

@ -61,7 +61,7 @@ $(document).ready(function()
$("a.e-dialog").colorbox({ $("a.e-dialog").colorbox({
iframe:true, iframe:true,
width:"60%", width:"60%",
height:"65%", height:"70%",
speed:100 speed:100
}); });
@ -352,7 +352,7 @@ $(document).ready(function()
var opt = linkid.split('-'); var opt = linkid.split('-');
if(area == 'remove') if(area == 'remove')
{ alert(area); { // alert(area);
var remove = linkid; var remove = linkid;
areaList = ''; areaList = '';
$('#check-' + opt[1]).show('fast'); $('#check-' + opt[1]).show('fast');

View File

@ -98,7 +98,7 @@ $(document).ready(function()
$(".e-media-select").live("click", function(){ $(".e-media-select").live("click", function(){
// console.log(this); console.log(this);
@ -111,7 +111,9 @@ $(document).ready(function()
$(this).closest("img").addClass("active"); $(this).closest("img").addClass("active");
$('#' + target, window.top.document).attr('value',path); // set new value $('#' + target, window.top.document).attr('value',path); // set new value
$('#' + target + "_prev", window.top.document).attr('src',preview); // set new value $('img#' + target + "_prev", window.top.document).attr('src',preview); // set new value
$('div#' + target + "_prev", window.top.document).html(preview); // set new value
$('span#' + target + "_prev", window.top.document).html(preview); // set new value
$('#src').attr('value',src); // working old $('#src').attr('value',src); // working old
$('#preview').attr('src',preview); // working old $('#preview').attr('src',preview); // working old

View File

@ -144,21 +144,31 @@ class e_form
return $ret; return $ret;
} }
// FIXME - Dialog JS no more working, investigate /**
public function mediaUrl($category = '', $label = '', $tagid='', $bbcode='') * Internal Function used by imagepicker and filepicker
*/
private function mediaUrl($category = '', $label = '', $tagid='', $extras='')
{ {
$cat = ($category) ? '&amp;for='.$category : ""; $cat = ($category) ? '&amp;for='.$category : "";
if(!$label) $label = ' Upload an image or file'; if(!$label) $label = ' Upload an image or file';
if($tagid) $cat .= '&amp;tagid='.$tagid; if($tagid) $cat .= '&amp;tagid='.$tagid;
parse_str($extras);
if($bbcode) $cat .= '&amp;bbcode=1'; if($bbcode) $cat .= '&amp;bbcode=1';
if(!$mode) $mode = 'main';
if(!$action) $action = 'dialog';
// $tabs // TODO - option to choose which tabs to display. // $tabs // TODO - option to choose which tabs to display.
//TODO Parse selection data back to parent form. //TODO Parse selection data back to parent form.
$url = e_ADMIN_ABS."image.php?mode=main&amp;action=dialog".$cat; $url = e_ADMIN_ABS."image.php?mode={$mode}&amp;action={$action}".$cat;
$url .= "&amp;iframe=1"; $url .= "&amp;iframe=1";
$ret = "<a title='Click on a thumbnail to change..' rel='external' class='e-dialog' href='".$url."'>".$label."</a>"; $ret = "<a title=\"{$title}\" rel='external' class='e-dialog' href='".$url."'>".$label."</a>";
// $footer = "<div style=\'padding:5px;text-align:center\' <a href=\'#\' >Save</a></div>"; // $footer = "<div style=\'padding:5px;text-align:center\' <a href=\'#\' >Save</a></div>";
$footer = ''; $footer = '';
@ -263,87 +273,45 @@ class e_form
return $ret; return $ret;
// ---------------- OLD DROPDOWN METHOD BELOW -----------------------------
// ----------------
}
function filepicker($name, $default, $label = '', $sc_parameters = '')
{
$tp = e107::getParser(); $tp = e107::getParser();
$sql = e107::getDb(); $name_id = $this->name2id($name);
if(is_string($sc_parameters)) if(is_string($sc_parameters))
{ {
if(strpos($sc_parameters, '=') === false) $sc_parameters = 'media='.$sc_parameters; if(strpos($sc_parameters, '=') === false) $sc_parameters = 'media='.$sc_parameters;
parse_str($sc_parameters, $sc_parameters); parse_str($sc_parameters, $sc_parameters);
} }
$qry = "SELECT * FROM `#core_media` WHERE media_userclass IN (".USERCLASS_LIST.") "; $cat = $tp->toDB($sc_parameters['media']);
$default = ($default) ? $default : "Choose a file";
// Old Method $label = "<span id='{$name_id}_prev' >".$default."</span>";
$qry .= vartrue($sc_parameters['media']) ? " AND (`media_category` = '".$tp->toDB($sc_parameters['media'])."' OR `media_category` = '_common' )" : " AND `media_category` = '_common' ";
// New Method
/*
if(vartrue($sc_parameters['owner']) && vartrue($sc_parameters['cat']))
{
$ret .= $this->mediaUrl($cat, $label,$name_id,"mode=dialog&action=list");
$ret .= "<input type='hidden' name='{$name}' id='{$name_id}' value='{$default}' />";
$qry = "SELECT * FROM `#core_media` WHERE media_userclass IN (".USERCLASS_LIST.") ";
$qry .= " AND (`media_owner` = '".$tp->toDB($sc_parameters['owner'])."' AND `media_category` = '".$tp->toDB($sc_parameters['cat'])."' ) OR `media_owner` = '_common' ";
} */
$qry .= "ORDER BY media_name";
if($sql->db_Select_gen($qry))
{
while($row = $sql->db_Fetch())
{
$opts[$row['media_category']][$row['media_url']] = $row['media_name']. " (".$row['media_dimensions'].") ";
}
asort($opts);
$hide = $default_url = '';
$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";
$hide = ' style="display: none;"';
}
if(is_string($sc_parameters)) parse_str($sc_parameters, $sc_parameters);
$name_id = $this->name2id($name);
$width = intval(vartrue($sc_parameters['width'], 150));
$onchange = "onchange=\"replaceSC('imagepreview={$name}|{$width}',this.form,'{$name_id}_prev'); \"";
$ret = $this->selectbox($name, $opts, $default, array('default'=>'&nbsp;', 'other' => $onchange));
$ret .= "<div class='imgselector-container' id='{$name_id}_prev'>";
$ret .= "<a href='{$default_url}'{$hide} rel='external' title='Preview {$default_url}' class='e-image-preview'>";
$thpath = isset($sc_parameters['nothumb']) || $hide ? $default : $tp->thumbUrl($default_thumb, 'w='.$width, true);
$ret .= "<img src='{$thpath}' alt='{$default_url}' class='image-selector' /></a>";
$ret .= "</div>\n";
return $ret; return $ret;
}
// ----------------
} }
/** /**
* Date field with popup calendar * Date field with popup calendar // NEW in 0.8/2.0
* $options allowed keys: * $options allowed keys:
* - time: show time, default is true * - time: show time, default is true
* - others: ???, default is false * - others: ???, default is false
@ -356,6 +324,12 @@ class e_form
*/ */
function datepicker($name, $datestamp = false, $options = array()) function datepicker($name, $datestamp = false, $options = array())
{ {
// DHTML Calendar is deprecated in 2.0.
$cal = new DHTML_Calendar(true); $cal = new DHTML_Calendar(true);
$cal_options['showsTime'] = varset($options['time'], true); $cal_options['showsTime'] = varset($options['time'], true);
$cal_options['showOthers'] = varset($options['others'], false); $cal_options['showOthers'] = varset($options['others'], false);
@ -1537,6 +1511,14 @@ class e_form
case 'image': //TODO - thumb, js tooltip... case 'image': //TODO - thumb, js tooltip...
if($value) if($value)
{ {
if(!preg_match("/[a-zA-z0-9_-]+\.(png|jpg|jpeg|gif|PNG|JPG|JPEG|GIF)$/",$value))
{
$value = "{e_IMAGE}filemanager/zip_32.png";
$src = $tp->replaceConstants(vartrue($parms['pre']).$value, 'abs');
return '<img src="'.$src.'" alt="'.$alt.'" class="e-thumb" />';
}
if(vartrue($parms['thumb'])) if(vartrue($parms['thumb']))
{ {
$src = $tp->replaceConstants(vartrue($parms['pre']).$value, 'abs'); $src = $tp->replaceConstants(vartrue($parms['pre']).$value, 'abs');

View File

@ -67,8 +67,8 @@ class e_media
if(!count($img_array)){ return $this;} if(!count($img_array)){ return $this;}
//print_a($img_array); // print_a($img_array);
//return; // return;
foreach($img_array as $f) foreach($img_array as $f)
{ {
@ -430,6 +430,7 @@ class e_media
$newfrm = $frm + $limit; $newfrm = $frm + $limit;
$bbcode = ($option['bbcode']) ? $option['bbcode'] : null; $bbcode = ($option['bbcode']) ? $option['bbcode'] : null;
if($category !='_icon') if($category !='_icon')
{ {
$cat = ($category) ? $category."+" : ""; // the '+' loads category '_common' as well as the chosen category. $cat = ($category) ? $category."+" : ""; // the '+' loads category '_common' as well as the chosen category.

View File

@ -620,7 +620,7 @@ $columnInfo = array(
$text = " $text = "
<div class='admintabs' id='tab-container'> <div class='admintabs' id='tab-container'>
<ul class='e-tabs e-hideme' id='core-download-tabs'> <ul class='e-tabs' id='core-download-tabs'>
<li id='tab-general'><a href='#download-create'>".DOWLAN_175."</a></li> <li id='tab-general'><a href='#download-create'>".DOWLAN_175."</a></li>
<li id='tab-external'><a href='#download-edit-external'>".DOWLAN_176."</a></li> <li id='tab-external'><a href='#download-edit-external'>".DOWLAN_176."</a></li>
<li id='tab-mirror'><a href='#download-edit-mirror'>".DOWLAN_128."</a></li> <li id='tab-mirror'><a href='#download-edit-mirror'>".DOWLAN_128."</a></li>
@ -632,10 +632,11 @@ $columnInfo = array(
<tr> <tr>
<td style='width:20%;'>".DOWLAN_13."</td> <td style='width:20%;'>".DOWLAN_13."</td>
<td style='width:80%'> <td style='width:80%'>
<div>".DOWLAN_131."&nbsp;&nbsp; <div>".DOWLAN_131."&nbsp;&nbsp;";
<select name='download_url' class='tbox'>
<option value=''>&nbsp;</option> // $text .= "<select name='download_url' class='tbox'>
"; // <option value=''>&nbsp;</option>\n";
$counter = 0; $counter = 0;
while (isset($file_array[$counter])) while (isset($file_array[$counter]))
@ -648,7 +649,7 @@ $columnInfo = array(
$found = 1; $found = 1;
} }
$text .= "<option value='".$fpath."' $selected>".$fpath."</option>\n"; // $text .= "<option value='".$fpath."' $selected>".$fpath."</option>\n";
$counter++; $counter++;
} }
@ -666,10 +667,14 @@ $columnInfo = array(
if (!$found && $download_url) if (!$found && $download_url)
{ {
$text .= "<option value='".$download_url."' selected='selected'>".$download_url.$etext."</option>\n"; // $text .= "<option value='".$download_url."' selected='selected'>".$download_url.$etext."</option>\n";
} }
$text .= " </select> // $text .= " </select>";
$text .= e107::getForm()->filepicker("download_url",$download_url,DOWLAN_131,"media=download_file&title=Choose a file");
$text .= "
</div> </div>
</td> </td>
</tr> </tr>