Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - V@no

Pages: 1 2 3 [4] 5 6 7 8 ... 14
46
Mods & Plugins (Releases & Support) / [MOD] Check for duplicate images v1.0
« on: September 10, 2006, 02:50:33 AM »
This is a very simple check if a uploaded file was previously uploaded.
The method used in this mod is to generate MD5 hash for each image in the database and then compare them with MD5 hash of newly uploaded files.
The name, filename and extension is ignored by this mod, the contents of the file is what used to generate MD5 hash. Though this method has a weak spot: if a file was altered in any way the MD5 hash will be different from the original file.


----------[ Installation ]------------

Step 1
Download this package. (File attached on bottom of this post too)
Extract it and upload image_md5_hash.php file into admin/plugins/ folder (if no such folder exists then create it)


Step 2
Open member.php
Find:
Code: [Select]
  if (!$error) {
    // Start Upload
    include(ROOT_PATH.'includes/upload.php');
Insert above:
Code: [Select]
/*
  MOD CHECK FOR DUPLICATE IMAGES
  START INSERT
*/
##########
# CONFIG #
##########

  $check_admin = true; //do check when administrator is uploading? (true/false)
  $show_image = true; //show link to the image that was previously uploaded? (true/false)
  $show_member = true; //show name and link to profile page of the member who previously uploaded that file? (true/false)

##############
# END CONFIG #
##############

  $md5 = "";
  unset($HTTP_POST_VARS['image_md5']);
  if ($user_info['user_level'] != ADMIN || $check_admin)
  {
    if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none")
    {
      $md5 = md5_file($HTTP_POST_FILES['media_file']['tmp_name']);
      $file = $HTTP_POST_FILES['media_file']['filename'];
    }
    elseif ($remote_media_file)
    {
      $md5 = md5($remote_media_file);
      $file = $remote_media_file;
    }
    if ($md5)
    {
      $sql = "SELECT image_id, image_name, cat_id, user_id
              FROM ".IMAGES_TABLE."
              WHERE image_md5 = '".$md5."'
              LIMIT 1";
      if ($row = $site_db->query_firstrow($sql))
      {

        $row['image_name'] = stripslashes($row['image_name']);
        if (function_exists('multilang')) $row['image_name'] = multilang($row['image_name']);
        $user_row = get_user_info($row['user_id']);
//        $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$file."</b><br />";
        $msg .= (($msg != "") ? "<br />" : "").(($user_info['user_level'] > GUEST && $user_info['user_id'] == $user_row['user_id']) ? $lang['image_md5_duplicate_self'] : sprintf(($show_member ? $lang['image_md5_duplicate_more'] : $lang['image_md5_duplicate_simple']), "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$user_row['user_id'])."\">".$user_row['user_name']."</a>"));
        if ($show_image && (($user_info['user_level'] > GUEST && $user_info['user_id'] != $user_row['user_id']) || (check_permission("auth_viewcat", $row['cat_id'] && check_permission("auth_viewimage", $row['cat_id'])))))
        {
          $msg .= ": <a href=\"".$site_sess->url(ROOT_PATH."details.php?image_id=".$row['image_id'])."\">".$row['image_name']."</a>";
        }
        $error = 1;
      }
      else
      {
        $sql = "SELECT image_id, image_name, user_id
                FROM ".IMAGES_TEMP_TABLE."
                WHERE image_md5 = '".$md5."'
                LIMIT 1";
        if ($row = $site_db->query_firstrow($sql))
        {
          $user_row = get_user_info($row['user_id']);
//          $msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$file."</b><br />";
          $msg .= (($msg != "") ? "<br />" : "").(($user_info['user_level'] > GUEST && $user_info['user_id'] == $row['user_id']) ? $lang['image_md5_duplicate_validation_self'] : sprintf(($show_member ? $lang['image_md5_duplicate_validation_more'] : $lang['image_md5_duplicate_validation_simple']), "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=showprofile&".URL_USER_ID."=".$user_row['user_id'])."\">".$user_row['user_name']."</a>"));
          $error = 1;
        }
      }
      $HTTP_POST_VARS['image_md5'] = $md5;
    }
  }
/*
  MOD CHECK FOR DUPLICATE IMAGES
  END INSERT
*/


Step 3
Open lang/<your language>/main.php
At the end, above closing ?> insert:

:flag-en: English:
Code: [Select]
$lang['image_md5'] = "Image MD5 hash";
$lang['image_md5_duplicate_self'] = "You have submitted this file before";
$lang['image_md5_duplicate_more'] = "This file has been previously submitted by %s";
$lang['image_md5_duplicate_simple'] = "This file has been previously submitted";
$lang['image_md5_duplicate_validation_self'] = "You have submitted this file before and awaiting validation.";
$lang['image_md5_duplicate_validation_more'] = "This file has been previously submitted by %s and awaiting validation.";
$lang['image_md5_duplicate_validation_simple'] = "This file has been previously submitted and awaiting validation.";

