1) ? PrevNextLink("image",$page-1,gTxt('prev'),'prev') : ''; $nav[] = sp.small($page. '/'.$numPages).sp; $nav[] = ($page != $numPages) ? PrevNextLink("image",$page+1,gTxt('next'),'next') : ''; // Added $sort and $dir $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) ) ) ) ), (function_exists("imagecreatefromjpeg")) ? thumb_ui( $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 (($file !== false) && @$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 { if ($file === false) image_list(upload_get_errormsg($_FILES['thefile']['error'])); 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 (($file !== false) && $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 { if ($file === false) image_list(upload_get_errormsg($_FILES['thefile']['error'])); 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 (($file !== false) && $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 { if ($file === false) image_list(upload_get_errormsg($_FILES['thefile']['error'])); 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 '
'. hInput('MAX_FILE_SIZE','1000000'). graf($label.': '. fInput('file','thefile','','edit'). popHelp($pophelp). fInput('submit','',gTxt('upload'),'smallerbox')). eInput('image'). sInput($step). hInput('id',$id). '
'; } // ------------------------------------------------------------- function image_change_pageby() { event_change_pageby('image'); image_list(); } // ------------------------------------------------------------- function thumb_ui($id) { global $prefs; extract($prefs); return tr( td( form( graf(gTxt('create_thumbnail')) . startTable('','left','',1) . tr( fLabelCell(gTxt('thumb_width').':') . fInputCell('width','',1,4). fLabelCell(gTxt('thumb_height').':') . fInputCell('height','',1,4). fLabelCell(gTxt('keep_square_pixels').':') . tda(checkbox2('crop', ''),' class="noline"'). tda(fInput('submit','',gTxt('Create'),'smallerbox'), ' class="noline"') ) . hInput('id',$id) . eInput('image') . sInput('thumbnail_create') . endTable() ) ) ); } // ------------------------------------------------------------- function thumbnail_create() { $id = gps('id'); $width = gps('width'); $height = gps('height'); if (!is_numeric ($width) && !is_numeric($height)) { image_edit(messenger('invalid_width_or_height',"($width)/($height)", ''),$id); return; } $crop = gps('crop'); $t = new txp_thumb( $id ); $t->crop = ($crop == '1'); $t->hint = '0'; if ( is_numeric ($width)) $t->width = $width; if ( is_numeric ($height)) $t->height = $height; if ($t->write()) { image_edit(messenger('thumbnail',$id,'saved'),$id); } else { image_edit(messenger('thumbnail',$id,'not_saved'),$id); } } ?>