コード例 #1
0
ファイル: Design.class.php プロジェクト: joswilson/NotJustOK
 /**
  * Get the User Avatar.
  *
  * @param string $sUername
  * @param string $sSex
  * @param integer $iSize
  * @return void Html contents. URL avatar default 150px or the user avatar.
  */
 public function getUserAvatar($sUsername, $sSex = '', $iSize = '')
 {
     $oCache = (new \PH7\Framework\Cache\Cache())->start(self::CACHE_AVATAR_GROUP . $sUsername, $sSex . $iSize, 60 * 24 * 30);
     if (!($sUrl = $oCache->get())) {
         $oUserModel = new \PH7\UserCoreModel();
         $iProfileId = $oUserModel->getId(null, $sUsername);
         $oGetAvatar = $oUserModel->getAvatar($iProfileId);
         $sSize = $iSize == '32' || $iSize == '64' || $iSize == '100' || $iSize == '150' || $iSize == '200' || $iSize == '400' ? '-' . $iSize : '';
         $sAvatar = @$oGetAvatar->pic;
         $sExt = PH7_DOT . (new File())->getFileExt($sAvatar);
         $sDir = 'user/avatar/img/' . $sUsername . PH7_SH;
         $sPath = PH7_PATH_PUBLIC_DATA_SYS_MOD . $sDir . $sAvatar;
         $sUrl = PH7_URL_DATA_SYS_MOD . $sDir . str_replace($sExt, $sSize . $sExt, $sAvatar);
         $bIsModerate = Registry::getInstance()->module === PH7_ADMIN_MOD;
         if (!is_file($sPath) || $oGetAvatar->approvedAvatar == '0') {
             /* If sex is empty, it is recovered in the database using information from member */
             $sSex = !empty($sSex) ? $sSex : $oUserModel->getSex(null, $sUsername, 'Members');
             $sSex = $this->oStr->lower($sSex);
             $sIcon = $sSex == 'male' || $sSex == 'female' || $sSex == 'couple' || $sSex == PH7_ADMIN_USERNAME ? $sSex : 'visitor';
             $sUrlTplName = defined('PH7_TPL_NAME') ? PH7_TPL_NAME : PH7_DEFAULT_THEME;
             /*** If the user does not have an avatar ***/
             if (!is_file($sPath)) {
                 // The user has no avatar, we try to get her Gravatar.
                 // Get the User Email.
                 $sEmail = $oUserModel->getEmail($iProfileId);
                 $bSecureGravatar = \PH7\Framework\Http\Http::isSsl();
                 $sUrl = $this->getGravatarUrl($sEmail, '404', $iSize, 'g', $bSecureGravatar);
                 if (!(new \PH7\Framework\Security\Validate\Validate())->url($sUrl, true)) {
                     // Our Default Image
                     $sUrl = PH7_URL_TPL . $sUrlTplName . PH7_SH . PH7_IMG . 'icon/' . $sIcon . '_no_picture' . $sSize . '.jpg';
                 }
             } elseif (!$bIsModerate) {
                 $sUrl = PH7_URL_TPL . $sUrlTplName . PH7_SH . PH7_IMG . 'icon/pending' . $sSize . '.jpg';
             }
         }
         unset($oUserModel);
         $oCache->put($sUrl);
     }
     unset($oCache);
     echo $sUrl;
 }