1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @title Avatar Design Core Class |
4
|
|
|
* |
5
|
|
|
* @author Pierre-Henry Soria <[email protected]> |
6
|
|
|
* @copyright (c) 2012-2017, Pierre-Henry Soria. All Rights Reserved. |
7
|
|
|
* @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
8
|
|
|
* @package PH7 / App / System / Core / Class / Design |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace PH7; |
12
|
|
|
|
13
|
|
|
use PH7\Framework\Layout\Html\Design; |
14
|
|
|
use PH7\Framework\Registry\Registry; |
15
|
|
|
use PH7\Framework\Server\Server; |
16
|
|
|
use PH7\Framework\Service\SearchImage\Google as GoogleImage; |
17
|
|
|
|
18
|
|
|
class AvatarDesignCore extends Design |
19
|
|
|
{ |
20
|
|
|
/** @var UserCore */ |
21
|
|
|
private $_oUser; |
22
|
|
|
|
23
|
|
|
public function __construct() |
24
|
|
|
{ |
25
|
|
|
parent::__construct(); |
26
|
|
|
$this->_oUser = new UserCore; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Display image avatar. |
31
|
|
|
* |
32
|
|
|
* @param string $sUsername |
33
|
|
|
* @param string $sFirstName |
34
|
|
|
* @param string $sSex |
35
|
|
|
* @param integer $iSize Avatar size (available sizes: 32, 64, 100, 150, 200, 400) |
36
|
|
|
* @param boolean $bRollover CSS effect |
37
|
|
|
*/ |
38
|
|
|
public function get($sUsername = '', $sFirstName = '', $sSex = null, $iSize = 32, $bRollover = false) |
39
|
|
|
{ |
40
|
|
|
// The profile does not exist, so it creates a fake profile = ghost |
41
|
|
|
if ($sUsername === PH7_ADMIN_USERNAME) { |
42
|
|
|
$sUsername = PH7_ADMIN_USERNAME; |
43
|
|
|
$sFirstName = t('Administrator'); |
44
|
|
|
$sSex = PH7_ADMIN_USERNAME; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (empty($sUsername)) { |
48
|
|
|
$sUsername = PH7_GHOST_USERNAME; |
49
|
|
|
$sFirstName = t('Ghost'); |
50
|
|
|
$sSex = PH7_GHOST_USERNAME; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$iSize = (int) $iSize; |
54
|
|
|
if ($bRollover) { |
55
|
|
|
echo '<style scoped="scoped">.rollover img{width:', ($iSize / 1), 'px;height:', ($iSize / 1), 'px;transition:all 0.3s ease-in-out;-webkit-transition:all 0.3s ease-in-out;-moz-transition:all 0.3s ease-in-out;-o-transition:all 0.3s ease-in-out;-ms-transition:all 0.3s ease-in-out;-khtml-transition:all 0.3s ease-in-out;z-index:0}.rollover a:hover >img{width:', $iSize, 'px;height:', $iSize, 'px;border:1px solid #eee;box-shadow:4px 4px 4px rgba(0,0,0,0.2);transform:scale(1.5,1.5);-webkit-transform:scale(1.5,1.5);-moz-transform:scale(1.5,1.5);-o-transform:scale(1.5,1.5);-ms-transform:scale(1.5,1.5);-khtml-transform:scale(1.5,1.5);transition:all 0.5s ease;-webkit-transition:all 0.5s ease;-moz-transition:all 0.5s ease;-o-transition:all 0.5s ease;-ms-transition:all 0.5s ease;-khtml-transition:all 0.5s ease;z-index:999}</style>'; |
56
|
|
|
echo '<div class="rollover"><a href="', $this->_oUser->getProfileSignupLink($sUsername, $sFirstName, $sSex), '"><img src="', $this->getUserAvatar($sUsername, $sSex, $iSize), '" alt="', ucfirst($sUsername), '" title="', ucfirst($sFirstName), '" /></a></div>'; |
57
|
|
|
} else { |
58
|
|
|
echo '<a class="pic" href="', $this->_oUser->getProfileSignupLink($sUsername, $sFirstName, $sSex), '"><img src="', $this->getUserAvatar($sUsername, $sSex, $iSize), '" alt="', ucfirst($sUsername), '" title="', ucfirst($sFirstName), '" class="avatar" /></a>'; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Display the lightbox avatar. |
64
|
|
|
* |
65
|
|
|
* @param string $sUsername |
66
|
|
|
* @param string $sFirstName |
67
|
|
|
* @param string $sSex |
68
|
|
|
* @param integer $iSize Avatar size (available sizes: 32, 64, 100, 150, 200, 400) |
69
|
|
|
*/ |
70
|
|
|
public function lightbox($sUsername = '', $sFirstName = '', $sSex = null, $iSize = 400) |
71
|
|
|
{ |
72
|
|
|
// The profile does not exist, so it creates a fake profile = ghost |
73
|
|
|
if (empty($sUsername)) { |
74
|
|
|
$sUsername = PH7_GHOST_USERNAME; |
75
|
|
|
$sFirstName = t('Ghost'); |
76
|
|
|
$sSex = PH7_GHOST_USERNAME; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
echo '<div class="picture_block"><a href="', $this->getUserAvatar($sUsername, $sSex, $iSize), '" title="', ucfirst($sUsername), '" data-popup="image"><img src="', $this->getUserAvatar($sUsername, $sSex, $iSize / 2), '" alt="', ucfirst($sUsername), '" title="', ucfirst($sFirstName), '" class="img_picture" /></a></div>'; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @internal Google Search Image works only on non-local URLs, so check if we aren't on dev environments. |
83
|
|
|
*/ |
84
|
|
|
if ( |
85
|
|
|
AdminCore::auth() |
86
|
|
|
&& Registry::getInstance()->controller === 'ModeratorController' |
87
|
|
|
&& !Server::isLocalHost() |
88
|
|
|
) { |
89
|
|
|
$sAvatarUrl = $this->getUserAvatar($sUsername, $sSex, null, false); |
|
|
|
|
90
|
|
|
|
91
|
|
|
echo '<p>'; |
92
|
|
|
$this->showAvatarOnGoogleLink($sAvatarUrl); |
93
|
|
|
echo '</p>'; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param string $sAvatarUrl |
99
|
|
|
*/ |
100
|
|
|
protected function showAvatarOnGoogleLink($sAvatarUrl) |
101
|
|
|
{ |
102
|
|
|
$oSearchImage = new GoogleImage($sAvatarUrl); |
103
|
|
|
|
104
|
|
|
$aLinkAttrs = [ |
105
|
|
|
'href' => $oSearchImage->getSearchImageUrl(), |
106
|
|
|
'title' => t('See any matching images with this profile photo'), |
107
|
|
|
'target' => '_blank', |
108
|
|
|
'class' => 'italic btn btn-default btn-xs' |
109
|
|
|
]; |
110
|
|
|
$this->htmlTag('a', $aLinkAttrs, true, t('Check it on Google Images')); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.