Avatar

Step by step introduction (General)

by Milo ⌂, Monday, November 28, 2016, 17:20 (180 days ago) @ Magma

Hi,

backup your files!

Step by step introduction:

avatar.inc.php
replace this file with the file from the ZIP archive.

functions.inc.php
add new function (no specific line):

/**
 * Returns the avatar image by user id
 *
 * @param int user_id
 * @return array [path, filename, path/filename] or false if not exists
 */ 
function getAvatar($user_id) {
 $avatar_images_path = 'images/avatars/';
 $fileIterator = new FilesystemIterator($avatar_images_path);
 $regexFileFilterIterator = new RegexIterator($fileIterator, "/\D+(".preg_quote(intval($user_id), '/')."(_\d+)?\.(jpg|gif|png|jpeg)$)/i", RegexIterator::GET_MATCH);
 $regexFileFilterIterator->rewind();
 $filename = ($regexFileFilterIterator->valid() && count($regexFileFilterIterator->current()) > 1) ? $regexFileFilterIterator->current()[1] : false;
 if ($filename === false || !file_exists($avatar_images_path.$filename))
  return false;
 return array($avatar_images_path, $filename, $avatar_images_path.$filename);
}

entry.inc.php
look for this code part (line 54ff)

       if($settings['avatars']==2)
        {
         if(file_exists('images/avatars/'.$entrydata['user_id'].'.jpg')) $avatar['image'] = 'images/avatars/'.$entrydata['user_id'].'.jpg';
         elseif(file_exists('images/avatars/'.$entrydata['user_id'].'.png')) $avatar['image'] = 'images/avatars/'.$entrydata['user_id'].'.png';
         elseif(file_exists('images/avatars/'.$entrydata['user_id'].'.gif')) $avatar['image'] = 'images/avatars/'.$entrydata['user_id'].'.gif';
         if(isset($avatar))
          {
           $image_info = getimagesize($avatar['image']);
           $avatar['width'] = $image_info[0];
           $avatar['height'] = $image_info[1];
           $smarty->assign('avatar', $avatar);
          }
        }


and replace it by the new code:

   if($settings['avatars']==2) {
    $avatarInfo = getAvatar($entrydata['user_id']);
    $avatar['image'] = $avatarInfo === false ? false : $avatarInfo[2];
 
    if(isset($avatar) && $avatar['image'] !== false) {
     $image_info = getimagesize($avatar['image']);
     $avatar['width']  = $image_info[0];
     $avatar['height'] = $image_info[1];
     $smarty->assign('avatar', $avatar);
    }
   }


thread.inc.php
Look for this code part (line 133ff)

        if($settings['avatars']==2)
         {
          if(file_exists('images/avatars/'.$data['user_id'].'.jpg')) $avatar['image'] = 'images/avatars/'.$data['user_id'].'.jpg';
          elseif(file_exists('images/avatars/'.$data['user_id'].'.png')) $avatar['image'] = 'images/avatars/'.$data['user_id'].'.png';
          elseif(file_exists('images/avatars/'.$data['user_id'].'.gif')) $avatar['image'] = 'images/avatars/'.$data['user_id'].'.gif';
          if(isset($avatar))
           {
            $image_info = getimagesize($avatar['image']);
            $avatar['width'] = $image_info[0];
            $avatar['height'] = $image_info[1];
            $data['avatar'] = $avatar;
            unset($avatar);
           }
         }

and replace it by

   if($settings['avatars']==2){
    $avatarInfo = getAvatar($data['user_id']);
    $avatar['image'] = $avatarInfo === false ? false : $avatarInfo[2];
    if(isset($avatar) && $avatar['image'] !== false) {
     $image_info = getimagesize($avatar['image']);
     $avatar['width']  = $image_info[0];
     $avatar['height'] = $image_info[1];
     $data['avatar']   = $avatar;
     unset($avatar);
    }
   }

user.inc.php
Look for this code part (line 256ff)

       if($settings['avatars']>0)
        {
         if(file_exists('images/avatars/'.$id.'.jpg')) $avatar['image'] = 'images/avatars/'.$id.'.jpg';
         elseif(file_exists('images/avatars/'.$id.'.png')) $avatar['image'] = 'images/avatars/'.$id.'.png';
         elseif(file_exists('images/avatars/'.$id.'.gif')) $avatar['image'] = 'images/avatars/'.$id.'.gif';
         if(isset($avatar))
          {
           $image_info = getimagesize($avatar['image']);
           $avatar['width'] = $image_info[0];
           $avatar['height'] = $image_info[1];
           $smarty->assign('avatar', $avatar);
          }
        }

and replace it by

  if($settings['avatars']>0) {
   $avatarInfo = getAvatar($id);
   $avatar['image'] = $avatarInfo === false ? false : $avatarInfo[2];
 
   if(isset($avatar) && $avatar['image'] !== false) {
    $image_info = getimagesize($avatar['image']);
    $avatar['width']  = $image_info[0];
    $avatar['height'] = $image_info[1];
    $smarty->assign('avatar', $avatar);
   }
  }


user.inc.php
Look for this code part (line 462ff)

       if($settings['avatars']>0)
        {
         if(file_exists('images/avatars/'.$_SESSION[$settings['session_prefix'].'user_id'].'.jpg')) $avatar['image'] = 'images/avatars/'.$_SESSION[$settings['session_prefix'].'user_id'].'.jpg';
         elseif(file_exists('images/avatars/'.$_SESSION[$settings['session_prefix'].'user_id'].'.png')) $avatar['image'] = 'images/avatars/'.$_SESSION[$settings['session_prefix'].'user_id'].'.png';
         elseif(file_exists('images/avatars/'.$_SESSION[$settings['session_prefix'].'user_id'].'.gif')) $avatar['image'] = 'images/avatars/'.$_SESSION[$settings['session_prefix'].'user_id'].'.gif';
 
         if(isset($avatar))
          {
           $image_info = getimagesize($avatar['image']);
           $avatar['width'] = $image_info[0];
           $avatar['height'] = $image_info[1];
           $smarty->assign('avatar', $avatar);
          }
        }

and replace it by

  if($settings['avatars']>0) {
   $avatarInfo = getAvatar($_SESSION[$settings['session_prefix'].'user_id']);
   $avatar['image'] = $avatarInfo === false ? false : $avatarInfo[2];
 
   if(isset($avatar) && $avatar['image'] !== false) {
    $image_info = getimagesize($avatar['image']);
    $avatar['width'] = $image_info[0];
    $avatar['height'] = $image_info[1];
    $smarty->assign('avatar', $avatar);
   }
  }

regards
Micha

--
Surveyor-Software: Geodetic Network Adjustment & Deformation-Analysis and Transformation


Complete thread:

 RSS Feed of thread

powered by my little forum