:flag-ru: Russian:
Code: [Select]
$lang['image_md5'] = "MD5 хэш файла";
$lang['image_md5_duplicate_self'] = "Вы уже раньше заливали этот файл";
$lang['image_md5_duplicate_more'] = "%s уже залили этот файл до вас";
$lang['image_md5_duplicate_simple'] = "Этот файл кто-то уже залил до вас";
$lang['image_md5_duplicate_validation_self'] = "Вы уже залили этот файл, и он ожидает подтверждения от администрации";
$lang['image_md5_duplicate_validation_more'] = "%s уже залили этот файл, и файл ожидает подтверждения от администрации";
$lang['image_md5_duplicate_validation_simple'] = "Кто-то уже залил этот файл, и файл ожидает подтверждения от администрации";


Step 4
Open includes/db_field_definitions.php
At the end, above closing ?> insert:
Code: [Select]
$additional_image_fields['image_md5'] = array($lang['image_md5'], "text", 0);




After installation in ACP (Admin Control Panel) in "Plugins" part of menu you should see new link "Image MD5 hash update".
When you click on it for the first time, the database installation process will start.
After new fields in the databse were added, you can again click on the "Image MD5 hash update" link and generate MD5 hash for all images in your gallery.

NOTE:
MD5 hash for remote images generates from the URL and not from the image content, so, if image was changed on the remote server, MD5 will not change.

P.S.
In case the download link doesnt work, I've attached the package, but I can not guarantee, that the attached package will be up-to-date in the future.

P.P.S.
This mod was created for 4images v1.7.3 but should work on v1.7 as well :)

47
In admin/thumbnailer.php find:
Code: [Select]
                  SET image_thumb_file = '".$image_cache[$key]['image_media_file']."'
Replace with:
Code: [Select]
                  SET image_thumb_file = '".addslashes($image_cache[$key]['image_media_file'])."'

