1
xgarb
ImageManager - Replacement - Long Post!...
  • 2008/6/29 17:44

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


As mentioned in this thread.. https://xoops.org/modules/newbb/viewtopic.php?viewmode=flat&type=&topic_id=61462&forum=14 I’ve gone ahead and re-coded the imagemanager.

I’ve done this for my own use so while I’ve tried to keep it xoopified as much as possible I have taken some shortcuts to get it running. Mostly this is hard coded text rather than language variables.

I’m not a born coder so this is at your own risk. I’ve tried to make it as secure as possible.

If anyone wants to help with this, take it over or absorb some of it into the core than that would be fantastic.

Basic concepts:
Uploaded files are stored as they are originally uploaded. Resized images are generated as required from the original uploads.
Users have their own upload directory that they use to manage their own images.

Improvements over original imagemanager:
Higher quality images produced when using Imagemagick
Quicker access to a user’s commonly used images
Images only need to be uploaded once for use at different sizes
More intuitive and attractive to use

Things missing from the original imagemanager:
Database storage of images
‘Friendly’ image names
Mime type data

Possible Further features:
Resize and crop images in the imagemanager


Download files here.. http://www.mediafire.com/?9fbt2d4ttwx

You can test it here .. http://xoopsforever.x10hosting.com
With username and pass combos: test1111/test1111 test2222/test2222 test3333/test3333

Screenshots and code extracts follow….

2
xgarb
Re: ImageManager - Replacement - Screenshots
  • 2008/6/29 17:55

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


After clicking the imagemanager button the user would see their own images. Other users cannot see these images unless they are used somewhere on the site:

Resized Image


If they click the 'Site Images' tab they then see the images all users have access to:

Resized Image


This is the 'user image detail' screen where the user can choose the image size to use or delete the image:

Resized Image


Same screen but for site images (no delete button):
Resized Image

Finally the user can add the image to their post etc..

Resized Image

I've realised the above might be confusing as some images appear in both the user and site wide screens. The user's images wouldn't show in the site images unless they'd uploaded them to both areas

3
xgarb
Re: ImageManager - imagemanager.php - Directories
  • 2008/6/29 18:05

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


I'll try and explain how some of the code works - if anyone spots improvements or problems let me know!

The new image manager creates directories on the server to store the images. This code creates either a directory matching one of the sections added in the images part of XOOPS admin or a directory for the user.

It also adds an .htaccess file to secure the directory

// site directories 
 
if (isset($_REQUEST['imgcat_id'])){ // POST or GET
   
$showPulldown 'yes';
   
$numberImagesShown 15;   
   
$imgcat_handler =& xoops_gethandler('imagecategory');
   
$catlist =& $imgcat_handler->getList($group'imgcat_read'1);
   
$currentcat_id intval($_REQUEST['imgcat_id']);
   
$imgcatname $catlist[$currentcat_id];
   
$cleanimgcatname preg_replace("/[^a-z0-9\.\-\_]/i"'_' ,$imgcatname); //replace odd characters with underscore
   
$userID $xoopsUser->getVar('uid');
   
$userIDcode str_pad($userID5"0"STR_PAD_LEFT); // always have 5 digits ie: userid 123 becomes 00123
   
$activeDir XOOPS_UPLOAD_PATH.'/'.$cleanimgcatname;
  } 
// or user's directory   
 
if ( (!isset($_GET['imgcat_id']) && !isset($_POST['imgcat_id']) ) || $imgcatname == 'User Images'){
   
$showPulldown 'no';
   
$numberImagesShown in_array($group,12) ? 10 15// groupID 12 gets 15 images in their dir
   
$userID $xoopsUser->getVar('uid');
   
$userIDcode str_pad($userID5"0"STR_PAD_LEFT); // always have 5 digits ie: userid 123 becomes 00123
   
$userDir 'user_'.$userIDcode// this is the folder in uploads dir for this user ie: user_00123
   
$activeDir XOOPS_UPLOAD_PATH.'/'.$userDir;
  }
// create directory if not existing
 
