1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-19 04:41:53 +02:00
This commit is contained in:
secretr
2010-10-04 16:01:17 +00:00
parent 6bd63adc78
commit 5670e36937
3 changed files with 314 additions and 81 deletions

View File

@@ -0,0 +1,162 @@
<?php
// $Id: imageselector.sc 11438 2010-03-16 17:00:44Z secretr $
//FIXME - full rewrite, backward compatible
function imageselector_shortcode($parm = '', $mod = '')
{
$sql = e107::getDb('imageselector.sc');
$tp = e107::getParser();
if (strstr($parm, "="))
{ // query style parms.
parse_str($parm, $parms);
extract($parms);
}
else
{ // comma separated parms.
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]) == "{")
{
$pvw_default = $tp->replaceConstants($default, 'abs');
$path = ""; // remove the default path if a constant is used.
}
$scaction = varsettrue($scaction, 'all');
$text = '';
$name_id = e107::getForm()->name2id($name);
//Get Select Box Only!
if ($scaction == 'select' || $scaction == 'all')
{
$imagelist = array();
// Media manager support
if(vartrue($parms['media']))
{
$qry = "SELECT * FROM `#core_media` WHERE media_userclass IN (".USERCLASS_LIST.") ";
$qry .= vartrue($parms['media']) && $parms['media'] !== 'all' ? " AND media_category='".$tp->toDB($parms['media'])."' " : " AND `media_category` NOT REGEXP '_icon_16|_icon_32|_icon_48|_icon_64' ";
$qry .= " AND media_category REGEX '.jpg|.png|.gif' ORDER BY media_name";
// FIXME - media_type=image?
if($sql->db_Select_gen($qry))
{
while($row = $sql->db_Fetch())
{
//$imagelist[$row['media_category']][$row['media_url']] = $row['media_name']. " (".$row['media_dimensions'].") ";
$imagelist[$row['media_category']][] = array('path' => $row['media_url'], 'fname' => $row['media_name']. " (".$row['media_dimensions'].") ");
}
asort($opts);
}
}
else
{
//require_once(e_HANDLER."file_class.php");
$fl = e107::getFile(false);
$recurse = ($subdirs) ? $subdirs : 0;
foreach ($paths as $pths)
{
$imagelist[$tp->createConstants($pths, 'mix')] = $fl->get_files($pths, '\.jpg|\.gif|\.png|\.JPG|\.GIF|\.PNG', 'standard', $recurse);
}
if (!$fullpath && (count($paths) > 1))
{
$fullpath = TRUE;
}
}
$multi = ($multiple == "TRUE" || $multiple == "1") ? " multiple='multiple' style='height:{$height}'" : ""; //style='float:left'
$width = ($width) ? $width : "0";
$height = ($height) ? $height : "0";
$label = ($label) ? $label : " -- -- ";
$tabindex = varset($tabindex) ? " tabindex='{$tabindex}'" : '';
$class = varset($class) ? " class='{$class}'" : " class='tbox imgselector'";
$text .= "<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."'>";
if (empty($icons)) $text .= "<option value=''>Empty</option>\n";
else
{
$icons = multiarray_sort($icons, 'fname');
foreach ($icons as $icon)
{
$dir = str_replace($paths, "", $icon['path']);
if (!$filter || ($filter && ereg($filter, $dir.$icon['fname'])))
{
$pth = $dir;
if($fullpath)
{
$pth = !vartrue($parms['media']) ? $tp->createConstants($icon['path'], 'rel') : $icon['path'];
}
$selected = ($default == $pth.$icon['fname'] || $pth.$default == $pth.$icon['fname']) ? " selected='selected'" : "";
$text .= "<option value='{$pth}{$icon['fname']}'{$selected}>&nbsp;&nbsp;&nbsp;{$dir}{$icon['fname']}</option>\n";
}
}
}
$text .= '</optgroup>';
}
$text .= "</select>";
if ($scaction == 'select') return $text;
}
$hide = '';
if (!$pvw_default)
{
if ($default)
{
$test = pathinfo($default);
if ('.' == $test['dirname'])
{
// file only, add absolute path
$path = $tp->createConstants($path, 1);
$path = $tp->replaceConstants($path, 'abs');
$pvw_default = $path.$default;
}
else
{
// path, convert to absolute path
$pvw_default = $tp->createConstants($default, 1);
$pvw_default = $tp->replaceConstants($pvw_default, 'abs');
}
}
else
{
$pvw_default = e_IMAGE_ABS."generic/blank.gif";
$hide = ' style="display: none;"';
}
}
$text .= "<div class='imgselector-container' id='{$name_id}_prev'>";
if (varset($click_target))
{
$pre = varset($click_prefix);
$post = varset($click_postfix);
$text .= "<a href='#'{$hide} title='Select' onclick='addtext(\"{$pre}\"+document.getElementById(\"{$name_id}\").value+\"{$post}\", true);document.getElementById(\"{$name_id}\").selectedIndex = -1;return false;'>";
}
else
{
$text .= "<a href='{$pvw_default}'{$hide} rel='external' title='Preview {$pvw_default}' class='e-image-preview'>";
}
if (vartrue($height)) $height = intval($height);
if (vartrue($width)) $width = intval($width);
$thpath = isset($parms['nothumb']) || $hide ? $pvw_default : $tp->thumbUrl($pvw_default, 'w='.$width.'&h='.$height, true);
$text .= "<img src='{$thpath}' alt='$pvw_default' class='image-selector' /></a>";
$text .= "</div>\n";
return "\n\n<!-- Start Image Selector [{$scaction}] -->\n\n".$text."\n\n<!-- End Image Selector [{$scaction}] -->\n\n";
}