48
Bug Fixes & Patches / [1.7.3] RSS feed not valid
« on: August 04, 2006, 09:15:02 PM »
This is not a bug in 4images itself, rather its a work around a bug in some PHP versions (not all versions have this bug), so if your RSS feed passes validation, you should not apply this patch.
(you can check if your RSS feed is valid at http://feedvalidator.org)

Step 1
In rss.php find
Code: [Select]
    'type' => mime_content_type($file),
Replace with:
Code: [Select]
    'type' => get_mime_content_type($file),

Step 2
In includes/functions.php at the end, above closing ?> insert:
Code: [Select]
function get_mime_content_type($file) {
    if (function_exists('mime_content_type')) {
      $type = mime_content_type($file);
      if ($type) {
        return $type;
      }
    }

    $info = @getimagesize($file);

    if (isset($info['mime'])) {
      return $info['mime'];
    }

    $type = @exec(trim('file -bi '.escapeshellarg($file)));

    if (strpos($type, ';') !== false) {
      list($type) = explode(';', $type);
    }

    if ($type) {
      return $type;
    }

    static $types = array(
      'ai' => 'application/postscript',
     'aif' => 'audio/x-aiff',
    'aifc' => 'audio/x-aiff',
    'aiff' => 'audio/x-aiff',
     'asc' => 'text/plain',
      'au' => 'audio/basic',
     'avi' => 'video/x-msvideo',
   'bcpio' => 'application/x-bcpio',
     'bin' => 'application/octet-stream',
       'c' => 'text/plain',
      'cc' => 'text/plain',
    'ccad' => 'application/clariscad',
     'cdf' => 'application/x-netcdf',
   'class' => 'application/octet-stream',
    'cpio' => 'application/x-cpio',
     'cpt' => 'application/mac-compactpro',
     'csh' => 'application/x-csh',
     'css' => 'text/css',
     'dcr' => 'application/x-director',
     'dir' => 'application/x-director',
     'dms' => 'application/octet-stream',
     'doc' => 'application/msword',
     'drw' => 'application/drafting',
     'dvi' => 'application/x-dvi',
     'dwg' => 'application/acad',
     'dxf' => 'application/dxf',
     'dxr' => 'application/x-director',
     'eps' => 'application/postscript',
     'etx' => 'text/x-setext',
     'exe' => 'application/octet-stream',
      'ez' => 'application/andrew-inset',
       'f' => 'text/plain',
     'f90' => 'text/plain',
     'fli' => 'video/x-fli',
     'gif' => 'image/gif',
    'gtar' => 'application/x-gtar',
      'gz' => 'application/x-gzip',
       'h' => 'text/plain',
     'hdf' => 'application/x-hdf',
      'hh' => 'text/plain',
     'hqx' => 'application/mac-binhex40',
     'htm' => 'text/html',
    'html' => 'text/html',
     'ice' => 'x-conference/x-cooltalk',
     'ief' => 'image/ief',
    'iges' => 'model/iges',
     'igs' => 'model/iges',
     'ips' => 'application/x-ipscript',
     'ipx' => 'application/x-ipix',
     'jpe' => 'image/jpeg',
    'jpeg' => 'image/jpeg',
     'jpg' => 'image/jpeg',
      'js' => 'application/x-javascript',
     'kar' => 'audio/midi',
   'latex' => 'application/x-latex',
     'lha' => 'application/octet-stream',
     'lsp' => 'application/x-lisp',
     'lzh' => 'application/octet-stream',
       'm' => 'text/plain',
     'man' => 'application/x-troff-man',
      'me' => 'application/x-troff-me',
    'mesh' => 'model/mesh',
     'mid' => 'audio/midi',
    'midi' => 'audio/midi',
     'mif' => 'application/vnd.mif',
    'mime' => 'www/mime',
     'mov' => 'video/quicktime',
   'movie' => 'video/x-sgi-movie',
     'mp2' => 'audio/mpeg',
     'mp3' => 'audio/mpeg',
     'mpe' => 'video/mpeg',
    'mpeg' => 'video/mpeg',
     'mpg' => 'video/mpeg',
    'mpga' => 'audio/mpeg',
      'ms' => 'application/x-troff-ms',
     'msh' => 'model/mesh',
      'nc' => 'application/x-netcdf',
     'oda' => 'application/oda',
     'pbm' => 'image/x-portable-bitmap',
     'pdb' => 'chemical/x-pdb',
     'pdf' => 'application/pdf',
     'pgm' => 'image/x-portable-graymap',
     'pgn' => 'application/x-chess-pgn',
     'png' => 'image/png',
     'pnm' => 'image/x-portable-anymap',
     'pot' => 'application/mspowerpoint',
     'ppm' => 'image/x-portable-pixmap',
     'pps' => 'application/mspowerpoint',
     'ppt' => 'application/mspowerpoint',
     'ppz' => 'application/mspowerpoint',
     'pre' => 'application/x-freelance',
     'prt' => 'application/pro_eng',
      'ps' => 'application/postscript',
      'qt' => 'video/quicktime',
      'ra' => 'audio/x-realaudio',
     'ram' => 'audio/x-pn-realaudio',
     'ras' => 'image/cmu-raster',
     'rgb' => 'image/x-rgb',
      'rm' => 'audio/x-pn-realaudio',
    'roff' => 'application/x-troff',
     'rpm' => 'audio/x-pn-realaudio-plugin',
     'rtf' => 'text/rtf',
     'rtx' => 'text/richtext',
     'scm' => 'application/x-lotusscreencam',
     'set' => 'application/set',
     'sgm' => 'text/sgml',
    'sgml' => 'text/sgml',
      'sh' => 'application/x-sh',
    'shar' => 'application/x-shar',
    'silo' => 'model/mesh',
     'sit' => 'application/x-stuffit',
     'skd' => 'application/x-koan',
     'skm' => 'application/x-koan',
     'skp' => 'application/x-koan',
     'skt' => 'application/x-koan',
     'smi' => 'application/smil',
    'smil' => 'application/smil',
     'snd' => 'audio/basic',
     'sol' => 'application/solids',
     'spl' => 'application/x-futuresplash',
     'src' => 'application/x-wais-source',
    'step' => 'application/STEP',
     'stl' => 'application/SLA',
     'stp' => 'application/STEP',
 'sv4cpio' => 'application/x-sv4cpio',
  'sv4crc' => 'application/x-sv4crc',
     'swf' => 'application/x-shockwave-flash',
       't' => 'application/x-troff',
     'tar' => 'application/x-tar',
     'tcl' => 'application/x-tcl',
     'tex' => 'application/x-tex',
    'texi' => 'application/x-texinfo',
  'texinfo -  application/x-texinfo',
     'tif' => 'image/tiff',
    'tiff' => 'image/tiff',
      'tr' => 'application/x-troff',
     'tsi' => 'audio/TSP-audio',
     'tsp' => 'application/dsptype',
     'tsv' => 'text/tab-separated-values',
     'txt' => 'text/plain',
     'unv' => 'application/i-deas',
   'ustar' => 'application/x-ustar',
     'vcd' => 'application/x-cdlink',
     'vda' => 'application/vda',
     'viv' => 'video/vnd.vivo',
    'vivo' => 'video/vnd.vivo',
    'vrml' => 'model/vrml',
     'wav' => 'audio/x-wav',
     'wrl' => 'model/vrml',
     'xbm' => 'image/x-xbitmap',
     'xlc' => 'application/vnd.ms-excel',
     'xll' => 'application/vnd.ms-excel',
     'xlm' => 'application/vnd.ms-excel',
     'xls' => 'application/vnd.ms-excel',
     'xlw' => 'application/vnd.ms-excel',
     'xml' => 'text/xml',
     'xpm' => 'image/x-xpixmap',
     'xwd' => 'image/x-xwindowdump',
     'xyz' => 'chemical/x-pdb',
     'zip' => 'application/zip',
    );

    $ext = get_file_extension($file);

    if (isset($types[$ext])) {
        return $types[$ext];
    }

    return 'application/octet-stream';
}

P.S. original post by Jan:
http://www.4homepages.de/forum/index.php?topic=13733.msg74134#msg74134

49
In postcards.php find:
Code: [Select]
      $msg = $lang['invalid_postcard_id'];
Replace with:
Code: [Select]
      show_error_page($lang['invalid_postcard_id']);

50
A few days ago I started making a multi-upload mod, which actualy is very simular to rroc's [MOD] multiupload, but it uses "modules" that allow use of other tools, such as Java applets for uploading files. Besides that, "modules" type will simplify installation process and make updates painless (just replace files with new version)
At this stage, the mod includes two "modules": basic and JUpload.
Basic - is plain multi field page, where each file must be selected manualy one-by-one like on a regular upload page.
JUpload - is a free Java applet from www.jupload.biz which supports "drag'n drop" feature :). Unfortunetly the applet is very buggy and half of the features dont work properly...:( Yet, I've tryed go around each bug, it seems to work "fine", atleast from JavaScript part. Also, I must say, at the moment JUpload module does not work with other browsers but only on Internet Explorer :(

Since this is a beta version, I will include minimum installation instruction and will not include any extra modifications to add links/buttons to multi-upload pages, you will need type url in the browser manualy (this way you can use it on your site without anyone knowing it exists, which may be a security benefit ;))

