1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 11:50:30 +02:00

Media-manager path and query fixes. Intuitive LEFT JOIN support for admin_ui.

This commit is contained in:
CaMer0n
2011-05-07 06:22:44 +00:00
parent a993bcc056
commit 8ef5c43753
5 changed files with 118 additions and 43 deletions

View File

@@ -106,7 +106,7 @@ class media_cat_ui extends e_admin_ui
// protected $editQry = "SELECT * FROM #faq_info WHERE faq_info_id = {ID}";
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
//'checkboxes' => array('title'=> '', 'type' => null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'media_cat_id' => array('title'=> LAN_ID, 'type' => 'number', 'width' =>'5%', 'forced'=> TRUE, 'readonly'=>TRUE),
'media_cat_nick' => array('title'=> "Nickname", 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE),
'media_cat_title' => array('title'=> LAN_TITLE, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readonly'=>TRUE),
@@ -214,7 +214,7 @@ class media_admin_ui extends e_admin_ui
protected $pluginName = 'core';
protected $table = "core_media";
// protected $listQry = "SELECT * FROM #core_media"; // without any Order or Limit.
protected $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 "; // without any Order or Limit.
// //protected $editQry = "SELECT * FROM #comments WHERE comment_id = {ID}";
@@ -236,20 +236,19 @@ class media_admin_ui extends e_admin_ui
protected $fields = array(
'checkboxes' => array('title'=> '', 'type' => null, 'data'=> null, 'width' =>'5%', 'forced'=> TRUE, 'thclass'=>'center', 'class'=>'center'),
'media_id' => array('title'=> LAN_ID, 'type' => 'number', 'data'=> 'int', 'width' =>'5%', 'forced'=> TRUE, 'nolist'=>TRUE),
'media_url' => array('title'=> 'Preview', 'type' => 'image', 'data'=> 'str', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60', 'writeParams' => 'path={e_MEDIA}', 'width' => '110px','readonly'=>false),
'media_url' => array('title'=> 'Preview', 'type' => 'image', 'data'=> 'str', 'thclass' => 'center', 'class'=>'center', 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','readonly'=>TRUE, 'writeParams' => 'path={e_MEDIA}', 'width' => '110px','readonly'=>false),
'media_category' => array('title'=> LAN_CATEGORY, 'type' => 'method', 'data'=> 'str', 'width' => 'auto', 'filter' => true, 'batch' => true,),
// 'media_preview' => array('title'=> "Preview", 'type' => 'image', 'data'=> null, 'width' => '10%'),
'media_upload' => array('title'=> "Upload File", 'type' => 'upload', 'data'=> false, 'readParm' => 'hidden', 'width' => '10%', 'nolist' => true),
// Upload should be managed completely separately via upload-handler.
// 'media_upload' => array('title'=> "Upload File", 'type' => 'upload', 'data'=> false, 'readParm' => 'hidden', 'width' => '10%', 'nolist' => true),
'media_name' => array('title'=> LAN_TITLE, 'type' => 'text', 'data'=> 'str', 'width' => 'auto'),
'media_caption' => array('title'=> "Caption", 'type' => 'text', 'data'=> 'str', 'width' => 'auto'),
'media_description' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'data'=> 'str', 'width' => 'auto', 'thclass' => 'left first', 'readParms' => 'truncate=100', 'writeParms' => 'counter=0'),
'media_category' => array('title'=> LAN_CATEGORY, 'type' => 'method', 'data'=> 'str', 'width' => 'auto', 'filter' => true, 'batch' => true,),
'media_type' => array('title'=> "Mime Type", 'type' => 'text', 'data'=> 'str', 'width' => 'auto', 'noedit'=>TRUE),
// 'media_author' => array('title'=> LAN_AUTHOR, 'type' => 'user', 'data'=> 'int'),
'media_author' => array('title'=> LAN_USER, 'type' => 'user', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center', 'filter' => true, 'batch' => true, 'noedit'=>TRUE ),
'media_type' => array('title'=> "Mime Type", 'type' => 'text', 'data'=> 'str', 'width' => 'auto', 'noedit'=>TRUE),
'media_author' => array('title'=> LAN_USER, 'type' => 'user', 'data'=> 'int', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center','readParms' => 'link=1', 'filter' => true, 'batch' => true, 'noedit'=>TRUE ),
'media_datestamp' => array('title'=> LAN_DATESTAMP, 'type' => 'datestamp', 'data'=> 'int', 'width' => '10%', 'noedit'=>TRUE), // User date
'media_size' => array('title'=> "Size", 'type' => 'number', 'data'=> 'int', 'width' => 'auto', 'noedit'=>TRUE),
'media_dimensions' => array('title'=> "Dimensions", 'type' => 'text', 'data'=> 'str', 'width' => '5%', 'noedit'=>TRUE, 'class'=>'nowrap'),
'media_dimensions' => array('title'=> "Dimensions", 'type' => 'text', 'data'=> 'str', 'width' => '5%', 'readonly'=>TRUE, 'class'=>'nowrap'),
'media_userclass' => array('title'=> LAN_USERCLASS, 'type' => 'userclass', 'data'=> 'str', 'width' => '10%', 'thclass' => 'center','filter'=>TRUE,'batch'=>TRUE ),
'media_tags' => array('title'=> "Tags/Keywords", 'type' => 'text', 'data'=> 'str', 'width' => '10%', 'filter'=>TRUE,'batch'=>TRUE ),
'media_usedby' => array('title'=> '', 'type' => 'text', 'data'=> 'text', 'width' => 'auto', 'thclass' => 'center', 'class'=>'center', 'nolist'=>true, 'readonly'=>TRUE ),
@@ -257,14 +256,15 @@ class media_admin_ui extends e_admin_ui
'options' => array('title'=> LAN_OPTIONS, 'type' => null, 'data'=> null, 'forced'=>TRUE, 'width' => '10%', 'thclass' => 'center last', 'class' => 'center')
);
protected $mimePaths = array(
'text' => 'files',
'multipart' => 'files',
'application' => 'files',
'audio' => 'audio',
'image' => 'images',
'video' => 'video',
'other' => 'files'
'text' => e_MEDIA_FILE,
'multipart' => e_MEDIA_FILE,
'application' => e_MEDIA_FILE,
'audio' => e_MEDIA_AUDIO,
'image' => e_MEDIA_IMAGE,
'video' => e_MEDIA_VIDEO,
'other' => e_MEDIA_FILE
);
// protected $fieldpref = array('checkboxes','media_url', 'media_id', 'media_thumb', 'media_title', 'media_caption', 'media_description', 'media_category', 'media_datestamp','media_userclass', 'options');
@@ -386,7 +386,7 @@ class media_admin_ui extends e_admin_ui
$fl = e107::getFile();
$mes = e107::getMessage();
if(vartrue($_FILES['file_userfile']))
{
$pref['upload_storagetype'] = "1";
@@ -438,18 +438,22 @@ class media_admin_ui extends e_admin_ui
}
else
{
$img_data = $this->mediaData($new_data['media_url']);
if(!($typePath = $this->getPath($img_data['media_type'])))
{
return FALSE;
}
$fname = basename($new_data['media_url']);
// move to the required place
if(strpos($new_data['media_url'], '{e_MEDIA}temp/') !== FALSE)
{
$tp = e107::getParser();
$oldpath = $tp->replaceConstants($new_data['media_url']);
$newpath = e_MEDIA.$typePath.'/'.$fname;
$newpath = $typePath.'/'.$fname;
if(!rename($oldpath, $newpath))
{
$mes->add("Couldn't move file from ".$oldpath." to ".str_replace('../', '', $newpath), E_MESSAGE_ERROR);
@@ -463,6 +467,7 @@ class media_admin_ui extends e_admin_ui
$img_data['media_name'] = basename($new_data['media_url']);
}
}
return $img_data;
}
@@ -488,11 +493,11 @@ class media_admin_ui extends e_admin_ui
return FALSE;
}
$dir = $this->mimePaths[$pmime]."/".date("Y-m");
$dir = $this->mimePaths[$pmime].date("Y-m");
if(!is_dir(e_MEDIA.$dir))
if(!is_dir($dir))
{
if(!mkdir(e_MEDIA.$dir, 0755))
if(!mkdir($dir, 0755))
{
$mes->add("Couldn't create folder ($dir).", E_MESSAGE_ERROR);
return FALSE;
@@ -539,7 +544,7 @@ class media_admin_ui extends e_admin_ui
<tr>
<th class='center'>".e107::getForm()->checkbox_toggle('e-column-toggle', 'batch_selected')."</th>
<th class='center' style='width:50px'>Preview</th>
<th class='center'>".LAN_NAME."</th>
<th class='center'>".LAN_FILE."</th>
<th>Mime Type</th>
<th>File Size</th>
<th>".LAN_DATESTAMP."</th>
@@ -589,13 +594,13 @@ class media_admin_ui extends e_admin_ui
$fl = e107::getFile();
$mes = e107::getMessage();
$sql = e107::getDb();
$tp = e107::getParser();
foreach($_POST['batch_selected'] as $file)
{
$oldpath = "temp/".$file;
$oldpath = e_MEDIA."temp/".$file;
$f = $fl->get_file_info(e_MEDIA.$oldpath);
$f = $fl->get_file_info($oldpath);
if(!$f['mime'])
{
@@ -604,25 +609,29 @@ class media_admin_ui extends e_admin_ui
$newpath = $this->getPath($f['mime']).'/'.$file;
// echo "oldpath=".$file;
//
// echo "<br />newpath=".$tp->createConstants($newpath,'rel');
// continue;
$f['fname'] = $file;
if(rename(e_MEDIA.$oldpath,e_MEDIA.$newpath))
if(rename($oldpath,$newpath))
{
$insert = array(
'media_caption' => $f['fname'],
'media_description' => '',
'media_category' => $_POST['batch_category'],
'media_datestamp' => $f['modified'],
'media_url' => "{e_MEDIA}".$newpath,
'media_url' => $tp->createConstants($newpath,'rel'),
'media_userclass' => 0,
'media_name' => $f['fname'],
'media_author' => USERID,
'media_size' => $f['fsize'],
'media_name' => $f['fname'],
'media_author' => USERID,
'media_size' => $f['fsize'],
'media_dimensions' => $f['img-width']." x ".$f['img-height'],
'media_usedby' => '',
'media_tags' => '',
'media_type' => $f['mime']
'media_usedby' => '',
'media_tags' => '',
'media_type' => $f['mime']
);
@@ -632,7 +641,7 @@ class media_admin_ui extends e_admin_ui
}
else
{
rename(e_MEDIA.$newpath,e_MEDIA.$oldpath); //move it back.
rename($newpath,$oldpath); //move it back.
}
}
}

View File

@@ -18,6 +18,7 @@ function imageselector_shortcode($parm = '', $mod = '')
list($name, $path, $default, $width, $height, $multiple, $label, $subdirs, $filter, $fullpath, $click_target, $click_prefix, $click_postfix, $tabindex, $class) = explode(",", $parm);
}
$paths = explode("|", $path);
if (trim($default[0]) == "{")
@@ -81,14 +82,14 @@ function imageselector_shortcode($parm = '', $mod = '')
$text .= '<div id="'.$name_id.'_cont">';
}
$text .= "<select{$multi}{$tabindex}{$class} name='{$name}' id='{$name_id}' onchange=\"replaceSC('imagepreview={$name}|{$width}|{$height}',this.form,'{$name_id}_prev'); \">
$text .= "\n<select{$multi}{$tabindex}{$class} name='{$name}' id='{$name_id}' onchange=\"replaceSC('imagepreview={$name}|{$width}|{$height}',this.form,'{$name_id}_prev'); \">
<option value=''>".$label."</option>\n";
require_once(e_HANDLER.'admin_handler.php');
foreach ($imagelist as $imagedirlabel => $icons)
{
if(!vartrue($parms['media'])) $imagedirlabel = str_replace('../', '', $tp->replaceConstants($imagedirlabel));
$text .= "<optgroup label='".$imagedirlabel."'>";
$text .= "<optgroup label='".$imagedirlabel."'>\n";
if (empty($icons)) $text .= "<option value=''>Empty</option>\n";
else
{
@@ -124,7 +125,7 @@ function imageselector_shortcode($parm = '', $mod = '')
}
}
}
$text .= '</optgroup>';
$text .= '</optgroup>\n';
}
$text .= "</select>";
$text .= "<a href='#' onclick=\"replaceSC('imageselector=".rawurlencode($parm)."&saction=select',\$('{$name_id}').up('form'),'{$name_id}_cont'); return false;\">refresh</a>";

View File

@@ -1991,6 +1991,13 @@ class e_admin_controller_ui extends e_admin_controller
* @var array
*/
protected $tableJoin = array();
/**
* Array of table names and their aliases. (detected from listQry)
* db query building
* @var array
*/
protected $joinAlias = array();
/**
* Main model table alias
@@ -2761,6 +2768,9 @@ class e_admin_controller_ui extends e_admin_controller
protected function parseAliases()
{
if($this->_alias_parsed) return $this; // already parsed!!!
if($this->getJoinData())
{
foreach ($this->getJoinData() as $table => $att)
@@ -2785,12 +2795,16 @@ class e_admin_controller_ui extends e_admin_controller
}
}
$this->joinAlias(); // generate Table Aliases from listQry
// check for table & field aliases
$fields = array(); // preserve order
foreach ($this->fields as $field => $att)
{
// tableAlias.fieldName.fieldAlias
if(strpos($field, '.') !== false)
if(strpos($field, '.') !== false) // manually entered alias.
{
$tmp = explode('.', $field, 3);
$att['table'] = $tmp[0] ? $tmp[0] : $this->getIfTableAlias(false);
@@ -2802,8 +2816,16 @@ class e_admin_controller_ui extends e_admin_controller
}
else
{
$att['table'] = $this->getIfTableAlias(false);
$att['alias'] = '';
if(isset($this->joinAlias[$this->table]) && $field !='checkboxes' && $field !='options')
{
$att['alias'] = $this->joinAlias[$this->table].".".$field;
}
else
{
$att['alias'] = "";
}
$att['field'] = $field;
$fields[$field] = $att;
}
@@ -2834,11 +2856,39 @@ class e_admin_controller_ui extends e_admin_controller
$fields[$field]['__tableField'] = '`'.$this->getTableName(false, true).'`.'.$field;
}*/
}
$this->fields = $fields;
$this->_alias_parsed = true;
return $this;
}
/**
* Intuitive LEFT JOIN Qry support. (preferred)
* Generate array of table names and their alias - auto-detected from listQry;
* eg. $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";
*/
protected function joinAlias()
{
//TODO - editQry
// TODO - auto-detect fields that belong to other tables. eg. u.user_id,u.user_name and adjust query to suit.
if($this->listQry)
{
preg_match_all("/`?#([\w-]+)`?\s*(as|AS)\s*([\w-])/im",$this->listQry,$matches);
foreach($matches[1] AS $k=>$v)
{
if(varset($matches[3][$k]))
{
$this->joinAlias[$v] = $matches[3][$k]; // array. eg $this->joinAlias['core_media'] = 'm';
}
}
}
}
// TODO - abstract, array return type, move to parent?
protected function _modifyListQry($raw = false, $isfilter = false, $forceFrom = false, $forceTo = false, $listQry = '')
{
@@ -2851,7 +2901,7 @@ class e_admin_controller_ui extends e_admin_controller
$tableSFieldsArr = array(); // FROM for main table
$tableSJoinArr = array(); // FROM for join tables
$filter = array();
$searchQuery = $tp->toDB($request->getQuery('searchquery', ''));
$searchFilter = $this->_parseFilterRequest($request->getQuery('filter_options', ''));
list($filterField, $filterValue) = $searchFilter;
@@ -2861,6 +2911,7 @@ class e_admin_controller_ui extends e_admin_controller
$searchQry[] = $this->fields[$filterField]['__tableField']." = '".$filterValue."'";
}
// main table should select everything
$tableSFieldsArr[] = $tablePath.'*';
foreach($this->getFields() as $key => $var)
@@ -2885,10 +2936,13 @@ class e_admin_controller_ui extends e_admin_controller
if($isfilter)
{
$filterFrom[] = $var['__tableField'];
}
}
}
if($isfilter)
{
if(!$filterFrom) return false;
@@ -3039,7 +3093,10 @@ class e_admin_controller_ui extends e_admin_controller
if(false === $forceTo) $forceTo = $this->getPerPage();
$qry .= ' LIMIT '.$from.', '.intval($forceTo);
}
// Debug Filter Query.
// echo $qry;
return $qry;
}
@@ -4225,6 +4282,10 @@ class e_admin_form_ui extends e_form
continue;
}
break;
case 'user': // TODO - User Filter
//$option[$key.'__'.$k] = $name;
break;
}
if(count($option) > 0)

View File

@@ -1216,12 +1216,14 @@ class e_form
*/
function renderValue($field, $value, $attributes, $id = 0)
{
$parms = array();
if(isset($attributes['readParms']))
{
if(!is_array($attributes['readParms'])) parse_str($attributes['readParms'], $attributes['readParms']);
$parms = $attributes['readParms'];
}
$tp = e107::getParser();
switch($field) // special fields
{

View File

@@ -317,6 +317,8 @@ define("LAN_DESCRIPTION", "Description");
define("LAN_VISIBILITY", "Visibility");
define("LAN_ICON", "Icon");
define("LAN_LOADING", "Loading...");
define("LAN_FILE", "File");
define("LAN_SECURITYL_0", "Looking for troubles (none)");
define("LAN_SECURITYL_5", "Balanced");