Posts: 322
Threads: 60
Joined: Nov 2014
Reputation:
7
2015-02-01, 07:14 AM
(This post was last modified: 2015-02-01, 01:33 PM by rajeevrrs55.)
Hello,
I need some features in my forum. is this possible.
if any anyone signup in my forum if his/her is name is "user1" his/her avatar automatically set "image of U alphabet"
the first letter of username will be default avatar of user. user can change later with his own avatar.
some example :
if username is "demo" avatar will we "image of D alphabet"
if username is "mybb" then avatar will we " image of M alphabet"
Example sites :
http://community.sitepoint.com/
hello, anybody there.
Posts: 1,062
Threads: 24
Joined: Jun 2011
Reputation:
69
I think this can be done with a rather simple plugin. Perhaps ask in "plugin requests".
Regards, Ad Bakker (NL)
Posts: 322
Threads: 60
Joined: Nov 2014
Reputation:
7
Is this possible, without any plugin with editing or any existing plugin.
Or move this thread to plugin request section.
Posts: 1,062
Threads: 24
Joined: Jun 2011
Reputation:
69
2015-02-01, 05:09 PM
(This post was last modified: 2015-02-01, 08:48 PM by Ad Bakker.)
If you have some patience I can try to do it tonight after dinner (it's 6:08 pm here now).
Here it is:
<?php
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("member_do_register_end", "default_avatar");
function default_avatar_info()
{
global $lang;
return Array(
'name' => "default avatar",
'description' => "assigns a default avatar at registration depending on 1st letter of username",
'website' => '',
'author' => 'Ad Bakker',
'authorsite' => '',
'version' => '1.0',
'guid' => '',
'compatibility' => '18*',
);
}
function default_avatar()
{
global $user_info, $db;
$file = "./default_avatars/image of ".strtoupper(substr($user_info['username'],0,1))." alphabet.jpg";
if (!file_exists($file)) return;
$size = getimagesize($file);
$avatar_array = array(
'avatar' => "{$file}",
'avatardimensions' => "{$size[0]}|{$size[1]}",
'avatartype' => "remote");
$db->update_query("users", $avatar_array, "username = \"{$user_info['username']}\"");
}
?>
Place your default avatars in a subdirectory of your home directory named "default_avatars".
I have tested it with a .jpg avatar, if you use .png or .gif files change this at the end of line 25.
The avatars must have exactly the name as you described, for instance for a user with a name starting with an "n" the avatar name must be "image of N alphabet.jpg" (or another extension). Note that the n is capitalized to N!!!
I tested it and it works.
Regards, Ad Bakker (NL)
Posts: 322
Threads: 60
Joined: Nov 2014
Reputation:
7
2015-02-02, 11:22 AM
(This post was last modified: 2015-02-03, 07:50 AM by rajeevrrs55.)
Thanks you.
let me try.
great it works.
make a plugin and publish in all mods of mybb so every one get a benefit of this.
Posts: 674
Threads: 141
Joined: Sep 2013
Reputation:
11
(2015-02-01, 05:09 PM)Ad Bakker Wrote: If you have some patience I can try to do it tonight after dinner (it's 6:08 pm here now).
Here it is:
<?php
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("member_do_register_end", "default_avatar");
function default_avatar_info()
{
global $lang;
return Array(
'name' => "default avatar",
'description' => "assigns a default avatar at registration depending on 1st letter of username",
'website' => '',
'author' => 'Ad Bakker',
'authorsite' => '',
'version' => '1.0',
'guid' => '',
'compatibility' => '18*',
);
}
function default_avatar()
{
global $user_info, $db;
$file = "./default_avatars/image of ".strtoupper(substr($user_info['username'],0,1))." alphabet.jpg";
if (!file_exists($file)) return;
$size = getimagesize($file);
$avatar_array = array(
'avatar' => "{$file}",
'avatardimensions' => "{$size[0]}|{$size[1]}",
'avatartype' => "remote");
$db->update_query("users", $avatar_array, "username = \"{$user_info['username']}\"");
}
?>
Place your default avatars in a subdirectory of your home directory named "default_avatars".
I have tested it with a .jpg avatar, if you use .png or .gif files change this at the end of line 25.
The avatars must have exactly the name as you described, for instance for a user with a name starting with an "n" the avatar name must be "image of N alphabet.jpg" (or another extension). Note that the n is capitalized to N!!!
I tested it and it works.
Where to add this code?
Posts: 62
Threads: 13
Joined: May 2015
Reputation:
2
(2015-12-05, 06:37 PM)Dr_The_One Wrote: (2015-02-01, 05:09 PM)Ad Bakker Wrote: If you have some patience I can try to do it tonight after dinner (it's 6:08 pm here now).
Here it is:
<?php
if(!defined("IN_MYBB"))
{
die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$plugins->add_hook("member_do_register_end", "default_avatar");
function default_avatar_info()
{
global $lang;
return Array(
'name' => "default avatar",
'description' => "assigns a default avatar at registration depending on 1st letter of username",
'website' => '',
'author' => 'Ad Bakker',
'authorsite' => '',
'version' => '1.0',
'guid' => '',
'compatibility' => '18*',
);
}
function default_avatar()
{
global $user_info, $db;
$file = "./default_avatars/image of ".strtoupper(substr($user_info['username'],0,1))." alphabet.jpg";
if (!file_exists($file)) return;
$size = getimagesize($file);
$avatar_array = array(
'avatar' => "{$file}",
'avatardimensions' => "{$size[0]}|{$size[1]}",
'avatartype' => "remote");
$db->update_query("users", $avatar_array, "username = \"{$user_info['username']}\"");
}
?>
Place your default avatars in a subdirectory of your home directory named "default_avatars".
I have tested it with a .jpg avatar, if you use .png or .gif files change this at the end of line 25.
The avatars must have exactly the name as you described, for instance for a user with a name starting with an "n" the avatar name must be "image of N alphabet.jpg" (or another extension). Note that the n is capitalized to N!!!
I tested it and it works.
Where to add this code?
Make a php file in the plugin folder.
default_avatar.php should work.
Posts: 1,001
Threads: 187
Joined: Aug 2010
Reputation:
16
Apologies in advanced for bumping a rather old thread, but is there a way to run this plugin across already registered users who haven't changed their default avatar?
|