if (!file_exists($activeDir)){
   
mkdir($activeDir0700);
   
// add an htaccess file to prevent script and non-image files being accessed...
   
$filename $activeDir.'/.htaccess';
   
$fh fopen($filename'w');
   
$stringData  "AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgin";
   
$stringData .= "Options -ExecCGIn";
   
$stringData .= "Order Deny,Allown";
   
$stringData .= "Deny from alln";
   
$stringData .= "n";
   
$stringData .= "Allow from alln";
   
$stringData .= "n";
   
$stringData .= "Options -Indexesn"// prevent browsing users dir
   
fwrite($fh$stringData);
   
fclose($fh);
   
chmod($filename0400);
  }
}

4
xgarb
Re: ImageManager - imagemanager.php - Thumbnail creation
  • 2008/6/29 18:09

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


I won't paste all the code here but the function...

function im_manager_createThumbnail($source,$thisActiveDir)

creates thumbnails in the cache folder. The new imagemagick command makes much better quality thumbnails than the previous code.

5
xgarb
Re: ImageManager - Process
  • 2008/6/29 18:35

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


I think rather than droning on through the code it's probably better if I go through how the system works. There's lots of commenting in the code to explain it anyway.

In the old imagemanager all the images are stored in a single directory.

In this system each of the sections from the XOOPS image admin has a directory on the file system. In addition each user can have their own directory. These are created the first time the imagemanager is started by a user for a user's own directory or a section from the admin area is selected in the imagemanager.

When an image is uploaded it is stored in one of these directories as an exact copy of the file on the user's PC.

If a user views their own images or the site's images a thumbnail is created of the relevant files and stored in the /cache folder. The user is shown these thumbnails on the screen.

Selecting a thumbnail shows a preview of the image (again generated and then stored in the /cache folder). The user can choose the size of image required and the alignment. If the user is viewing their own images they have the option of removing the image from their area (this only removes the original uploaded file).

Finally the file they've selected is created at the size chosen and moved to the upload folder. They can then press a button to add the image display code to the page.

Short Version!: Images are uploaded to a specific directory for storage. All the images shown on the site are created from this original. Thumbnails and previews shown while using the imagemanager are stored in the cache folder. If an image is selected to be shown on the site a copy is made of the original and this copy is stored in the /uploads directory.

6
Mamba
Re: ImageManager - Replacement - Long Post!...
  • 2008/6/29 22:16

  • Mamba

  • Moderator

  • Posts: 11409

  • Since: 2004/4/23


This is very nice!!!! Congratulations!
Support XOOPS => DONATE
Use 2.5.11 | Docs | Modules | Bugs

7
noo-b
Re: ImageManager - Replacement - Long Post!...
  • 2008/6/30 1:55

  • noo-b

  • Just can't stay away

  • Posts: 456

  • Since: 2007/10/23


cool....thank you xgarb...

this should be improved and included in XOOPS 2.3

i heard 2.3 beta will be release soon..maybe the core team can include it in 2.3 rc
I Love Xoops

8
phppp
Re: ImageManager - Replacement - Long Post!...
  • 2008/6/30 9:32

  • phppp

  • XOOPS Contributor

  • Posts: 2857

  • Since: 2004/1/25


Excellent improvements.
Let's see how to adopt into our next release. Or to modularize image management functionality.

9
xgarb
Re: ImageManager - Replacement - Long Post!...
  • 2008/6/30 10:10

  • xgarb

  • Not too shy to talk

  • Posts: 154

  • Since: 2003/3/30


Feel free to use it however you like. My code will need some work to integrate it properly into the core.

I've always thought a user and site file manager would work well in XOOPS with areas for storing images, mp3s, video etc.

I usually favour features being 'modulalized' but in the case of a file manager I wonder if it would be better in the core so all modules would use the same system.

Maybe a core module so it's a module but always comes with the core?

10
Burning
Re: ImageManager - Replacement - Long Post!...
  • 2008/7/3 10:33

  • Burning

  • Theme Designer

  • Posts: 1163

  • Since: 2006/8/22


Woah !!
It's like a dream... but it's true

Thanks xgarb x1000 !!!
Still learning CSS and... english

Login

Who's Online

252 user(s) are online (127 user(s) are browsing Support Forums)


Members: 0


Guests: 252


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