So, here it goes:

Step 1
Download file from the attachment at the end of this thread.
Unpack it and upload all files to your site, make sure restore the directory tree (create new folders if dont exist):
includes/mupload.php
includes/mu_modules/basic.php[/b]
includes/mu_modules/jupload.php
includes/mu_modules/jupload/jupload.jar
templates/<your template>/member_mupload_jupload.html
templates/<your template>/member_muploaddropdown.html
templates/<your template>/member_muploadform_basic.html
templates/<your template>/member_muploadform_basic_bit.html
templates/<your template>/member_muploadform_jupload.html


Step 2
Open member.php
Find:
Code: [Select]
include(ROOT_PATH.'includes/page_header.php');Comment it out (add # or // at the beginning of this line) or simply remove it.

Step 2.1
Find:
Code: [Select]
$sendprocess = 0;Insert below:
Code: [Select]
/*
  MOD MULTI-UPLOAD-PLUS
  BEGIN INSERT
*/
if ($action == "muploadimage" || $action == "muploadform")
{
  $dir = opendir(ROOT_PATH."includes/mu_modules/");
  $mu_modules = array();
  while ($file = readdir($dir))
  {
    if (is_file(ROOT_PATH."includes/mu_modules/".$file) && !is_dir(ROOT_PATH."includes/mu_modules/".$file) && substr(strrchr($file,"."), 1) == "php") $mu_modules[] = $file;
  }
  closedir($dir);
  include(ROOT_PATH.'includes/mupload.php');
}
include(ROOT_PATH.'includes/page_header.php');
/*
  MOD MULTI-UPLOAD-PLUS
  END INSERT
*/


Step 3
Open templates/<youre template>/header.html
Find <body (that line might contein other stuff)
Now, look if in that tag present onLoad="" (probably if its present it has some stuff between the quotes)
If you found one, then right after first quote add: {mupload_onload} tag. (i.e. if you found something like this:
Code: [Select]
<body onLoad="somestuff();">then after modification it should look like this:
Code: [Select]
<body onLoad="{mupload_onload} somestuff();">If you did not have any onload="" thing, then simply add one, after space after <body (as in the example above, but without somestuff(); ;))


That it. :D

Now, how to use it.
In the address bar of your browser (I'd suggest you test it on IE first) type:
1) for "basic" form: http://<youraddress>/path/to/4images/member.php?action=muploadform or http://<youraddress>/path/to/4images/member.php?action=muploadform&mutype=basic
2) for "JUpload form: http://<youraddress>/path/to/4images/member.php?action=muploadform&mutype=jupload

P.S.
Here is a list of planned features:
- auto resize images
- auto copy original images into "big" folder (only if resized)
- auto backup original images into user-defined directory (with additional code this could be used later for restoration and/or reading EXIF/IPTC info)
- support for watermark by SLL

Version history:

v0.3b
- fixed thumbnails wouldnt upload
- fixed template can not be found error if upload error

v0.2b
- added support for [MOD] Categories upload dropdown form (replace includes/mupload.php)

v0.1b
- original release


Some screenshots:
Basic:



JUpload:



51
Bug Fixes & Patches / [1.7.2] Security fix for global.php
« on: April 26, 2006, 12:25:45 AM »
If you downloaded 4images v1.7.2 before 25-04-2006 you should apply this fix!
If you downloaded it after that date, then you should not worry about it, the download package already conteins this fix.

Step 1

In global.php
find:
Code: [Select]
/*
$val = str_replace("\r\n", "\n", $val);
$val = str_replace("\r",   "\n", $val);
$val = strtr($val, $search2, $replace2);
      $val = str_replace("\r", '', $val);  // \r === \x0D
*/

/*
do {
        $oldval = $val;
        $val = preg_replace('#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i', "", $val);
      } while ($oldval != $val);
*/

Replace with:
Code: [Select]
      $val = str_replace("\r\n", "\n", $val);
      $val = str_replace("\r",   "\n", $val);
      $val = strtr($val, $search2, $replace2);
      $val = str_replace("\r", '', $val);  // \r === \x0D

      do {
        $oldval = $val;
        $val = preg_replace('#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>#i', "", $val);
      } while ($oldval != $val);

Or you can download 4images package from this page and replace global.php from that package.

Step 2

And in case someone already used this hole on your site, you should find and delete any user who has < and > tags in their name (well, atleast these who has <script or other HTML tags) (personaly I would not feel bad even perm ban for that)
For that go to ACP (Admin Control Panel) -> Edit users -> in the "Userame conteins" field enter: < and click "Find"
Repeat search for >

[EDIT]
For these who cant find the code above, you probably have something like this instead:
Code: [Select]
      $val = str_replace("\r\n", "\n", $val);
      $val = str_replace("\r",   "\n", $val);
      $val = strtr($val, $search2, $replace2);
      $val = str_replace("\r", '', $val);  // \r === \x0D
(note, there is no /* and */ around that block of code!
So, replace this block with the code above.

52
On some servers that is running Windows OS, some URLs can get an extra backslash, which in some cases could produce 404 error.
If you are NOT experiencing such problem, you dont need apply this fix


In global.php find:
Code: [Select]
  $script_url .= (dirname($PHP_SELF) != "/") ? dirname($PHP_SELF) : "";

Replace it with:
Code: [Select]
  $dirname = str_replace("\\", "/", dirname($PHP_SELF));
  $script_url .= ($dirname != "/") ? $dirname : "";

53
Quote
PHP Fatal error: imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png: fatal libpng error: zlib error in example.php on line 10
This error only occur on servers with PHP v5.1.x or newer, when resizing/creating thumbnails from PNG images and using GD type of graphic module.
To fix that, apply this patch.

54
Bug Fixes & Patches / [1.7 / 1.7.1] PHP v5.1.x and PNG images error
« on: February 25, 2006, 10:26:48 AM »
Since PHP v5.1 the GD function imagepng() accepts compression argument. The compression argument must be from 0 to 9. 4images is using the compression settings when creating thumbnails or image resizing for jpeg images which can be from 0 to 100. Because of that using imagepng() function will return fatal error
Quote
PHP Fatal error: imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png: fatal libpng error: zlib error in example.php on line 10

The fix is simple:
In includes/image_utils.php find:
Code: [Select]
    $image_handle = "image".$types[$image_info[2]];
Insert below:
Code: [Select]
    if ($image_info[2] == 3) $quality = 9;

55
Error Messages / Fehlermeldungen / MySQL error: "Got error XX from ...."
« on: February 25, 2006, 12:26:12 AM »
These type of errors usualy occur when something happend with the server. There are so many codes that mysql could show, so there is no way they could be puplished here...
If you have shell access to your server, or to any other server that has MySQL installed, you can execute the following command:
Code: [Select]
perror XXwhere XX is the error code.

Here is a list of most common error codes. Also on that site, you have more chances find explanation of your error ;)

[UPDATE]
For Windows systems, the perror.exe you can find in 'mysql\bin' and you can execute it from command prompt (aka DOS prompt)

56
FAQ, Tips / phpinfo()
« on: February 19, 2006, 07:30:56 PM »
If you've been asked to look into your phpinfo or provide a link to it and you dont know what does that mean, here is a little explanation.

phpinfo is a function in PHP that shows the information about the PHP on your server. To get that information simply create a new text file phpinfo.php (the name is your choice, make sure extension is php) with the following contents:
Code: [Select]
<?php
phpinfo
();
?>
Then upload this file to your web server and execute it by typing in the address bar: http://your address/path/to/phpinfo/file/phpinfo.php
It should show you the PHP settings on your server.

Update
Since v1.7.2 phpinfo() can be found in ACP (Admin Control Panel)

57

Found a little Bug in 4images.

It's not very critical, just if you use an non-standard user table fields.
Then the user online won't be showed.

Fix:
Search this line in includes/session.php
Code: [Select]
if ($row['session_user_id'] != GUEST && (isset($row['user_id']) && $row['user_id'] != GUEST)) {
and replace it with
Code: [Select]
if ($row['session_user_id'] != GUEST && (isset($row[$user_table_fields['user_id']]) && $row[$user_table_fields['user_id']] != GUEST)) {

58
Mods & Plugins (Releases & Support) / [MOD] Recycle Bin for images v1.1
« on: January 26, 2006, 07:45:27 AM »
------------- [ Introduction ] -----------------

With this mod you will be able restore deleted, by members, images.
In the settings under Allow users to delete their own images setting you will be able choose one of the following:
  • Not allow. With this option members can not delete their own images
  • Allow permanent deletion. With this option images deleted from the server, no restoration is possible
  • Move deleted images into "Recycle Bin" category.
  • Make deleted images as inactive, which will prevent them from being showed on the site.
  • When used "Recycle Bin" or image as inactive type of deletion, member can type a reason of deletion

This mod supports [Mod] Show original image in new window by clicking on image, [MOD] Multi-Language support for any text and can handle backup files.


------------- [ Installation ] -----------------

Step 1
Create a new category "Recycle Bin" (name is your choice)
Set View category and View images permissions to Administrator
Remmember the category ID, you will need it in next step.


Step 2
Open member.php
Find:
Code: [Select]
if ($action == "deleteimage") {Insert above:
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
if ($action == "deleteimage")
{
  $recycle_bin_cat = XXXXXXXX; //recycle bin category ID
  $big = ""; //big folder name. leave empty if your are not using it
//  $big = "big"; //big folder name. leave empty if your are not using it
  $backup = (defined('BACKUPDIR')) ? BACKUPDIR : ""; //backup dir with trailing slash! leave empty if not using it
//  $backup = "/www/4images_backup/"; //backup dir with trailing slash! leave empty if not using it

  $control_panel = $lang['image_delete'];
  if (!function_exists("multilang"))
  {
    function multilang($text)
    {
      return $text;
    }
  }
  function movefiles($src, $dest)
  {
    $n = 2;
    $copy = "";
    $name = substr($dest,0,(strlen($dest)-strlen(strrchr($dest,"."))));
    $ext = substr(strrchr($dest,"."), 1);
    while (file_exists($name.$copy.".".$ext))
    {
      $copy = "_".$n;
      $n++;
    }
    $dest = $name.$copy.".".$ext;
    if ($ok = @copy($src, $dest))
    {
      @chmod($dest, CHMOD_FILES);
      @unlink($src);
      return basename($dest);
    }

    return false;
  }
  if ($config['user_delete_image'] > 1)
  {
    if (!$image_id)
    {
      show_error_page($lang['no_permission']);
      exit;
    }
    $sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_media_file, i.image_thumb_file".get_user_table_field(", u.", "user_level")."
            FROM ".IMAGES_TABLE." i
            LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
            WHERE i.image_active = 1 AND i.image_id = $image_id AND i.cat_id NOT IN (".get_auth_cat_sql('auth_viewcat', 'NOTIN').",".$recycle_bin_cat.")";
    $image_row = $site_db->query_firstrow($sql);
    if (!$image_row || ($user_info['user_level'] != ADMIN && ($image_row['user_level'] <= USER_AWAITING || $user_info['user_id'] != $image_row['user_id'] || (!$config['user_delete_image'] && $user_info['user_cat'] != $image_row['cat_id']))))
    {
      show_error_page($lang['no_permission']);
      exit;
    }
    $sql = "";
    switch($config['user_delete_image'])
    {
      case 2: //recycle bin
        $mime_type_match = array();
        include(ROOT_PATH.'includes/upload_definitions.php');
        $error = 0;
        $media_moved = 0;
        $new_media_name = $image_row['image_media_file'];
        $new_thumb_name = $image_row['image_thumb_file'];
        if (!$error && $image_row['image_media_file'] && !is_remote($image_row['image_media_file']))
        {
          if ($new_media_name = movefiles(MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file'], MEDIA_PATH."/".$recycle_bin_cat."/".$image_row['image_media_file']))
          {
            $media_moved = 1;
          }
          else
          {
            $error = 1;
          }
        }
        if (!$error && $image_row['image_thumb_file'] && !is_remote($image_row['image_thumb_file']))
        {
          if (!$new_thumb_name = movefiles(THUMB_PATH."/".$image_row['cat_id']."/".$image_row['image_thumb_file'], THUMB_PATH."/".$recycle_bin_cat."/".$image_row['image_thumb_file']))
          {
            $error = 1;
            if ($media_moved)
            {
              movefiles(MEDIA_PATH."/".$recycle_bin_cat."/".$new_media_name, MEDIA_PATH."/".$image_row['cat_id']."/".$image_row['image_media_file']);
            }
          }
        }
        if (!$error && $big)
        {
          $file = MEDIA_PATH."/".$image_row['cat_id']."/".$big."/".$image_row['image_media_file'];
          $new_file = MEDIA_PATH."/".$recycle_bin_cat."/".$big."/".$new_media_name;
          if ($image_row['image_media_file'] && file_exists($file))
          {
            if (!@is_dir(MEDIA_PATH."/".$recycle_bin_cat."/".$big))
            {
              $oldumask = umask(0);
              $result = @mkdir(MEDIA_PATH."/".$recycle_bin_cat."/".$big, CHMOD_DIRS);
              umask($oldumask);
              if (!is_dir(MEDIA_PATH."/".$recycle_bin_cat."/".$big) || !$result)
              {
                $result = @mkdir(MEDIA_PATH."/".$recycle_bin_cat."/".$big, 0755);
       
              }
              @chmod(MEDIA_PATH."/".$recycle_bin_cat."/".$big, CHMOD_DIRS);
            }
            if (file_exists($new_file))
            {
              @unlink($new_file);
            }
            if (@copy($file, $new_file))
            {
              @unlink($file);
              @chmod($new_file, CHMOD_FILES);
            }
          }
        }
        if (!$error && $backup)
        {
          $file = $backup."/".$image_row['cat_id']."/".$image_row['image_media_file'];
          $new_file = $backup."/".$recycle_bin_cat."/".$new_media_name;
          if ($image_row['image_media_file'] && file_exists($file))
          {
            if (!@is_dir(MEDIA_PATH."/".$recycle_bin_cat."/".$backup))
            {
              $oldumask = umask(0);
              $result = @mkdir($backup."/".$recycle_bin_cat, CHMOD_DIRS);
              umask($oldumask);
              if (!is_dir($backup."/".$recycle_bin_cat) || !$result)
              {
                $result = @mkdir($backup."/".$recycle_bin_cat, 0755);
       
              }
              @chmod($backup."/".$recycle_bin_cat, CHMOD_DIRS);
            }
            if (file_exists($new_file))
            {
              @unlink($new_file);
            }
            if (@copy($file, $new_file))
            {
              @unlink($file);
              @chmod($new_file, CHMOD_FILES);
            }
          }
        }
        $sql = "UPDATE ".IMAGES_TABLE."
                SET image_media_file = '".addslashes($new_media_name)."', image_thumb_file = '".addslashes($new_thumb_name)."', cat_id = ".$recycle_bin_cat."
                WHERE image_id = ".$image_row['image_id'];
        break;
      case 3: //mark as inactive
        $sql = "UPDATE ".IMAGES_TABLE."
                SET image_active = 0
                WHERE image_id = ".$image_row['image_id'];
        break;
    }
    if (!$error && (!$sql || !$site_db->query($sql)))
    {
      $error = 1;
    }
    if (!$error)
    {
      $msg_color = 1;
    }
    $msg = "<meta http-equiv=\"refresh\" content=\"2; url=".$site_sess->url(ROOT_PATH.(($error) ? "details.php?".URL_IMAGE_ID."=".$image_id : "categories.php?cat_id=".$image_row['cat_id']))."\">".(($error) ? $lang['image_delete_error'] : $lang['image_delete_success']);
    $txt_clickstream = get_category_path($image_row['cat_id'], 1, 0, 1).(($error) ? $config['category_separator']."<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id)."\" class=\"clickstream\">".multilang($image_row['image_name'])."</a>".$config['category_separator'] : "");
    $action = "";
  }
}
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/

Replace XXXXXXXX with your "Recycle Bin" category ID.
Also, if you are using [Mod] Show original image in new window by clicking on image then uncomment (remove //) from this line:
Quote
//  $big = "big"; //big folder name. leave empty if your are not using it
Do the same thing to $backup variable if you are storing backup images somewhere on your server.


Step 2.1
Find two instances:
Code: [Select]
$config['user_delete_image'] != 1(note, this is a part of a line!)
Replace both with:
Code: [Select]
!$config['user_delete_image']


Step 3
Open details.php
Find:
Code: [Select]
$config['user_delete_image'] != 1(note, this is a part of a line!)
Replace it with:
Code: [Select]
!$config['user_delete_image']


Step 4
Open admin/settings.php
Find:
Code: [Select]
  show_setting_row("user_delete_image", "radio");Replace it with:
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN REPLACE
*/
  echo "<tr class=\"".get_row_bg()."\">\n<td valign=\"top\"><p class=\"rowtitle\">".$setting['user_delete_image']."</p></td>\n";
  echo "<td><p>";
  echo "\n<select name=\"setting_item[user_delete_image]\" class=\"categoryselect\" onkeypress=\"if(window.event.keyCode==13)this.form.submit();\">\n";
  for($i = 0; $i < count($setting['user_delete_image_array']); $i++)
  {
    echo "<option value=\"".$i."\"".(($i == $config['user_delete_image']) ? " selected" : "").">".$setting['user_delete_image_array'][$i]."</option>\n";
  }
  echo "</select>\n";
  echo "</p></td>\n</tr>\n";
/*
MOD RECYCLE BIN FOR IMAGES
END REPLACE
*/



Step 5
Open lang/<your language>/admin.php
Find:
Code: [Select]
$setting['user_delete_image'] = "Allow users to delete their own images";Insert below:
English:
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$setting['user_delete_image_array'] = array(
  "No",
  "Permanent delete",
  "Move to Recycle Bin",
  "Mark as inactive"
);
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/

Deutsch (thanks to mawenzi):
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$setting['user_delete_image_array'] = array(
  "Nein",
  "Ja - Endgultig Loschen",
  "Ja - Verschieben in den Papierkorb",
  "Ja - Markieren als Inaktiv"
);
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/

Русский:
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$setting['user_delete_image_array'] = array(
  "Нет",
  "Да, полное удаление",
  "Да, сохранять в мусорнике",
  "Да, сделать не активными"
);
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/


This is it. For those who would like to let members provide a reason why they deleted an image, you can follow these steps:


Step 6
Add new field into 4images_images table (name: delete_reason type: VARCHAR(255))
Or you can run this MySQL query (you can use phpmyadmin or any other MySQL managers):
Code: [Select]
ALTER TABLE 4images_images ADD delete_reason VARCHAR( 255 ) NOT NULL

Step 7
Open member.php
Find:
Code: [Select]
  $control_panel = $lang['image_delete'];
Insert below:
Code: [Select]
  $delete_reason = isset($HTTP_POST_VARS['delete_reason']) ? addslashes($HTTP_POST_VARS['delete_reason']) : "";


Step 7.1
Find:
Code: [Select]
                SET image_media_file = '".addslashes($new_media_name)."', image_thumb_file = '".addslashes($new_thumb_name)."', cat_id = ".$recycle_bin_cat."
Replace with:
Code: [Select]
                SET image_media_file = '".addslashes($new_media_name)."', image_thumb_file = '".addslashes($new_thumb_name)."', cat_id = ".$recycle_bin_cat.", delete_reason = '".$delete_reason."'


Step 7.2
Find:
Code: [Select]
                SET image_active = 0
Replace with:
Code: [Select]
                SET image_active = 0, delete_reason = '".$delete_reason."'


Step 7.3
Find:
Code: [Select]
    "lang_delete_image_confirm" => $lang['image_delete_confirm'],
Insert below:
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
    "lang_delete_reason" => $lang['delete_reason'],
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/


Step 8
Open includes/db_field_definitions.php
At the end, above closing ?> insert:
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$additional_image_fields['delete_reason'] = array($lang['delete_reason'], "text", 0);
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/


Step 9
Open lang/<your language>/main.php
At the end, above closing ?> insert:
English:
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$lang['delete_reason'] = "Reason for deletion";
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/

Русский:
Code: [Select]
/*
MOD RECYCLE BIN FOR IMAGES
BEGIN INSERT
*/
$lang['delete_reason'] = "Причина удаления";
/*
MOD RECYCLE BIN FOR IMAGES
END INSERT
*/


Step 10
Open templates/<your template>/member_deleteimage.html
Insert (design is your task ;)):
Code: [Select]
{lang_delete_reason} <textarea name="delete_reason"></textarea>

Step 11
This step needed only if you want to display the reason to admin (when used recycle bin method):
Open templates/<your template>/details.html
Add the following tags (again, design is your task):[qcode]{if is_admin}{if delete_reason}
{lang_delete_reason}: {delete_reason}
{endif delete_reason}{endif is_admin}[/qcode]

59
Error Messages / Fehlermeldungen / Warning: session_start(): open(
« on: January 17, 2006, 01:22:22 AM »
This error became pretty common around here. Unfortunetly the only thing you can do about it is contact your host's administrator and hope they fix this as soon as possible.

This is server-side problem and without root access to the server is not possible to fix it.


I was suffering from the same problem that many are ... seeing these messages when you run 4images:

 Fatal error: session_start(): Failed to initialize storage module: user (path: /tmp) in
 /your_home_directory/path_to_4images_gallery/includes/sessions.php on line 84

If you are getting this message *CONSISTENTLY*, then there is clearly something wrong with the hosting company's server setup, and you need to ask them to take a look. Hopefully, they will fix it.

But, if 4Images works fine most of the time, and you sometimes see one of these messages, or your server seems to get hung up on them for a minute or so, then it starts working again ... try this:

Create a /tmp/sessions directory in your home directory, check the permission to make sure it is writeable, then add the following line to .htaccess:

php_value session.save_path /your_home_directory/tmp/sessions

This solved my problem 100%, and I assume it will work for many of you, too. This simply isolates your 4Images session variables to a private /tmp space, avoiding whatever conflicts were causing the problem.

60
This bug accur only when a member was added into a usergroup and then admin update/change that member's permissions, in some cases it will update/change the usergroup permissions as well.
To test it do the following:
1) register a new account on register.php page (not in ACP!)
2) in ACP set any permission in one category to "Private"
3) create a new usergroup "test"
4) in ACP find the new user account and add it to "test" usergroup
5) edit permissions for the user, and change any of the available permissions.
6) edit usergroup "test", the changes saved from user's permissions (step 5) affected the permissions of this usergroup.

To fix that do the following:

In admin/usergroups.php find:
Code: [Select]
            WHERE gm.user_id = $user_id AND g.group_id = gm.group_id";Replace with:
Code: [Select]
            WHERE gm.user_id = $user_id AND g.group_id = gm.group_id AND g.group_type = ".GROUPTYPE_SINGLE;

Pages: 1 2 3 [4] 5 6 7 8 ... 14