Gå til innhold

Et forslag til php koden, for å ha limit til 50x50...


Anbefalte innlegg

Satt og puslet litt med php om dagen, og jeg har lenge sagt at en slik kode kan spare dere for timer med avatar pisking. Så satt jeg sammen denne avatar limititer koden: Jeg er ganske sikker på at det må være skrive rettigheter på avatar dir`en da. :)


#################################################################

##

## Author Note:

## This code works on PHP3

## Tested and working productive on PHP 3.0.12/Apache

## Tested and working productive on PHP 4.0.5/IIS4

## Important:

## The $board_config['avatar_path'] folder MUST be writeable by the webserver.

## Otherwise set an alternate path in function download_avatar()

##  -->    $localfile = '/tmp/'.$userdata['session_user_id'].basename($filename);

#################################################################

## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD

#################################################################



#

#-----[ OPEN ]------------------------------------------

#

/path2phpBB2/includes/usercp_avatar.php

#

#-----[ FIND ]------------------------------------------

#

/***************************************************************************

*

*   This program is free software; you can redistribute it and/or modify

*   it under the terms of the GNU General Public License as published by

*   the Free Software Foundation; either version 2 of the License, or

*   (at your option) any later version.

*

*

***************************************************************************/

#

#-----[ AFTER, ADD ]------------------------------------------

#

function download_avatar($filename)

{

  global $board_config, $userdata;



  $retvar="NULL";

  $localfile = './'.$board_config['avatar_path'].'/'.$userdata['session_user_id'].basename($filename);

  $fd = @fopen($filename,"rb");

  if ($fd)

  {

// Read exactly the maximum defined avatar size from the remote file.

// If we don't find any dimension info in it afterwards, then it's not allowed anyway

       $imgdata=fread($fd,$board_config['avatar_filesize']);

       $fl=@fopen($localfile,"wb");

       if ($fl)

       {

          @fwrite($fl,$imgdata);

          @fclose($fl);

          if ($fp != -1) $retvar=$localfile;

       }

       fclose($fd);

  }

return $retvar;

}

#

#-----[ FIND ]------------------------------------------

#

function user_avatar_url($mode, &$error, &$error_msg, $avatar_filename)

{

  if ( !preg_match('#^http://#i', $avatar_filename) )

  {

     $avatar_filename = 'http://' . $avatar_filename;

  }



  if ( !preg_match('#^(http://[a-z0-9-]+?.([a-z0-9-]+.)*[a-z]+(:[0-9]+)*/.*?.(gif|jpg|jpeg|png)$)#is', $avatar_filename) )

  {

     $error = true;

     $error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Wrong_remote_avatar_format'] : $lang['Wrong_remote_avatar_format'];

     return;

  }



  return ( $mode == 'editprofile' ) ? ", user_avatar = '" . str_replace("'", "''", $avatar_filename) . "', user_avatar_type = " . USER_AVATAR_REMOTE : '';



}

#

#-----[ REPLACE WITH ]------------------------------------------

#

function user_avatar_url($mode, &$error, &$error_msg, $avatar_filename)

{

  global $board_config, $lang;



  if ( !preg_match('#^http://#i', $avatar_filename) )

  {

     $avatar_filename = 'http://' . $avatar_filename;

  }



  if ( !preg_match('#^(http://[a-z0-9-]+?.([a-z0-9-]+.)*[a-z]+(:[0-9]+)*/.*?.(gif|jpg|jpeg|png)$)#is', $avatar_filename) )

  {

     $error = true;

     $error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $lang['Wrong_remote_avatar_format'] : $lang['Wrong_remote_avatar_format'];

     return;

  }



// Get remote avatar size [R. 17.04.2002]

// Download the file

  $tmp_filename=download_avatar($avatar_filename);



// Get avatar size, check the values and invalidate them, if necessary

  if ($tmp_filename!='NULL') list($width, $height) = getimagesize($tmp_filename);

  if (!isset($width) or $width==0) $width=2*$board_config['avatar_max_width'];

  if (!isset($height) or $height==0) $height=2*$board_config['avatar_max_height'];



// Delete the tempfile

  @unlink($tmp_filename);



// Now compare the image dimension with phpBB config and print error message, if necessary

  if ( $width > $board_config['avatar_max_width'] && $height > $board_config['avatar_max_height'] )

  {

     $l_avatar_size = sprintf($lang['Avatar_imagesize'], $board_config['avatar_max_width'], $board_config['avatar_max_height']);

     $error = true;

     $error_msg = ( !empty($error_msg) ) ? $error_msg . '<br />' . $l_avatar_size : $l_avatar_size;

     return;

  }



  return ( $mode == 'editprofile' ) ? ", user_avatar = '" . str_replace("'", "''", $avatar_filename) . "', user_avatar_type = " . USER_AVATAR_REMOTE : '';



}

#

#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------ 

 

Det meste står forklart :). Jeg tar ikke ansvar for koden såklart :wink:

Lenke til kommentar
Videoannonse
Annonse

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...