I have hacked the XOOPS core to allow multi uploads with avatars, hope this helps other.
1, Create a folder called cache in uploads and CHMOD 0777.
2, Edit the following file modules/system/admin/avatars/main.php
At line 52 replace the whole case 'list' with this code:
le="color: #000000"><?php if ( $op == 'list' ) { xoops_cp_header(); echo '<h4 style="text-align:left">' . _MD_AVATARMAN . '</h4>'; $avt_handler = &xoops_gethandler( 'avatar' ); $savatar_count = $avt_handler->getCount( new Criteria( 'avatar_type', 'S' ) ); $cavatar_count = $avt_handler->getCount( new Criteria( 'avatar_type', 'C' ) ); echo '<ul><li>' . _MD_SYSAVATARS . ' (' . sprintf( _NUMIMAGES, '<b>' . $savatar_count . '</b>' ) . ') [<a href="admin.php?fct=avatars&op=listavt&type=S">' . _LIST . '</a>]</li><li>' . _MD_CSTAVATARS . ' (' . sprintf( _NUMIMAGES, '<b>' . $cavatar_count . '</b>' ) . ') [<a href="admin.php?fct=avatars&op=listavt&type=C">' . _LIST . '</a>]</li></ul>'; include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; include_once XOOPS_ROOT_PATH . "/modules/wfsection/class/wfslists.php"; $iform = new XoopsThemeForm( _MD_ADDAVT, 'avatar_form', 'admin.php' ); $iform->setExtra( 'enctype="multipart/form-data"' ); $graph_array = &XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . "/uploads/cache" ); WfsLists::getarray( XOOPS_ROOT_PATH . "/uploads/cache" ); echo $htmlarray; $atvarslisting = array(); $smallimage_select = new XoopsFormSelect( '', 'atvarslisting', '', 10, true ); $smallimage_select->addOptionArray( $graph_array ); $smallimage_tray = new XoopsFormElementTray( "Upload Batch Avatars:", ' ' ); $smallimage_tray->addElement( $smallimage_select ); $iform->addElement( $smallimage_tray ); $iform->addElement( new XoopsFormText( _IMGWEIGHT, 'avatar_weight', 3, 4, 0 ) ); $iform->addElement( new XoopsFormRadioYN( "Use Auto Weight?", 'avatar_autoweight', 0, _YES, _NO ) ); $iform->addElement( new XoopsFormRadioYN( _IMGDISPLAY, 'avatar_display', 1, _YES, _NO ) ); $iform->addElement( new XoopsFormHidden( 'op', 'batchaddfile' ) ); $iform->addElement( new XoopsFormHidden( 'fct', 'avatars' ) ); $iform->addElement( new XoopsFormButton( '', 'avt_button', _SUBMIT, 'submit' ) ); $iform->display(); $form = new XoopsThemeForm( _MD_ADDAVT, 'avatar_form', 'admin.php' ); $form->setExtra( 'enctype="multipart/form-data"' ); $form->addElement( new XoopsFormText( _IMAGENAME, 'avatar_name', 50, 255 ), true ); $form->addElement( new XoopsFormFile( _IMAGEFILE, 'avatar_file', 500000 ) ); $form->addElement( new XoopsFormText( _IMGWEIGHT, 'avatar_weight', 3, 4, 0 ) ); $form->addElement( new XoopsFormRadioYN( _IMGDISPLAY, 'avatar_display', 1, _YES, _NO ) ); $form->addElement( new XoopsFormHidden( 'op', 'addfile' ) ); $form->addElement( new XoopsFormHidden( 'fct', 'avatars' ) ); $form->addElement( new XoopsFormButton( '', 'avt_button', _SUBMIT, 'submit' ) ); $form->display(); xoops_cp_footer(); exit(); }
and after case 'save' add add this:
le="color: #000000"><?php if ( $op == 'batchaddfile' ) { include_once XOOPS_ROOT_PATH . '/class/uploader.php'; global $xoopsConfigUser; function getmimetype( $ext ) { $mimetypes = mimetype(); if ( isset( $mimetypes[$ext] ) ) { return $mimetypes[$ext]; } else { return false; } } function mimetype() { return array( "gif" => "image/gif", "ief" => "image/ief", "jpeg" => "image/pjpeg", "jpeg" => "image/jpeg", "jpg" => "image/jpeg", "jpe" => "image/jpeg", "png" => "image/x-png", "unknown" => "application/octet-stream" ); } $allowedmimetypes = array( 'image/gif', 'image/jpeg', 'image/pjpeg', 'image/x-png', 'image/png' ); $sourcepath = XOOPS_ROOT_PATH . '/uploads/cache/'; $destpath = XOOPS_ROOT_PATH . '/uploads/'; $err = array(); $ucount = count( $HTTP_POST_VARS['atvarslisting'] ); for ( $i = 0; $i < $ucount; $i++ ) { $sourcefile = strtolower( basename( $HTTP_POST_VARS['atvarslisting'][$i] ) ); if ( @!file_exists( $sourcepath . $sourcefile ) ) { $err[] = "File " . basename( $sourcefile ) . " does not exist in path " . $sourcepath . "<br />"; continue; } // file size check, XOOPS doesn't do this when uploading? maybe it should? if ( is_file( $sourcepath . $sourcefile ) ) { $size = filesize( $sourcepath . $sourcefile ); if ( $size > $xoopsConfigUser['avatar_maxsize'] ) { $err[] = "File size for " . basename( $sourcefile ) . " exceeds the ".$xoopsConfigUser['avatar_maxsize']." bytes limit.<br />"; continue; } } $mediaDimension = getimagesize( $sourcepath . $sourcefile ); if ( $mediaDimension[0] > $xoopsConfigUser['avatar_width'] || $mediaDimension[1] > $xoopsConfigUser['avatar_height'] ) { $err[] = "File height or/and width (".$mediaDimension[1]." x ".$mediaDimension[0].") for file: " . basename( $sourcefile ) . " exceeds the " . $xoopsConfigUser['avatar_width'] . " x " . $xoopsConfigUser['avatar_height'] . " limit"; continue; } // split filename $filename = explode( '.', $sourcefile ); $basename = $filename['0']; $ext = $filename['1']; $filemimetype = getmimetype( $ext ); if ( $filemimetype == false ) { $err[] = "Unknown filetype for file " . $sourcefile . "<br />File has not been copied into the database.<br />"; continue; } if ( count( $allowedmimetypes ) > 0 && !in_array( $filemimetype, $allowedmimetypes ) ) { $err[] = "Not allowed mimetype for file " . $sourcefile . "<br />File has not been copied into the database.<br />"; continue; } $destfile = uniqid( 'savt' ) . '.' . $ext; // copy files over with new name and delete the old one if ( !copy( $sourcepath . $sourcefile, $destpath . $destfile ) ) { $err[] = "Error copying " . $sourcefile . " to path" . $destpath . ". "; } else { touch( $destpath . $destfile ); chmod( $destpath . $destfile, 0644 ); if (!chmod( $sourcepath, 0777 )) { $err[] = "Error changing write permission on path" . $sourcepath . ", please change to 0777"; } chmod( $sourcepath . $sourcefile, 0666 ); if ( !unlink( $sourcepath . $sourcefile ) ) { $err[] = "Error deleting " . $sourcefile . " to path" . $destpath . " "; $deleteme = $sourcepath . $sourcefile . "deleteme"; if ( @rename( $sourcepath . $sourcefile, $deleteme ) ) { touch( $deleteme ); chmod( $deleteme, 0644 ); } } } $avt_handler = &xoops_gethandler( 'avatar' ); $avatar = &$avt_handler->create(); $avatar->setVar( 'avatar_file', $destfile ); $avatar->setVar( 'avatar_name', $basename ); $avatar->setVar( 'avatar_mimetype', $filemimetype ); $avatar_display = empty( $avatar_display ) ? 0 : 1; $avatar->setVar( 'avatar_display', $avatar_display ); if ( $avatar_autoweight == 1 ) { $avatar->setVar( 'avatar_weight', $i + 1 ); } else { $avatar->setVar( 'avatar_weight', $avatar_weight ); } $avatar->setVar( 'avatar_type', 'S' ); if ( !$avt_handler->insert( $avatar ) ) { $err[] = sprintf( _FAILSAVEIMG, $avatar->getVar( 'avatar_name' ) ); } } if ( count( $err ) > 0 ) { xoops_cp_header(); xoops_error( $err ); xoops_cp_footer(); exit(); } redirect_header( 'admin.php?fct=avatars', 2, _MD_AM_DBUPDATED ); }
How it works, copy all your new atavars to the cache folder and select the atavars you wish to upload and click on submit.
You should now have multi atavars