2012-10-11 08:00:15 +00:00
< ?
class Users {
/**
* Get $Classes ( list of classes keyed by ID ) and $ClassLevels
* ( list of classes keyed by level )
* @ return array ( $Classes , $ClassLevels )
*/
public static function get_classes () {
2013-08-28 23:08:41 +00:00
global $Debug ;
2012-10-11 08:00:15 +00:00
// Get permissions
2013-08-28 23:08:41 +00:00
list ( $Classes , $ClassLevels ) = G :: $Cache -> get_value ( 'classes' );
2012-10-11 08:00:15 +00:00
if ( ! $Classes || ! $ClassLevels ) {
2013-08-28 23:08:41 +00:00
$QueryID = G :: $DB -> get_query_id ();
G :: $DB -> query ( '
2013-05-28 08:01:02 +00:00
SELECT ID , Name , Level , Secondary
FROM permissions
ORDER BY Level ' );
2013-08-28 23:08:41 +00:00
$Classes = G :: $DB -> to_array ( 'ID' );
$ClassLevels = G :: $DB -> to_array ( 'Level' );
G :: $DB -> set_query_id ( $QueryID );
G :: $Cache -> cache_value ( 'classes' , array ( $Classes , $ClassLevels ), 0 );
2012-10-11 08:00:15 +00:00
}
$Debug -> set_flag ( 'Loaded permissions' );
2013-05-16 16:15:57 +00:00
2012-10-11 08:00:15 +00:00
return array ( $Classes , $ClassLevels );
}
/**
* Get user info , is used for the current user and usernames all over the site .
*
* @ param $UserID int The UserID to get info for
* @ return array with the following keys :
* int ID
* string Username
* int PermissionID
2013-05-27 08:00:58 +00:00
* array Paranoia - $Paranoia array sent to paranoia . class
2012-10-11 08:00:15 +00:00
* boolean Artist
* boolean Donor
* string Warned - When their warning expires in international time format
* string Avatar - URL
* boolean Enabled
* string Title
* string CatchupTime - When they last caught up on forums
* boolean Visible - If false , they don ' t show up on peer lists
* array ExtraClasses - Secondary classes .
* int EffectiveClass - the highest level of their main and secondary classes
*/
public static function user_info ( $UserID ) {
2013-08-28 23:08:41 +00:00
global $Classes , $SSL ;
$UserInfo = G :: $Cache -> get_value ( " user_info_ $UserID " );
2012-10-11 08:00:15 +00:00
// the !isset($UserInfo['Paranoia']) can be removed after a transition period
if ( empty ( $UserInfo ) || empty ( $UserInfo [ 'ID' ]) || ! isset ( $UserInfo [ 'Paranoia' ]) || empty ( $UserInfo [ 'Class' ])) {
2013-08-28 23:08:41 +00:00
$OldQueryID = G :: $DB -> get_query_id ();
G :: $DB -> query ( "
2013-05-16 16:15:57 +00:00
SELECT
m . ID ,
m . Username ,
m . PermissionID ,
m . Paranoia ,
i . Artist ,
i . Donor ,
i . Warned ,
i . Avatar ,
m . Enabled ,
m . Title ,
i . CatchupTime ,
m . Visible ,
GROUP_CONCAT ( ul . PermissionID SEPARATOR ',' ) AS Levels
2012-10-11 08:00:15 +00:00
FROM users_main AS m
2013-07-10 00:08:53 +00:00
INNER JOIN users_info AS i ON i . UserID = m . ID
2013-05-16 16:15:57 +00:00
LEFT JOIN users_levels AS ul ON ul . UserID = m . ID
2013-07-10 00:08:53 +00:00
WHERE m . ID = '$UserID'
2012-10-11 08:00:15 +00:00
GROUP BY m . ID " );
2013-08-28 23:08:41 +00:00
if ( ! G :: $DB -> has_results ()) { // Deleted user, maybe?
2013-07-10 00:08:53 +00:00
$UserInfo = array (
2013-08-28 23:08:41 +00:00
'ID' => $UserID ,
2013-07-10 00:08:53 +00:00
'Username' => '' ,
'PermissionID' => 0 ,
2013-08-28 23:08:41 +00:00
'Paranoia' => array (),
2013-07-10 00:08:53 +00:00
'Artist' => false ,
'Donor' => false ,
'Warned' => '0000-00-00 00:00:00' ,
'Avatar' => '' ,
'Enabled' => 0 ,
'Title' => '' ,
'CatchupTime' => 0 ,
2013-08-28 23:08:41 +00:00
'Visible' => '1' ,
2013-09-13 08:00:53 +00:00
'Levels' => '' ,
'Class' => 0 );
2012-10-11 08:00:15 +00:00
} else {
2013-08-28 23:08:41 +00:00
$UserInfo = G :: $DB -> next_record ( MYSQLI_ASSOC , array ( 'Paranoia' , 'Title' ));
2012-10-11 08:00:15 +00:00
$UserInfo [ 'CatchupTime' ] = strtotime ( $UserInfo [ 'CatchupTime' ]);
$UserInfo [ 'Paranoia' ] = unserialize ( $UserInfo [ 'Paranoia' ]);
if ( $UserInfo [ 'Paranoia' ] === false ) {
$UserInfo [ 'Paranoia' ] = array ();
}
2013-09-13 08:00:53 +00:00
$UserInfo [ 'Class' ] = $Classes [ $UserInfo [ 'PermissionID' ]][ 'Level' ];
2012-10-11 08:00:15 +00:00
}
if ( ! empty ( $UserInfo [ 'Levels' ])) {
$UserInfo [ 'ExtraClasses' ] = array_fill_keys ( explode ( ',' , $UserInfo [ 'Levels' ]), 1 );
} else {
$UserInfo [ 'ExtraClasses' ] = array ();
}
unset ( $UserInfo [ 'Levels' ]);
2013-09-13 08:00:53 +00:00
$EffectiveClass = $UserInfo [ 'Class' ];
2012-10-11 08:00:15 +00:00
foreach ( $UserInfo [ 'ExtraClasses' ] as $Class => $Val ) {
$EffectiveClass = max ( $EffectiveClass , $Classes [ $Class ][ 'Level' ]);
}
$UserInfo [ 'EffectiveClass' ] = $EffectiveClass ;
2013-08-28 23:08:41 +00:00
G :: $Cache -> cache_value ( " user_info_ $UserID " , $UserInfo , 2592000 );
G :: $DB -> set_query_id ( $OldQueryID );
2012-10-11 08:00:15 +00:00
}
if ( strtotime ( $UserInfo [ 'Warned' ]) < time ()) {
$UserInfo [ 'Warned' ] = '0000-00-00 00:00:00' ;
2013-08-28 23:08:41 +00:00
G :: $Cache -> cache_value ( " user_info_ $UserID " , $UserInfo , 2592000 );
2012-10-11 08:00:15 +00:00
}
return $UserInfo ;
}
/**
* Gets the heavy user info
* Only used for current user
*
* @ param $UserID The userid to get the information for
* @ return fetched heavy info .
* Just read the goddamn code , I don ' t have time to comment this shit .
*/
public static function user_heavy_info ( $UserID ) {
2013-08-28 23:08:41 +00:00
$HeavyInfo = G :: $Cache -> get_value ( " user_info_heavy_ $UserID " );
2012-10-11 08:00:15 +00:00
if ( empty ( $HeavyInfo )) {
2013-05-16 16:15:57 +00:00
2013-08-28 23:08:41 +00:00
$QueryID = G :: $DB -> get_query_id ();
G :: $DB -> query ( "
2013-05-16 16:15:57 +00:00
SELECT
m . Invites ,
m . torrent_pass ,
m . IP ,
m . CustomPermissions ,
m . can_leech AS CanLeech ,
i . AuthKey ,
i . RatioWatchEnds ,
i . RatioWatchDownload ,
i . StyleID ,
i . StyleURL ,
i . DisableInvites ,
i . DisablePosting ,
i . DisableUpload ,
i . DisableWiki ,
i . DisableAvatar ,
i . DisablePM ,
i . DisableRequests ,
i . DisableForums ,
2013-08-28 23:08:41 +00:00
i . DisableTagging , " . "
2013-05-16 16:15:57 +00:00
i . SiteOptions ,
i . DownloadAlt ,
i . LastReadNews ,
i . LastReadBlog ,
i . RestrictedForums ,
i . PermittedForums ,
m . FLTokens ,
m . PermissionID
2012-10-11 08:00:15 +00:00
FROM users_main AS m
2013-07-10 00:08:53 +00:00
INNER JOIN users_info AS i ON i . UserID = m . ID
WHERE m . ID = '$UserID' " );
2013-08-28 23:08:41 +00:00
$HeavyInfo = G :: $DB -> next_record ( MYSQLI_ASSOC , array ( 'CustomPermissions' , 'SiteOptions' ));
2012-10-11 08:00:15 +00:00
if ( ! empty ( $HeavyInfo [ 'CustomPermissions' ])) {
$HeavyInfo [ 'CustomPermissions' ] = unserialize ( $HeavyInfo [ 'CustomPermissions' ]);
} else {
$HeavyInfo [ 'CustomPermissions' ] = array ();
}
if ( ! empty ( $HeavyInfo [ 'RestrictedForums' ])) {
$RestrictedForums = array_map ( 'trim' , explode ( ',' , $HeavyInfo [ 'RestrictedForums' ]));
} else {
$RestrictedForums = array ();
}
unset ( $HeavyInfo [ 'RestrictedForums' ]);
if ( ! empty ( $HeavyInfo [ 'PermittedForums' ])) {
$PermittedForums = array_map ( 'trim' , explode ( ',' , $HeavyInfo [ 'PermittedForums' ]));
} else {
$PermittedForums = array ();
}
unset ( $HeavyInfo [ 'PermittedForums' ]);
2013-08-28 23:08:41 +00:00
G :: $DB -> query ( "
2013-06-06 08:01:03 +00:00
SELECT PermissionID
FROM users_levels
WHERE UserID = $UserID " );
2013-08-28 23:08:41 +00:00
$PermIDs = G :: $DB -> collect ( 'PermissionID' );
2012-10-11 08:00:15 +00:00
foreach ( $PermIDs AS $PermID ) {
$Perms = Permissions :: get_permissions ( $PermID );
if ( ! empty ( $Perms [ 'PermittedForums' ])) {
2013-06-18 08:00:48 +00:00
$PermittedForums = array_merge ( $PermittedForums , array_map ( 'trim' , explode ( ',' , $Perms [ 'PermittedForums' ])));
2012-10-11 08:00:15 +00:00
}
}
$Perms = Permissions :: get_permissions ( $HeavyInfo [ 'PermissionID' ]);
unset ( $HeavyInfo [ 'PermissionID' ]);
if ( ! empty ( $Perms [ 'PermittedForums' ])) {
2013-06-18 08:00:48 +00:00
$PermittedForums = array_merge ( $PermittedForums , array_map ( 'trim' , explode ( ',' , $Perms [ 'PermittedForums' ])));
2012-10-11 08:00:15 +00:00
}
if ( ! empty ( $PermittedForums ) || ! empty ( $RestrictedForums )) {
$HeavyInfo [ 'CustomForums' ] = array ();
foreach ( $RestrictedForums as $ForumID ) {
$HeavyInfo [ 'CustomForums' ][ $ForumID ] = 0 ;
}
foreach ( $PermittedForums as $ForumID ) {
$HeavyInfo [ 'CustomForums' ][ $ForumID ] = 1 ;
}
} else {
$HeavyInfo [ 'CustomForums' ] = null ;
}
2013-01-24 08:00:24 +00:00
if ( isset ( $HeavyInfo [ 'CustomForums' ][ '' ])) {
unset ( $HeavyInfo [ 'CustomForums' ][ '' ]);
}
2012-10-11 08:00:15 +00:00
$HeavyInfo [ 'SiteOptions' ] = unserialize ( $HeavyInfo [ 'SiteOptions' ]);
if ( ! empty ( $HeavyInfo [ 'SiteOptions' ])) {
$HeavyInfo = array_merge ( $HeavyInfo , $HeavyInfo [ 'SiteOptions' ]);
}
unset ( $HeavyInfo [ 'SiteOptions' ]);
2013-08-28 23:08:41 +00:00
G :: $DB -> set_query_id ( $QueryID );
G :: $Cache -> cache_value ( " user_info_heavy_ $UserID " , $HeavyInfo , 0 );
2012-10-11 08:00:15 +00:00
}
return $HeavyInfo ;
}
/**
* Updates the site options in the database
*
* @ param int $UserID the UserID to set the options for
* @ param array $NewOptions the new options to set
* @ return false if $NewOptions is empty , true otherwise
*/
public static function update_site_options ( $UserID , $NewOptions ) {
if ( ! is_number ( $UserID )) {
error ( 0 );
}
if ( empty ( $NewOptions )) {
return false ;
}
2013-08-28 23:08:41 +00:00
$QueryID = G :: $DB -> get_query_id ();
2012-10-11 08:00:15 +00:00
// Get SiteOptions
2013-08-28 23:08:41 +00:00
G :: $DB -> query ( "
2013-05-28 08:01:02 +00:00
SELECT SiteOptions
FROM users_info
WHERE UserID = $UserID " );
2013-08-28 23:08:41 +00:00
list ( $SiteOptions ) = G :: $DB -> next_record ( MYSQLI_NUM , false );
2012-10-11 08:00:15 +00:00
$SiteOptions = unserialize ( $SiteOptions );
// Get HeavyInfo
$HeavyInfo = Users :: user_heavy_info ( $UserID );
// Insert new/replace old options
$SiteOptions = array_merge ( $SiteOptions , $NewOptions );
$HeavyInfo = array_merge ( $HeavyInfo , $NewOptions );
// Update DB
2013-08-28 23:08:41 +00:00
G :: $DB -> query ( "
2013-05-28 08:01:02 +00:00
UPDATE users_info
SET SiteOptions = '".db_string(serialize($SiteOptions))."'
WHERE UserID = $UserID " );
2013-08-28 23:08:41 +00:00
G :: $DB -> set_query_id ( $QueryID );
2012-10-11 08:00:15 +00:00
// Update cache
2013-08-28 23:08:41 +00:00
G :: $Cache -> cache_value ( " user_info_heavy_ $UserID " , $HeavyInfo , 0 );
2012-10-11 08:00:15 +00:00
2013-08-28 23:08:41 +00:00
// Update G::$LoggedUser if the options are changed for the current
if ( G :: $LoggedUser [ 'ID' ] == $UserID ) {
G :: $LoggedUser = array_merge ( G :: $LoggedUser , $NewOptions );
G :: $LoggedUser [ 'ID' ] = $UserID ; // We don't want to allow userid switching
2012-10-11 08:00:15 +00:00
}
return true ;
}
2012-11-16 08:00:21 +00:00
/**
* Generates a check list of release types , ordered by the user or default
2013-07-04 08:00:56 +00:00
* @ param array $SiteOptions
2012-11-16 08:00:21 +00:00
* @ param boolean $Default Returns the default list if true
*/
2013-07-04 08:00:56 +00:00
public static function release_order ( & $SiteOptions , $Default = false ) {
global $ReleaseTypes ;
2012-11-16 08:00:21 +00:00
$RT = $ReleaseTypes + array (
1024 => 'Guest Appearance' ,
1023 => 'Remixed By' ,
1022 => 'Composition' ,
1021 => 'Produced By' );
if ( $Default || empty ( $SiteOptions [ 'SortHide' ])) {
$Sort =& $RT ;
$Defaults = ! empty ( $SiteOptions [ 'HideTypes' ]);
} else {
$Sort =& $SiteOptions [ 'SortHide' ];
2013-07-18 08:00:51 +00:00
$MissingTypes = array_diff_key ( $RT , $Sort );
2013-07-04 08:00:56 +00:00
if ( ! empty ( $MissingTypes )) {
foreach ( array_keys ( $MissingTypes ) as $Missing ) {
$Sort [ $Missing ] = 0 ;
}
}
2012-11-16 08:00:21 +00:00
}
foreach ( $Sort as $Key => $Val ) {
if ( isset ( $Defaults )) {
2013-05-28 08:01:02 +00:00
$Checked = ( $Defaults && isset ( $SiteOptions [ 'HideTypes' ][ $Key ]) ? ' checked="checked"' : '' );
2012-11-16 08:00:21 +00:00
} else {
2013-07-18 08:00:51 +00:00
if ( ! isset ( $RT [ $Key ])) {
continue ;
}
2013-05-28 08:01:02 +00:00
$Checked = ( $Val ? ' checked="checked"' : '' );
2013-07-18 08:00:51 +00:00
$Val = $RT [ $Key ];
2012-11-16 08:00:21 +00:00
}
2013-07-18 08:00:51 +00:00
$ID = $Key . '_' . ( int ) !! $Checked ;
2013-06-03 08:00:52 +00:00
// The HTML is indented this far for proper indentation in the generated HTML
// on user.php?action=edit
2012-11-16 08:00:21 +00:00
?>
2013-06-03 08:00:52 +00:00
< li class = " sortable_item " >
< label >< input type = " checkbox " < ? = $Checked ?> id="<?=$ID?>" /> <?=$Val?></label>
</ li >
2012-11-16 08:00:21 +00:00
< ?
}
}
/**
* Returns the default order for the sort list in a JS - friendly string
* @ return string
*/
2013-07-04 08:00:56 +00:00
public static function release_order_default_js ( & $SiteOptions ) {
2012-11-16 08:00:21 +00:00
ob_start ();
2013-07-04 08:00:56 +00:00
self :: release_order ( $SiteOptions , true );
2012-11-16 08:00:21 +00:00
$HTML = ob_get_contents ();
ob_end_clean ();
return json_encode ( $HTML );
}
2012-10-11 08:00:15 +00:00
/**
* Generate a random string
*
* @ param Length
* @ return random alphanumeric string
*/
public static function make_secret ( $Length = 32 ) {
$Secret = '' ;
2013-05-28 08:01:02 +00:00
$Chars = 'abcdefghijklmnopqrstuvwxyz0123456789' ;
$CharLen = strlen ( $Chars ) - 1 ;
2012-10-11 08:00:15 +00:00
for ( $i = 0 ; $i < $Length ; ++ $i ) {
$Secret .= $Chars [ mt_rand ( 0 , $CharLen )];
}
return $Secret ;
}
/**
* Create a password hash . This method is deprecated and
* should not be used to create new passwords
*
* @ param $Str password
* @ param $Secret salt
* @ return password hash
*/
2013-05-28 08:01:02 +00:00
public static function make_hash ( $Str , $Secret ) {
2012-10-11 08:00:15 +00:00
return sha1 ( md5 ( $Secret ) . $Str . sha1 ( $Secret ) . SITE_SALT );
}
/**
* Verify a password against a password hash
*
* @ param $Password password
* @ param $Hash password hash
* @ param $Secret salt - Only used if the hash was created
2013-04-18 08:00:54 +00:00
* with the deprecated Users :: make_hash () method
2012-10-11 08:00:15 +00:00
* @ return true on correct password
*/
2013-05-28 08:01:02 +00:00
public static function check_password ( $Password , $Hash , $Secret = '' ) {
2012-10-11 08:00:15 +00:00
if ( ! $Password || ! $Hash ) {
return false ;
}
if ( Users :: is_crypt_hash ( $Hash )) {
return crypt ( $Password , $Hash ) == $Hash ;
} elseif ( $Secret ) {
return Users :: make_hash ( $Password , $Secret ) == $Hash ;
}
return false ;
}
/**
* Test if a given hash is a crypt hash
*
* @ param $Hash password hash
* @ return true if hash is a crypt hash
*/
public static function is_crypt_hash ( $Hash ) {
return preg_match ( '/\$\d[axy]?\$/' , substr ( $Hash , 0 , 4 ));
}
/**
* Create salted crypt hash for a given string with
* settings specified in CRYPT_HASH_PREFIX
*
* @ param $Str string to hash
* @ return salted crypt hash
*/
public static function make_crypt_hash ( $Str ) {
$Salt = CRYPT_HASH_PREFIX . Users :: gen_crypt_salt () . '$' ;
return crypt ( $Str , $Salt );
}
/**
* Create salt string for eksblowfish hashing . If / dev / urandom cannot be read ,
* fall back to an unsecure method based on mt_rand () . The last character needs
* a special case as it must be either '.' , 'O' , 'e' , or 'u' .
*
* @ return salt suitable for eksblowfish hashing
*/
public static function gen_crypt_salt () {
$Salt = '' ;
$Chars = " ./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 " ;
$Numchars = strlen ( $Chars ) - 1 ;
if ( $Handle = @ fopen ( '/dev/urandom' , 'r' )) {
$Bytes = fread ( $Handle , 22 );
2013-04-30 18:18:07 +00:00
for ( $i = 0 ; $i < 21 ; $i ++ ) {
2012-10-11 08:00:15 +00:00
$Salt .= $Chars [ ord ( $Bytes [ $i ]) & $Numchars ];
}
$Salt [ $i ] = $Chars [( ord ( $Bytes [ $i ]) & 3 ) << 4 ];
} else {
2013-04-30 18:18:07 +00:00
for ( $i = 0 ; $i < 21 ; $i ++ ) {
2012-10-11 08:00:15 +00:00
$Salt .= $Chars [ mt_rand ( 0 , $Numchars )];
}
$Salt [ $i ] = $Chars [ mt_rand ( 0 , 3 ) << 4 ];
}
return $Salt ;
}
/**
* Returns a username string for display
*
* @ param int $UserID
* @ param boolean $Badges whether or not badges ( donor , warned , enabled ) should be shown
* @ param boolean $IsWarned -- TODO : Why the fuck do we need this ?
* @ param boolean $IsEnabled -- TODO : Why the fuck do we need this ?
* @ param boolean $Class whether or not to show the class
* @ param boolean $Title whether or not to show the title
* @ return HTML formatted username
*/
2013-08-28 23:08:41 +00:00
public static function format_username ( $UserID , $Badges = false , $IsWarned = true , $IsEnabled = true , $Class = false , $Title = false , $IsDonorForum = false ) {
global $Classes ;
2012-10-11 08:00:15 +00:00
// This array is a hack that should be made less retarded, but whatevs
// PermID => ShortForm
$SecondaryClasses = array (
);
if ( $UserID == 0 ) {
return 'System' ;
}
2013-09-13 08:00:53 +00:00
$UserInfo = self :: user_info ( $UserID );
2012-10-11 08:00:15 +00:00
if ( $UserInfo [ 'Username' ] == '' ) {
return " Unknown [ $UserID ] " ;
}
$Str = '' ;
2013-08-28 23:08:41 +00:00
$Username = $UserInfo [ 'Username' ];
$Paranoia = $UserInfo [ 'Paranoia' ];
$ShowDonorIcon = ! in_array ( 'hide_donor_heart' , $Paranoia );
if ( $IsDonorForum ) {
list ( $Prefix , $Suffix , $HasComma ) = Donations :: get_titles ( $UserID );
$Username = " $Prefix $Username " . ( $HasComma ? ', ' : ' ' ) . " $Suffix " ;
}
2012-10-11 08:00:15 +00:00
if ( $Title ) {
2013-08-28 23:08:41 +00:00
$Str .= " <strong><a href= \" user.php?id= $UserID\ " > $Username </ a ></ strong > " ;
2012-10-11 08:00:15 +00:00
} else {
2013-08-28 23:08:41 +00:00
$Str .= " <a href= \" user.php?id= $UserID\ " > $Username </ a > " ;
2012-10-11 08:00:15 +00:00
}
if ( $Badges ) {
2013-08-28 23:08:41 +00:00
$DonorRank = Donations :: get_rank ( $UserID );
2013-09-13 08:00:53 +00:00
if ( $DonorRank == 0 && $UserInfo [ 'Donor' ] == 1 ) {
$DonorRank = 1 ;
}
if ( $ShowDonorIcon && $DonorRank > 0 ) {
2013-08-28 23:08:41 +00:00
$IconLink = 'donate.php' ;
$IconImage = 'donor.png' ;
2013-09-13 08:00:53 +00:00
$IconText = 'Donor' ;
$DonorHeart = $DonorRank ;
$SpecialRank = Donations :: get_special_rank ( $UserID );
$EnabledRewards = Donations :: get_enabled_rewards ( $UserID );
$DonorRewards = Donations :: get_rewards ( $UserID );
if ( $EnabledRewards [ 'HasDonorIconMouseOverText' ] && ! empty ( $DonorRewards [ 'IconMouseOverText' ])) {
$IconText = display_str ( $DonorRewards [ 'IconMouseOverText' ]);
}
if ( $EnabledRewards [ 'HasDonorIconLink' ] && ! empty ( $DonorRewards [ 'CustomIconLink' ])) {
$IconLink = display_str ( $DonorRewards [ 'CustomIconLink' ]);
}
if ( $EnabledRewards [ 'HasCustomDonorIcon' ] && ! empty ( $DonorRewards [ 'CustomIcon' ])) {
$IconImage = ImageTools :: process ( $DonorRewards [ 'CustomIcon' ]);
} else {
if ( $SpecialRank === MAX_SPECIAL_RANK ) {
2013-08-28 23:08:41 +00:00
$DonorHeart = 6 ;
2013-09-13 08:00:53 +00:00
} elseif ( $DonorRank === 5 ) {
$DonorHeart = 4 ; // Two points between rank 4 and 5
} elseif ( $DonorRank >= MAX_RANK ) {
2013-08-28 23:08:41 +00:00
$DonorHeart = 5 ;
}
2013-09-13 08:00:53 +00:00
if ( $DonorHeart === 1 ) {
$IconImage = STATIC_SERVER . 'common/symbols/donor.png' ;
} else {
$IconImage = STATIC_SERVER . " common/symbols/donor_ { $DonorHeart } .png " ;
}
2013-08-28 23:08:41 +00:00
}
$Str .= " <a href= \" $IconLink\ " >< img class = \ " donor_icon \" src= \" $IconImage\ " alt = \ " $IconText\ " title = \ " $IconText\ " /></ a > " ;
}
2013-04-18 08:00:54 +00:00
}
2013-01-11 08:00:38 +00:00
2013-08-28 23:08:41 +00:00
$Str .= ( $IsWarned && $UserInfo [ 'Warned' ] != '0000-00-00 00:00:00' ) ? '<a href="wiki.php?action=article&id=218"'
2013-02-22 08:00:24 +00:00
. '><img src="' . STATIC_SERVER . 'common/symbols/warned.png" alt="Warned" title="Warned'
2013-08-28 23:08:41 +00:00
. ( G :: $LoggedUser [ 'ID' ] === $UserID ? ' - Expires ' . date ( 'Y-m-d H:i' , strtotime ( $UserInfo [ 'Warned' ])) : '' )
. '" /></a>' : '' ;
$Str .= ( $IsEnabled && $UserInfo [ 'Enabled' ] == 2 ) ? '<a href="rules.php"><img src="' . STATIC_SERVER . 'common/symbols/disabled.png" alt="Banned" title="Be good, and you won\'t end up like this user" /></a>' : '' ;
2012-10-11 08:00:15 +00:00
if ( $Badges ) {
$ClassesDisplay = array ();
2013-08-28 23:08:41 +00:00
foreach ( array_intersect_key ( $SecondaryClasses , $UserInfo [ 'ExtraClasses' ]) as $PermID => $PermShort ) {
$ClassesDisplay [] = '<span class="secondary_class" title="' . $Classes [ $PermID ][ 'Name' ] . '">' . $PermShort . '</span>' ;
2012-10-11 08:00:15 +00:00
}
if ( ! empty ( $ClassesDisplay )) {
$Str .= ' ' . implode ( ' ' , $ClassesDisplay );
}
}
if ( $Class ) {
if ( $Title ) {
$Str .= ' <strong>(' . Users :: make_class_string ( $UserInfo [ 'PermissionID' ]) . ')</strong>' ;
} else {
$Str .= ' (' . Users :: make_class_string ( $UserInfo [ 'PermissionID' ]) . ')' ;
}
}
if ( $Title ) {
// Image proxy CTs
if ( check_perms ( 'site_proxy_images' ) && ! empty ( $UserInfo [ 'Title' ])) {
$UserInfo [ 'Title' ] = preg_replace_callback ( '~src=("?)(http.+?)(["\s>])~' ,
function ( $Matches ) {
2013-04-30 18:18:07 +00:00
return 'src=' . $Matches [ 1 ] . ImageTools :: process ( $Matches [ 2 ]) . $Matches [ 3 ];
2012-10-11 08:00:15 +00:00
},
$UserInfo [ 'Title' ]);
}
if ( $UserInfo [ 'Title' ]) {
$Str .= ' <span class="user_title">(' . $UserInfo [ 'Title' ] . ')</span>' ;
}
}
return $Str ;
}
/**
* Given a class ID , return its name .
*
* @ param int $ClassID
* @ return string name
*/
public static function make_class_string ( $ClassID ) {
global $Classes ;
return $Classes [ $ClassID ][ 'Name' ];
}
2012-10-27 08:00:09 +00:00
/**
2013-08-28 23:08:41 +00:00
* Returns an array with User Bookmark data : group IDs , collage data , torrent data
2012-10-27 08:00:09 +00:00
* @ param string | int $UserID
2013-02-25 21:16:55 +00:00
* @ return array Group IDs , Bookmark Data , Torrent List
2012-10-27 08:00:09 +00:00
*/
2013-08-28 23:08:41 +00:00
public static function get_bookmarks ( $UserID ) {
2012-10-27 08:00:09 +00:00
$UserID = ( int ) $UserID ;
2013-08-28 23:08:41 +00:00
if (( $Data = G :: $Cache -> get_value ( " bookmarks_group_ids_ $UserID " ))) {
2013-02-25 21:16:55 +00:00
list ( $GroupIDs , $BookmarkData ) = $Data ;
2012-10-27 08:00:09 +00:00
} else {
2013-08-28 23:08:41 +00:00
$QueryID = G :: $DB -> get_query_id ();
G :: $DB -> query ( "
2013-05-28 08:01:02 +00:00
SELECT GroupID , Sort , `Time`
FROM bookmarks_torrents
2013-07-10 00:08:53 +00:00
WHERE UserID = $UserID
2013-05-28 08:01:02 +00:00
ORDER BY Sort , `Time` ASC " );
2013-08-28 23:08:41 +00:00
$GroupIDs = G :: $DB -> collect ( 'GroupID' );
$BookmarkData = G :: $DB -> to_array ( 'GroupID' , MYSQLI_ASSOC );
G :: $DB -> set_query_id ( $QueryID );
G :: $Cache -> cache_value ( " bookmarks_group_ids_ $UserID " ,
2013-02-25 21:16:55 +00:00
array ( $GroupIDs , $BookmarkData ), 3600 );
2012-10-27 08:00:09 +00:00
}
2013-02-25 21:16:55 +00:00
$TorrentList = Torrents :: get_groups ( $GroupIDs );
return array ( $GroupIDs , $BookmarkData , $TorrentList );
2012-10-27 08:00:09 +00:00
}
2012-11-16 08:00:21 +00:00
2012-11-01 08:00:21 +00:00
/**
2013-04-19 08:00:55 +00:00
* Generate HTML for a user ' s avatar or just return the avatar URL
2012-11-01 08:00:21 +00:00
* @ param unknown $Avatar
* @ param unknown $Username
* @ param unknown $Setting
* @ param number $Size
* @ param string $ReturnHTML
* @ return string
*/
2013-08-28 23:08:41 +00:00
public static function show_avatar ( $Avatar , $UserID , $Username , $Setting , $Size = 150 , $ReturnHTML = True ) {
2013-05-01 08:00:16 +00:00
$Avatar = ImageTools :: process ( $Avatar );
2013-08-28 23:08:41 +00:00
$Style = 'style="max-height: 400px;"' ;
$AvatarMouseOverText = '' ;
$SecondAvatar = '' ;
$Class = 'class="double_avatar"' ;
$EnabledRewards = Donations :: get_enabled_rewards ( $UserID );
if ( $EnabledRewards [ 'HasAvatarMouseOverText' ]) {
$Rewards = Donations :: get_rewards ( $UserID );
$AvatarMouseOverText = $Rewards [ 'AvatarMouseOverText' ];
}
if ( ! empty ( $AvatarMouseOverText )) {
$AvatarMouseOverText = " title= \" $AvatarMouseOverText\ " alt = \ " $AvatarMouseOverText\ " " ;
}
if ( $EnabledRewards [ 'HasSecondAvatar' ] && ! empty ( $Rewards [ 'SecondAvatar' ])) {
$SecondAvatar = 'data-gazelle-second-avatar="' . ImageTools :: process ( $Rewards [ 'SecondAvatar' ]) . '"' ;
}
2013-04-19 08:00:55 +00:00
// case 1 is avatars disabled
switch ( $Setting ) {
2012-11-01 08:00:21 +00:00
case 0 :
2013-04-07 08:00:41 +00:00
if ( ! empty ( $Avatar )) {
2013-08-28 23:08:41 +00:00
$ToReturn = ( $ReturnHTML ? " <img src= \" $Avatar\ " width = \ " $Size\ " $Style $AvatarMouseOverText $SecondAvatar $Class /> " : $Avatar );
2013-04-07 08:00:41 +00:00
} else {
2013-04-19 08:00:55 +00:00
$URL = STATIC_SERVER . 'common/avatars/default.png' ;
2013-09-08 08:00:57 +00:00
$ToReturn = ( $ReturnHTML ? " <img src= \" $URL\ " width = \ " $Size\ " $Style $AvatarMouseOverText $SecondAvatar /> " : $URL );
2012-11-01 08:00:21 +00:00
}
break ;
case 2 :
2013-08-28 23:08:41 +00:00
$ShowAvatar = true ;
2012-11-01 08:00:21 +00:00
case 3 :
2013-08-28 23:08:41 +00:00
switch ( G :: $LoggedUser [ 'Identicons' ]) {
2012-11-01 08:00:21 +00:00
case 0 :
2013-04-19 08:00:55 +00:00
$Type = 'identicon' ;
2012-11-01 08:00:21 +00:00
break ;
case 1 :
2013-04-19 08:00:55 +00:00
$Type = 'monsterid' ;
2012-11-01 08:00:21 +00:00
break ;
case 2 :
2013-04-19 08:00:55 +00:00
$Type = 'wavatar' ;
2012-11-01 08:00:21 +00:00
break ;
case 3 :
2013-04-19 08:00:55 +00:00
$Type = 'retro' ;
2012-11-01 08:00:21 +00:00
break ;
case 4 :
2013-04-19 08:00:55 +00:00
$Type = '1' ;
2013-08-28 23:08:41 +00:00
$Robot = true ;
2012-11-01 08:00:21 +00:00
break ;
case 5 :
2013-04-19 08:00:55 +00:00
$Type = '2' ;
2013-08-28 23:08:41 +00:00
$Robot = true ;
2012-11-01 08:00:21 +00:00
break ;
case 6 :
2013-04-19 08:00:55 +00:00
$Type = '3' ;
2013-08-28 23:08:41 +00:00
$Robot = true ;
2012-11-01 08:00:21 +00:00
break ;
default :
2013-04-19 08:00:55 +00:00
$Type = 'identicon' ;
2012-11-01 08:00:21 +00:00
}
2013-04-19 08:00:55 +00:00
$Rating = 'pg' ;
2013-04-07 08:00:41 +00:00
if ( ! $Robot ) {
2013-04-19 08:00:55 +00:00
$URL = 'https://secure.gravatar.com/avatar/' . md5 ( strtolower ( trim ( $Username ))) . " ?s= $Size &d= $Type &r= $Rating " ;
2013-04-07 08:00:41 +00:00
} else {
2013-05-28 08:01:02 +00:00
$URL = 'https://robohash.org/' . md5 ( $Username ) . " ?set=set $Type &size= { $Size } x $Size " ;
2012-11-01 08:00:21 +00:00
}
2013-08-28 23:08:41 +00:00
if ( $ShowAvatar == true && ! empty ( $Avatar )) {
$ToReturn = ( $ReturnHTML ? " <img src= \" $Avatar\ " width = \ " $Size\ " $Style $AvatarMouseOverText $SecondAvatar $Class /> " : $Avatar );
2013-04-07 08:00:41 +00:00
} else {
2013-08-28 23:08:41 +00:00
$ToReturn = ( $ReturnHTML ? " <img src= \" $URL\ " width = \ " $Size\ " $Style $AvatarMouseOverText $SecondAvatar $Class /> " : $URL );
2012-11-01 08:00:21 +00:00
}
break ;
default :
2013-04-19 08:00:55 +00:00
$URL = STATIC_SERVER . 'common/avatars/default.png' ;
2013-08-28 23:08:41 +00:00
$ToReturn = ( $ReturnHTML ? " <img src= \" $URL\ " width = \ " $Size\ " $Style $AvatarMouseOverText $SecondAvatar $Class /> " : $URL );
2012-11-01 08:00:21 +00:00
}
return $ToReturn ;
}
2012-11-16 08:00:21 +00:00
2012-11-01 08:00:21 +00:00
public static function has_avatars_enabled () {
global $HeavyInfo ;
return $HeavyInfo [ 'DisableAvatars' ] != 1 ;
}
2013-07-03 08:01:01 +00:00
/**
* Checks whether user has autocomplete enabled
*
* 0 - Enabled everywhere ( default ), 1 - Disabled , 2 - Searches only
*
* @ param string $Type the type of the input .
2013-07-04 08:00:56 +00:00
* @ param boolean $Output echo out HTML
2013-07-03 08:01:01 +00:00
* @ return boolean
*/
public static function has_autocomplete_enabled ( $Type , $Output = true ) {
$Enabled = false ;
2013-08-28 23:08:41 +00:00
if ( empty ( G :: $LoggedUser [ 'AutoComplete' ])) {
2013-07-03 08:01:01 +00:00
$Enabled = true ;
2013-08-28 23:08:41 +00:00
} elseif ( G :: $LoggedUser [ 'AutoComplete' ] !== 1 ) {
2013-07-04 08:00:56 +00:00
switch ( $Type ) {
2013-07-03 08:01:01 +00:00
case 'search' :
2013-08-28 23:08:41 +00:00
if ( G :: $LoggedUser [ 'AutoComplete' ] == 2 ) {
2013-07-03 08:01:01 +00:00
$Enabled = true ;
}
break ;
case 'other' :
2013-08-28 23:08:41 +00:00
if ( G :: $LoggedUser [ 'AutoComplete' ] != 2 ) {
2013-07-03 08:01:01 +00:00
$Enabled = true ;
}
break ;
}
}
if ( $Enabled && $Output ) {
2013-07-04 08:00:56 +00:00
echo ' data-gazelle-autocomplete="true"' ;
2013-07-03 08:01:01 +00:00
}
return $Enabled ;
}
2012-10-11 08:00:15 +00:00
}