1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 04:38:27 +01:00

Some banner plugin work. imagepicker() may now be customized in preview size.

This commit is contained in:
Cameron 2013-03-09 19:22:30 -08:00
parent 269bdb8ebb
commit ac0ce7e98c
13 changed files with 110 additions and 53 deletions

View File

@ -541,13 +541,15 @@ class media_form_ui extends e_admin_form_ui
$bbcode = (vartrue($_GET['bbcode']) == 'file') ? "file" : "";
// $save = ($_GET['bbcode']!='file') ? "e-dialog-save" : "";
// e-dialog-close
$text = $this->renderValue('options',$value,'',$id);
// File Picker.
if($_GET['action'] == 'dialog')
{
$text .= "<input type='button' value='Select' data-placement='left' class='e-media-select e-dialog-save e-dialog-close btn' data-id='{$id}' data-name=\"".$title."\" data-target='{$tagid}' data-bbcode='{$bbcode}' data-path='{$path}' data-preview='{$preview}' title=\"".$title."\" />";
$text = "<input type='button' value='Select' data-placement='left' class='e-media-select e-dialog-save e-dialog-close btn btn-primary btn-large' data-id='{$id}' data-name=\"".$title."\" data-target='{$tagid}' data-bbcode='{$bbcode}' data-path='{$path}' data-preview='{$preview}' title=\"".$title."\" />";
}
$text .= $this->renderValue('options',$value,'',$id);
return "<div class='nowrap'>".$text."</div>";
@ -906,6 +908,7 @@ class media_admin_ui extends e_admin_ui
$file = (substr($cat,-5) == "_file") ? TRUE : FALSE;
$mes = e107::getMessage();
$mes->addDebug("For:".$cat);
if($file)
{
@ -958,7 +961,10 @@ class media_admin_ui extends e_admin_ui
function mediaSelectUpload($type='image')
{
$frm = e107::getForm();
$bbcodeMode = ($this->getQuery('bbcode')=='img') ? 'bbcode=img' : FALSE;
$options = array();
$options['bbcode'] = ($this->getQuery('bbcode')=='img') ? 'img' : FALSE;
$text = "
@ -966,16 +972,18 @@ class media_admin_ui extends e_admin_ui
<li class='active'><a data-toggle='tab' href='#core-media-select'>Choose from Library</a></li>
<li><a data-toggle='tab' href='#core-media-upload'>Upload a File</a></li>";
if($bbcodeMode)
if($options['bbcode'])
{
$text .= "<li><a data-toggle='tab' href='#core-media-style'>Appearance</a></li>\n";
}
if($_GET['from'])
{
$bbcodeMode .= "&from=".intval($_GET['from']);
$options['from'] .= intval($_GET['from']);
}
$text .= "
</ul>
@ -986,7 +994,12 @@ class media_admin_ui extends e_admin_ui
";
$tag = ($bbcodeMode) ? "" : $this->getQuery('tagid');
$tag = ($options['bbcode']) ? "" : $this->getQuery('tagid');
if($_GET['w'])
{
$options['w'] = intval($_GET['w']);
}
if($type == 'file')
{
@ -996,7 +1009,7 @@ class media_admin_ui extends e_admin_ui
}
else
{
$text .= e107::getMedia()->mediaSelect($this->getQuery('for'),$this->getQuery('tagid'),$bbcodeMode); // eg. news, news-thumbnail
$text .= e107::getMedia()->mediaSelect($this->getQuery('for'),$this->getQuery('tagid'), $options); // eg. news, news-thumbnail
}
$text .= "
@ -1022,7 +1035,7 @@ class media_admin_ui extends e_admin_ui
*
*/
if($bbcodeMode)
if($options['bbcode'])
{
$text .= "<div class='tab-pane' id='core-media-style'>
<legend>Appearance</legend>
@ -1076,7 +1089,7 @@ class media_admin_ui extends e_admin_ui
$text .= "</div>";
// For BBCODE mode. //TODO image-float.
if($bbcodeMode)
if($options['bbcode'])
{

View File

@ -292,26 +292,34 @@ class e_form
/**
* Internal Function used by imagepicker and filepicker
*/
private function mediaUrl($category = '', $label = '', $tagid='', $extras='')
private function mediaUrl($category = '', $label = '', $tagid='', $extras=null)
{
$cat = ($category) ? '&amp;for='.$category : "";
if(!$label) $label = ' Upload an image or file';
if($tagid) $cat .= '&amp;tagid='.$tagid;
parse_str($extras);
if(is_string($extras))
{
parse_str($extras,$extras);
}
if(vartrue($bbcode)) $cat .= '&amp;bbcode=1';
if(!vartrue($mode)) $mode = 'main';
if(!vartrue($action)) $action = 'dialog';
if(vartrue($extras['bbcode'])) $cat .= '&amp;bbcode=1';
$mode = vartrue($extras['mode'],'main');
$action = vartrue($extras['action'],'dialog');
// $tabs // TODO - option to choose which tabs to display.
//TODO Parse selection data back to parent form.
$url = e_ADMIN_ABS."image.php?mode={$mode}&amp;action={$action}".$cat;
$url .= "&amp;iframe=1";
if(vartrue($extras['w']))
{
$url .= "&amp;w=".$extras['w'];
}
$title = "Media Manager : ".$category;
$ret = "<a title=\"{$title}\" rel='external' class='e-dialog' href='".$url."'>".$label."</a>"; // using colorbox.
@ -441,21 +449,18 @@ class e_form
/**
* FIXME - better GUI, {IMAGESELECTOR} rewrite, flexibility, thumbnails, tooltip image preivew, etc.
* FIXME - use the media-manager as an image selector.
* SC Parameter list:
* - media: if present - load from media table
* - path: server pats to be listed (separated by |) - only if 'media' param is not present
* - subdirs: folder search depth (default is 10)
* - width: preview width in pixels
* - height: preview height in pixels
* Additional usage is <code>$sc_parameters = 'news'</code>
* where
* Full list can be found in shortcodes/imageselector.php
* FIXME {IMAGESELECTOR} rewrite
* @param string $name input name
* @param string $default default value
* @param string $label custom label
* @param string $sc_parameters shortcode parameters
* --- SC Parameter list ---
* - media: if present - load from media table
* - w: preview width in pixels
* - h: preview height in pixels
* @example $frm->imagepicker('banner_image', $_POST['banner_image'], '', 'banner'); // all images from category 'banner_image' + common images.
* @example $frm->imagepicker('banner_image', $_POST['banner_image'], '', 'media=banner&w=600');
* @return string html output
*/
function imagepicker($name, $default, $label = '', $sc_parameters = '')
@ -483,14 +488,14 @@ class e_form
else
{
//$default = $default_url = e_IMAGE_ABS."generic/blank.gif";
$default_url = e_IMAGE_ABS."generic/blank.gif";
$default_url = e_IMAGE_ABS."generic/nomedia.png";
$blank = TRUE;
}
//$width = intval(vartrue($sc_parameters['width'], 150));
$cat = $tp->toDB(vartrue($sc_parameters['media']));
if($cat == '_icon')
if($cat == '_icon') // ICONS
{
$ret = "<div class='imgselector-container' style='display:block;width:64px;min-height:64px'>";
$thpath = isset($sc_parameters['nothumb']) || vartrue($hide) ? $default : $default_thumb;
@ -498,21 +503,27 @@ class e_form
$label = "<img id='{$name_id}_prev' src='{$default_url}' alt='{$default_url}' class='image-selector' style='{$style}' />";
}
else
else // Images
{
$title = (vartrue($sc_parameters['help'])) ? "title='".$sc_parameters['help']."'" : "";
$width = vartrue($sc_parameters['w'], 120);
$height = vartrue($sc_parameters['h'], 100);
$ret = "<div class='imgselector-container e-tip' {$title} style='display:block;width:120px;min-height:100px'>";
$att = 'aw=120&ah=100';
$ret = "<div class='imgselector-container e-tip' {$title} style='display:block;width:".$width."px;min-height:".$height."px;'>";
$att = 'aw='.$width."'&ah=".$height."'";
$thpath = isset($sc_parameters['nothumb']) || vartrue($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;' />";
$label = "<img id='{$name_id}_prev' src='{$default_url}' alt='{$default_url}' class='image-selector' style='display:block;border:1px dashed black;' />";
if($cat != 'news' && $cat !='page')
{
$cat = $cat . "_image";
}
}
$ret .= $this->mediaUrl($cat, $label,$name_id);
$ret .= $this->mediaUrl($cat, $label,$name_id,$sc_parameters);
$ret .= "</div>\n";
$ret .= "<input type='hidden' name='{$name}' id='{$name_id}' value='{$default}' />";
// $ret .= $this->text($name,$default); // to be hidden eventually.
@ -545,9 +556,12 @@ class e_form
$default_label = ($default) ? $default : "Choose a file";
$label = "<span id='{$name_id}_prev' class='btn btn-small'>".basename($default_label)."</span>";
$sc_parameters['mode'] = 'main';
$sc_parameters['action'] = 'dialog';
// $ret .= $this->mediaUrl($cat, $label,$name_id,"mode=dialog&action=list");
$ret .= $this->mediaUrl($cat, $label,$name_id,"mode=main&action=dialog");
$ret .= $this->mediaUrl($cat, $label,$name_id,$sc_parameters);
$ret .= "<input type='hidden' name='{$name}' id='{$name_id}' value='{$default}' style='width:400px' />";
return $ret;

View File

@ -361,12 +361,20 @@ class e_media
{
$cat = str_replace("+","",$cat);
// $inc[] = "media_category = '_common_image' ";
$inc[] = "media_category REGEXP '(^|,)(_common_image)(,|$)' ";
// $inc[] = "media_category REGEXP '(^|,)(_common_image)(,|$)' ";
// $inc[] = "media_category LIKE '%_common_image%' ";
$catArray[] = '_common_image';
}
if($cat)
{
$inc[] = "media_category REGEXP '(^|,)(".$cat.")(,|$)' "; // for multiple category field.
$catArray[] = $cat;
// $inc[] = "media_category LIKE '%".$cat."%' "; // for multiple category field.
// $inc[] = "media_category REGEXP '(^|,)(".$cat.")(,|$)' "; // for multiple category field.
}
// $inc[] = "media_category REGEXP '(^|,)_common_image|banner_image(,|$)' ";
// TODO check the category is valid.
if($search)
@ -379,22 +387,24 @@ class e_media
$ret = array();
$query = "SELECT * FROM #core_media WHERE media_userclass IN (".USERCLASS_LIST.") AND ( ".implode(" OR ",$inc)." ) " ;
// $query = "SELECT * FROM #core_media WHERE media_userclass IN (".USERCLASS_LIST.") AND ( ".implode(" OR ",$inc)." ) " ;
$query = "SELECT * FROM #core_media WHERE `media_category` REGEXP '(^|,)".implode("|",$catArray)."(,|$)' AND `media_userclass` IN (".USERCLASS_LIST.") " ;
if($search)
{
$query .= " AND ( ".implode(" OR ",$searchinc)." ) " ;
}
$query .= " ORDER BY media_datestamp DESC";
$query .= " ORDER BY media_id DESC";
if($amount)
{
$query .= " LIMIT ".$from." ,".$amount;
}
e107::getDb()->db_Select_gen($query);
while($row = e107::getDb()->db_Fetch(MYSQL_ASSOC))
e107::getDb()->gen($query);
while($row = e107::getDb()->fetch(MYSQL_ASSOC))
{
$id = $row['media_id'];
$ret[$id] = $row;
@ -503,7 +513,13 @@ class e_media
public function mediaSelect($category='',$tagid=null,$att=null)
{
parse_str($att,$option); // grab 'onclick' .
if(is_string($att))
{
parse_str($att,$option); // grab 'onclick' .
}
else {
$option = $att;
}
$frm = ($option['from']) ? $option['from'] : 0;
$limit = ($option['limit']) ? $option['limit'] : 20;
@ -511,8 +527,6 @@ class e_media
$bbcode = ($option['bbcode']) ? $option['bbcode'] : null;
$navMode = ($option['nav']) ? TRUE : FALSE;
$search = ($option['search']) ? $option['search'] : null;
if($category !='_icon')
{
@ -539,8 +553,9 @@ class e_media
// $total_images = $this->getImages($cat); // for use by next/prev in filter at some point.
$att = 'aw=120&ah=100';
$prevId = $tagid."_prev";
$prevAtt = '&aw='.vartrue($option['w'],$w); // .'&ah=100'; // Image Parsed back to Form as PREVIEW image.
$prevId = $tagid."_prev"; // ID of image in Form.
$thumbAtt = 'aw=120&ah=100'; // Thumbnail of the Media-Manager Preview.
// EXAMPLE of FILTER GUI.
// $text .= "CAT=".$cat;
@ -603,14 +618,16 @@ class e_media
$media_path : Inserted into html tags eg. <img src='here'...
*/
// print_a($images);
// return;
foreach($images as $im)
{
$class = ($category !='_icon') ? "media-select-image" : "media-select-icon";
$media_path = ($w || $h) ? $tp->thumbUrl($im['media_url'], "&w={$w}") : $tp->thumbUrl($im['media_url']); // $tp->replaceConstants($im['media_url'],'full'); // max-size
$realPath = $tp->thumbUrl($im['media_url'], $att);
$realPath = $tp->thumbUrl($im['media_url'], $prevAtt); // Parsed back to Form as Preview Image.
$diz = $tp->toAttribute($im['media_title'])."\n".$im['media_dimensions'];
$repl = array($im['media_url'],$media_path);
@ -637,7 +654,7 @@ class e_media
$data_bb = ($bbcode) ? "img" : "";
$img_url = ($cat !='_icon') ? e107::getParser()->thumbUrl($im['media_url'], $att) : $media_path;
$img_url = ($cat !='_icon') ? e107::getParser()->thumbUrl($im['media_url'], $thumbAtt) : $media_path;
$text .= "<a data-toggle='context' class='{$class} e-tip' data-id='{$im['media_id']}' data-width='{$w}' data-height='{$h}' data-src='{$media_path}' data-bbcode='{$data_bb}' data-target='{$tagid}' data-path='{$im['media_url']}' data-preview='{$realPath}' title=\"".$diz."\" style='float:left' href='#' onclick=\"{$onclicki}\" >";
$text .= "<img class='image-rounded' src='".$img_url."' alt=\"".$im['media_title']."\" title=\"{$diz}\" />";

View File

@ -1850,7 +1850,7 @@ class e107plugin
$data['class'] = 253;
$status = e107::getMedia()->createCategory($data) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$mes->add("Adding Media Category: {$data['category']}", $status);
e107::getMedia()->import($data['category'],e_PLUGIN.$folder, false,'min-size=20000');
$c++;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 973 B

View File

@ -497,7 +497,12 @@ if ($action == "create")
</tr>
<tr>
<td>".BNRLAN_14."</td>
<td>
<td>".$frm->imagepicker('banner_image', $_POST['banner_image'], '', 'media=banner&w=600');
/*
$text .= "
<div class='field-spacer'>
<button class='btn button action' type='button' value='no-value' onclick='e107Helper.toggle(\"banner-repo\")'><span>".BNRLAN_32."</span></button>
</div>
@ -542,7 +547,10 @@ if ($action == "create")
$c++;
}
$text .= "
</div>
</div>";
*/
$text .= "
</td>
</tr>
<tr>

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -12,4 +12,7 @@
<adminLinks>
<link url='admin_banner.php' description='Configure Banners' icon='images/banners_32.png' iconSmall='images/banners_16.png' primary='true' >Configure Banners</link>
</adminLinks>
<mediaCategories>
<category type="image">Banners</category>
</mediaCategories>
</e107Plugin>

View File

@ -165,6 +165,7 @@ $(document).ready(function()
//alert(bbpath);
}
$('#src').attr('value',src); // working old
$('#preview').attr('src',preview); // working old
@ -174,6 +175,7 @@ $(document).ready(function()
$('#width').val(width);
$('#height').val(height);
$('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