Topic: Adding avatars automatically

Hello!


At the moment I am developing a simple addon that allows my forum users to generate avatars based on some data. I would like to add some code that would automatically resize the generated image to a specified size and set it as the user's avatar on the forums - no matter whether the user already has or does not have an avatar.

If user already has uploaded avatar, it is easy to change it to the newly generated one but since I have seen some data regarding avatar in the MySQL database, I suppose it is a bit trickier to write code that would set the avatar for a use that does not have one, am I right?

Could you give me little advice what code should I use? I got overwhelmed by the CMS's code when tried to find required pieces. I am strictly interested in how to set an image as user's avatar (I can handle uploading, resizing with imagick).


Regards,
Gregoric

2 (edited by kudataz 2014-06-02 06:52)

Re: Adding avatars automatically

based on user id.
i want too..

sorry my BAD english T___T
Have a nice day >.<
(^____^)v

Re: Adding avatars automatically

There is a function for deleting an user's avatar in include/functions.php, it is called delete_avatar(). This function is visible globally, so you can use it anywhere in your addon. Setting an avatar will be a little more complicated, because there is no function for such action, you will have to write this code yourself. It is not complicated, you just need to upload file into avatar directory and then run a simple update on table users. You should analyze the file profile.php lines 1079 - 1220, there is the code responsible for setting an avatar.

If you need any help, just ask. I will be glad to help you with coding smile

If you want to contact me quickly - send e-mail, not PM.
<?php $t='<?php $t=%c%s%c; printf($t,39,$t,39,10);%c'; printf($t,39,$t,39,10);

4 (edited by Gregoric 2014-06-09 13:51)

Re: Adding avatars automatically

keeshii wrote:

There is a function for deleting an user's avatar in include/functions.php, it is called delete_avatar(). This function is visible globally, so you can use it anywhere in your addon. Setting an avatar will be a little more complicated, because there is no function for such action, you will have to write this code yourself. It is not complicated, you just need to upload file into avatar directory and then run a simple update on table users. You should analyze the file profile.php lines 1079 - 1220, there is the code responsible for setting an avatar.

If you need any help, just ask. I will be glad to help you with coding smile

Thank you, I will surely consult you smile


At the moment I have another problem.

I have been working on the interface of my project and moved some project files to different directories. One of them was my .php file that is responsible for executing script. Previously, it had been in root/awatar folder and now I have moved it to root/img/avatars. Is the access to this directory denied with htaccess somehow? I cannot submit form to this location, nor I can simply view the file. I am using folder based (fancy) rewriting, if that matters.
Edit: I have solved this problem by moving the php file with code to root directory, but I would still appreciate answer, just to know.

And another two quick questions: is there a variable somewhere in common.php or anywhere else that stores just the base forum url? Secondly, is it possible to create some redirect rule that would redirect user from /avatar to /user/[$id]/avatar/ ?

Thanks in advance

Re: Adding avatars automatically

The problems I had mentioned above are solved already.

I do have another question. How do I create a valid MySQL query? I have an external file with PHP code and I have added this code today so that I could edit some data in the database but it seems not to work.

if (!defined('FORUM_ROOT'))
          define('FORUM_ROOT', './');
      require FORUM_ROOT.'include/common.php';

        $query = array(
            'UPDATE'    => 'users',
            'SET'        => 'avatar=\'2\', avatar_height=\'125\', avatar_width=\'125\'',
            'WHERE'        => 'id='.$id
        );
        $forum_db->query_build($query) or error(__FILE__, __LINE__);

When the code is to be executed I get 'CSRF token mismatch' error. What should I do so that I could do a MySQL call from my own code? I would really appreciate help!