1
Neobless
Hack for multi upload atavars
  • 2004/1/22 17:08

  • Neobless

  • Just popping in

  • Posts: 11

  • Since: 2004/1/22


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:

if ( $op == 'list' )
    {
        
xoops_cp_header();
        echo 
'_MD_AVATARMAN '';
        
$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 
'
  • _MD_SYSAVATARS ' (' sprintf_NUMIMAGES'$savatar_count ') . ') [_LIST ']
  • _MD_CSTAVATARS ' (' sprintf_NUMIMAGES'$cavatar_count ') . ') [_LIST ']
'
;

        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::getImgListAsArrayXOOPS_ROOT_PATH "/uploads/cache" );
        
WfsLists::getarrayXOOPS_ROOT_PATH "/uploads/cache" );
        echo 
$htmlarray;
        
$atvarslisting = array();

        
$smallimage_select = new XoopsFormSelect'''atvarslisting'''10true );
        
$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'34) );
        
$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'50255 ), true );
        
$form->addElement( new XoopsFormFile_IMAGEFILE'avatar_file'500000 ) );
        
$form->addElement( new XoopsFormText_IMGWEIGHT'avatar_weight'34) );
        
$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:

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 strtolowerbasename$HTTP_POST_VARS['atvarslisting'][$i] ) );

            if ( @!
file_exists$sourcepath $sourcefile ) )
            {
                
$err[] = "File " basename$sourcefile ) . " does not exist in path " $sourcepath "";
                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.";
                    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 "File has not been copied into the database.";
                continue;
            } 
            if ( 
count$allowedmimetypes ) > && !in_array$filemimetype$allowedmimetypes ) )
            {
                
$err[] = "Not allowed mimetype for file " $sourcefile "File has not been copied into the database.";
                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 $destfile0644 );
                if (!
chmod$sourcepath0777 ))
                {
                    
$err[] = "Error changing write permission on path" $sourcepath ", please change to 0777";
                }
                
chmod$sourcepath $sourcefile0666 );
                if ( !
unlink$sourcepath $sourcefile ) )
                {
                    
$err[] = "Error deleting " $sourcefile " to path" $destpath " ";
                    
$deleteme $sourcepath $sourcefile "deleteme";
                    if ( @
rename$sourcepath $sourcefile$deleteme ) )
                    {
                        
touch$deleteme );
                        
chmod$deleteme0644 );
                    } 
                } 
            } 
            
$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 ) ? 1;
            
$avatar->setVar'avatar_display'$avatar_display );
            if ( 
$avatar_autoweight == )
            {
                
$avatar->setVar'avatar_weight'$i );
            } 
            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 ) > )
        {
            
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


2
IncommingForce
Re: Hack for multi upload atavars

Dis is a fantastic hack !!

I intalled and uploaded over a 100 new atavars without a probelm !!

Thanks Neobless for this !

3
sunsnapper
Re: Hack for multi upload avatars

This would be a nice feature to add to the core... whether in this form or another.

4
morris
Re: Hack for multi upload atavars
  • 2004/1/22 22:49

  • morris

  • Just popping in

  • Posts: 54

  • Since: 2003/9/25


Is it possible to download the main.php file completely because I don't understand where to place the following: and after case 'save' add add this:
etc.

Thanks.

5
Neobless
Re: Hack for multi upload atavars
  • 2004/1/22 23:29

  • Neobless

  • Just popping in

  • Posts: 11

  • Since: 2004/1/22


Geezz!!

Download it!!!

6
morris
Re: Hack for multi upload atavars
  • 2004/1/23 21:39

  • morris

  • Just popping in

  • Posts: 54

  • Since: 2003/9/25


Thanks for the file, but it doesn't work for me.
I created a cache dir (0777)in the uploads dir but I only see the following in the avatar manager:

Avatar Manager
System Avatars (18 images) [List]
Custom Avatars (2 images) [List]

No possibility to select the avatars in the cache dir!

Am I doing something wrong?

Morris.

7
Brad
Re: Hack for multi upload atavars
  • 2004/2/17 21:29

  • Brad

  • Not too shy to talk

  • Posts: 150

  • Since: 2003/12/4


I'm not seeing anything different either, after applying this hack to XOOPS 2.0.6.

[minutes later...]

Alright, I see the f*ck*ng problem. This hack ASSUMES that the person applying it has WF-Sections installed.

8
ukandrewf
Re: Hack for multi upload atavars
  • 2004/3/7 20:07

  • ukandrewf

  • Friend of XOOPS

  • Posts: 198

  • Since: 2002/12/2


i know this is probably pretty dumb but...

When I try to copy the code from the above examples the structure of the code is f*cked up. I'm sure i did it once before but this time it's just putting all the code in as 2 lines which isn't much good.

Also the download link isn't working for the main.php file so I can't download and get it from there.

Any ideas?

9
Gamut
Re: Hack for multi upload atavars
  • 2004/4/7 6:56

  • Gamut

  • Just popping in

  • Posts: 34

  • Since: 2002/1/5 1


Ok I have just tried this multi-load avatar hack and got the following error:

Fatal error: Undefined class name 'wfslists' in /home/phoenix/public_html/modules/system/admin/avatars/main.php on line 69

This hack refers to a non-existent "wfslists.php" from WF-Sections class directory. Unfortunately there is no such file.

The part of the code in the hack that causes this problem is as follows:

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();



Clearly 2 things need to be changed, but to what? (wfsfiles?, wfstree?...???)

(1)XOOPS_ROOT_PATH . "/modules/wfsection/class/wfslists.php";
(2)WfsLists::getarray

Any advice would be greatly appreciated as I do not want to upload avatars one by one. (I am amazed that the avatar management is actually worse than it used to be in earlier XOOPs versions!)

10
ros256
Re: Hack for multi upload atavars
  • 2004/10/13 0:20

  • ros256

  • Just popping in

  • Posts: 3

  • Since: 2004/10/12


Hi,

I installed WF-Sections and applied the code hack above, then moved my images to the uploads/cache directory (chmod'd 0777 as directed). Now when I go to the avatars admin page (with PHP debug on) I get the following:

Avatar Manager
System Avatars (0 images) [List]
Custom Avatars (0 images) [List]
Notice [PHP]: Undefined variable: this in file modules/wfsection/class/wfslists.php line 40
Warning [PHP]: Missing argument 2 for getdirlistasarray() in file modules/wfsection/class/wfslists.php line 65

Any idea what the problem is?

Thanks,

Rosencrantz

Login

Who's Online

355 user(s) are online (247 user(s) are browsing Support Forums)


Members: 0


Guests: 355


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits