1)
? PrevNextLink("image",$page-1,gTxt('prev'),'prev') : '';
$nav[] = sp.small($page. '/'.$numPages).sp;
$nav[] = ($page != $numPages)
? PrevNextLink("image",$page+1,gTxt('next'),'next') : '';
$rs = safe_rows_start("*", "txp_image", "1 order by $sort $dir limit $offset,$limit");
if($rs) {
while ($a = nextRow($rs)) {
extract($a);
$thumbnail = ($thumbnail)
? ''
: gTxt('no');
$elink = eLink('image','image_edit','id',$id,$name);
$txtilelink = 'Textile';
$txplink = 'Textpattern';
$xhtmlink = 'XHTML';
$dlink = dLink('image','image_delete','id',$id);
echo
tr(
// added $id
td($id).td($elink).td($category).td($txtilelink.' / '.$txplink.' / '.$xhtmlink).
td($author).
td($thumbnail).
td($dlink,10)
);
}
echo
tr(
tdcs(
graf(join('',$nav))
,4)
);
}
echo endTable();
if (!is_dir(IMPATH) or !is_writeable(IMPATH)) {
echo graf(str_replace("{imgdir}",IMPATH,gTxt('img_dir_not_writeable')),' style="text-align:center;color:red"');
}
}
// -------------------------------------------------------------
function image_edit($message='',$id='')
{
if (!$id) $id = gps('id');
global $txpcfg,$img_dir;
pagetop('image',$message);
$categories = getTree("root", "image");
$rs = safe_row("*", "txp_image", "id='$id'");
if ($rs) {
extract($rs);
echo startTable('list'),
tr(
td(
'
'.
br.upload_form(gTxt('replace_image'),'replace_image_form',
'image_replace',$id)
)
),
tr(
td(
join('',
array(
($thumbnail)
? '
'.br
: '',
upload_form(gTxt('upload_thumbnail'),'upload_thumbnail',
'thumbnail_insert',$id)
)
)
)
),
tr(
td(
form(
graf(gTxt('image_name').br.fInput('text','name',$name,'edit')) .
graf(gTxt('image_category').br.treeSelectInput('category',
$categories,$category)) .
graf(gTxt('alt_text').br.fInput('text','alt',$alt,'edit','','',50)) .
graf(gTxt('caption').br.text_area('caption','100','400',$caption)) .
graf(fInput('submit','',gTxt('save'),'publish')) .
hInput('id',$id) .
eInput('image') .
sInput('image_save')
)
)
),
endTable();
}
}
// -------------------------------------------------------------
function image_insert()
{
global $txpcfg,$extensions,$txp_user;
extract($txpcfg);
$category = doSlash(gps('category'));
$file = $_FILES['thefile']['tmp_name'];
$name = $_FILES['thefile']['name'];
$file = get_uploaded_file($file);
list($w,$h,$extension) = getimagesize($file);
if ($extensions[$extension]) {
$ext = $extensions[$extension];
$name = substr($name,0,strrpos($name,'.'));
$name .= $ext;
$name2db = doSlash($name);
$rs = safe_insert("txp_image",
"w = '$w',
h = '$h',
category = '$category',
ext = '$ext',
`name` = '$name2db',
`date` = now(),
author = '$txp_user'
");
$id = mysql_insert_id();
if(!$rs){
image_list('there was a problem saving image data');
} else {
$newpath = IMPATH.$id.$ext;
if(shift_uploaded_file($file, $newpath) == false) {
safe_delete("txp_image","id='$id'");
safe_alter("txp_image", "auto_increment=$id");
image_list($newpath.sp.gTxt('upload_dir_perms'));
} else {
chmod($newpath,0755);
image_edit(messenger('image',$name,'uploaded'),$id);
}
}
} else {
image_list(gTxt('only_graphic_files_allowed'));
}
}
// -------------------------------------------------------------
function image_replace()
{
global $txpcfg,$extensions,$txp_user,$img_dir,$path_to_site;
extract($txpcfg);
$id = gps('id');
$file = $_FILES['thefile']['tmp_name'];
$name = $_FILES['thefile']['name'];
$file = get_uploaded_file($file);
list($w,$h,$extension) = getimagesize($file);
if ($extensions[$extension]) {
$ext = $extensions[$extension];
$name = substr($name,0,strrpos($name,'.'));
$name .= $ext;
$name2db = doSlash($name);
$rs = safe_update("txp_image",
"w = '$w',
h = '$h',
ext = '$ext',
`name` = '$name2db',
`date` = now(),
author = '$txp_user'",
"id = $id
");
if(!$rs){
image_list('there was a problem saving image data');
} else {
$newpath = IMPATH.$id.$ext;
if(shift_uploaded_file($file, $newpath) == false) {
safe_delete("txp_image","id='$id'");
safe_alter("txp_image", "auto_increment=$id");
image_list($newpath.sp.gTxt('upload_dir_perms'));
} else {
chmod($newpath,0755);
image_edit(messenger('image',$name,'uploaded'),$id);
}
}
} else {
image_list(gTxt('only_graphic_files_allowed'));
}
}
// -------------------------------------------------------------
function thumbnail_insert()
{
global $txpcfg,$extensions,$txp_user,$img_dir,$path_to_site;
extract($txpcfg);
$id = gps('id');
$file = $_FILES['thefile']['tmp_name'];
$name = $_FILES['thefile']['name'];
$file = get_uploaded_file($file);
list(,,$extension) = getimagesize($file);
if ($extensions[$extension]) {
$ext = $extensions[$extension];
$newpath = IMPATH.$id.'t'.$ext;
if(shift_uploaded_file($file, $newpath) == false) {
image_list($newpath.sp.gTxt('upload_dir_perms'));
} else {
chmod($newpath,0755);
safe_update("txp_image", "thumbnail='1'", "id='$id'");
image_edit(messenger('image',$name,'uploaded'),$id);
}
} else image_list(gTxt('only_graphic_files_allowed'));
}
// -------------------------------------------------------------
function image_save()
{
extract(doSlash(gpsa(array('id','name','category','caption','alt'))));
safe_update(
"txp_image",
"name = '$name',
category = '$category',
alt = '$alt',
caption = '$caption'",
"id = '$id'"
);
image_list(messenger("image",$name,"updated"));
}
// -------------------------------------------------------------
function image_delete()
{
global $txpcfg;
extract($txpcfg);
$id = ps('id');
$rs = safe_row("*", "txp_image", "id='$id'");
if ($rs) {
extract($rs);
$rsd = safe_delete("txp_image","id='$id'");
$ul = unlink(IMPATH.$id.$ext) or exit(image_list());
if(is_file(IMPATH.$id.'t'.$ext)){
$ult = unlink(IMPATH.$id.'t'.$ext);
}
if ($rsd && $ul) image_list(messenger("image",$name,"deleted"));
} else image_list();
}
// -------------------------------------------------------------
function upload_form($label,$pophelp,$step,$id='')
{
return
'