Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

[V2.0.18.8] Two-in-one: "new user registered callback/ default user image" and "updating a DB value"

Hello again!

I'm quite liking Vanilla so far, but there're still two small challenges I'm currently facing.

First, I would like all of my members to have a default user picture. There doesn't seem to be a standard option for this, so I was wondering if there is some kind of callback I can use when a user registers so I can set it automatically.

The second question ties in neatly to this, namely "how would I set this"? I am also offering some standard pictures for my users to use, and here I'm facing the same problem. I moved these images to "uploads/userpics/default" for consistencies sake and am presenting them to the user. Once they click an item though, what should happen? I mean, I could write a setUserPic.php script, but I'm guessing there's an easier/ more preferred way of going about this. Any tips?

And no, I haven't updated yet, but yes, I will soon. ;)

Best Answers

  • Options
    x00x00 MVP
    edited December 2013 Answer ✓

    sorry there is also UserPhotoDefaultUrl

    This is a function you can predefine in conf/boostrap.before.php (create this file)

    <?php if (!defined('APPLICATION')) exit();
    if (!function_exists('UserPhotoDefaultUrl')) {
      function UserPhotoDefaultUrl(){
         return Url('path/to/image');
      }
    }
    

    grep is your friend.

  • Options
    hgtonighthgtonight ∞ · New Moderator
    Answer ✓

    APPLICATION is defined in the index.php file and it is checked at the beginning of most files to prevent them from being executed outside the framework. Which is a good thing.

    Wrap your code in a plugin. Check out my Testing Ground plugin for a quick way to get into plugin development.

    https://github.com/hgtonight/Plugin-TestingGround

    This plugin will execute the Controller_Index() method when requesting 'http://forum.example.com/plugin/testingground/`. Put your code in that function and query it via AJAX.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    R_JR_J Ex-Fanboy Munich Admin
    Answer ✓

    @x00 said:
    that applies to making a fork too.

    I think this is a very important part of the sentence you're disagreeing: if you are changing the core you are technically forking the project. If you by any means want to fork the repo, do it in a way that you can track your changes easily. That's how I read x00s statement ;)

    But originally I just wanted to give another solution for your problem. It might be the most dirtiest of all possibilities here, but it is the least obtrusive from the framework point of view...

    That makes your picture the default value in user table so it will be used for each new user

    ALTER TABLE `GDN_User` CHANGE `Photo` `Photo` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT 'http://forum.example.com/path/to/your/usericon.png'
    

    And that will update the picture for every user who has not set his profile picture yet

    UPDATE `GDN_User` SET `Photo` = 'http://forum.example.com/path/to/your/usericon.png' WHERE `Photo` IS NULL
    
«1

Answers

  • Options

    First, I would like all of my members to have a default user picture. There doesn't seem to be a standard option for this, so I was wondering if there is some kind of callback I can use when a user registers so I can set it automatically.

    Simplest way just use gravatar pluign and you can change the default image.

    You wouldn't have to set anything in the db.

    grep is your friend.

  • Options
    SenshiSenshi New
    edited December 2013

    @x00: I'm afraid I really don't want to use gravatar for my forum though; otherwise it would have been fine. =)

    EDIT: This also wouldn't solve the issue for the default avatars I'm afraid.

  • Options
    x00x00 MVP
    edited December 2013 Answer ✓

    sorry there is also UserPhotoDefaultUrl

    This is a function you can predefine in conf/boostrap.before.php (create this file)

    <?php if (!defined('APPLICATION')) exit();
    if (!function_exists('UserPhotoDefaultUrl')) {
      function UserPhotoDefaultUrl(){
         return Url('path/to/image');
      }
    }
    

    grep is your friend.

  • Options
    x00x00 MVP
    edited December 2013

    if you only care about discussions list, comments then that predefined function will do the job.

    Because they use the UserPhoto function.

    grep is your friend.

  • Options
    LincLinc Detroit Admin

    Yes, UserPhotoDefaultUrl works for a code solution. I was actually reticent to mention it because I couldn't remember what version we introduced it, haha.

  • Options
    SenshiSenshi New
    edited December 2013

    Thanks both, UserPhotoDefaultUrl seems to work fine, though I had to forego the Url()* call, and it also seems to add an 'n' character before the picture's filename. It seems this is just a Vanilla thing though?

    I can definitely ensure valid values for it, so I'll take a look at the $UserMode->Save() method; thanks!

    *The code I'm using now, just in case a future visitor sees this:

    <?php if (!defined('APPLICATION')) exit();
        if (!function_exists('UserPhotoDefaultUrl')) {
            function UserPhotoDefaultUrl(){
                return ('path/to/image.png'; //produces 'path/to/nimage.png'
            }
        }
    ?>
    
  • Options

    Ah, gotcha; perfect, thanks a bunch!! =D

  • Options
    SenshiSenshi New
    edited December 2013

    Apologies for the many questions; I promise this is the last one. =)

    I can get the "standard avatar" system working by executing $UserModel->Save() from inside an existing .php file and a $_GET variable, but I was wondering if I can cleanly separate this out somehow and call it using AJAX. Simply making an additional .php file isn't working as 'APPLICATION' isn't defined. Is there an easy way of giving this script access to 'APPLICATION' somehow?

  • Options
    x00x00 MVP
    edited December 2013

    Senshi if you are going to delve into proper development, I would broadly read the docs.

    You should not edit the core, nor do you request individual scripts bypassing the dispatcher and framework. Not in a modern MVC framework.

    grep is your friend.

  • Options
    hgtonighthgtonight ∞ · New Moderator
    Answer ✓

    APPLICATION is defined in the index.php file and it is checked at the beginning of most files to prevent them from being executed outside the framework. Which is a good thing.

    Wrap your code in a plugin. Check out my Testing Ground plugin for a quick way to get into plugin development.

    https://github.com/hgtonight/Plugin-TestingGround

    This plugin will execute the Controller_Index() method when requesting 'http://forum.example.com/plugin/testingground/`. Put your code in that function and query it via AJAX.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options
    SenshiSenshi New
    edited December 2013

    @x00: Eh, I was afraid you'd say that. Normally I would definitely go that route, but this forum is really just an "extra appendage", if anything, to my project, so I'd rather not spend too much time getting to know Vanilla and doing everything "the right way". I know it's bad practice, but in my case I think the time and effort involved just isn't worth it. I've only made some very small changes (and yes, one or two little hacks), and this is the last one. I'll just go with my working approach then. =)

    Thanks again for both your help, it's very much appreciated!!
    Cheers!

  • Options
    peregrineperegrine MVP
    edited December 2013

    @Senshi said:
    x00: Eh, I was afraid you'd say that. Normally I would definitely go that route, but this forum is really just an "extra appendage", if anything, to my project, so I'd rather not spend too much time getting to know Vanilla and doing everything "the right way". I know it's bad practice, but in my case I think the time and effort involved just isn't worth it. I've only made some very small changes (and yes, one or two little hacks), and this is the last one. I'll just go with my working approach then. =)

    Thanks again for both your help, it's very much appreciated!!
    Cheers!

    well, at least the responses may have been insightful for you! (hint: clicking insightful)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @Senshi said:
    I've only made some very small changes (and yes, one or two little hacks), and this is the last one. I'll just go with my working approach then. =)

    I have no problem with people hacking the core for personal projects. I really don't.

    It makes it impossible to support, however.

    @Senshi said:
    Thanks again for both your help, it's very much appreciated!!
    Cheers!

    Same to you :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Options

    @hgtonight said:
    I have no problem with people hacking the core for personal projects. I really don't.

    Honestly, that's refreshing to hear; really glad to hear I'm not the only one who thinks like this! Your solution worked perfectly btw, thank you so much!

    @peregrine said:
    well, at least the responses may have been insightful for you! (hint: clicking insightful)

    They have most definitely been! Thanks for the reminder!

    I promise I'm not normally so haphazard about things; next time I use Vanilla I'll be sure to go about it the proper route. It's a great piece of software! =)

  • Options

    tbh honest it should be discouraged, unless the person is willing to maintain that fork and knows what they are getting into. Not becuase they think they are saving time, when long term they are in for a world of pain.

    Any security update will overwrite those changes, unless they are using some version control software an have prepared a patch which they will then have to resolve to apply it.

    Doing thing properly is always the best option, that applies to making a fork too.

    grep is your friend.

  • Options

    @x00 said:
    Doing thing properly is always the best option, that applies to making a fork too.

    I'll have to politely disagree here. Learning Vanilla and figuring out how to do what I did the right way would probably take me quite a few days. In my case that's just not worth it. I don't even know if the forum will be used after my app's closed beta, and any changes I made to the core can be redone in ±20-30 minutes I reckon.

    I get what you're saying, I really do, but "always" is a very strong word. =)

  • Options
    R_JR_J Ex-Fanboy Munich Admin
    Answer ✓

    @x00 said:
    that applies to making a fork too.

    I think this is a very important part of the sentence you're disagreeing: if you are changing the core you are technically forking the project. If you by any means want to fork the repo, do it in a way that you can track your changes easily. That's how I read x00s statement ;)

    But originally I just wanted to give another solution for your problem. It might be the most dirtiest of all possibilities here, but it is the least obtrusive from the framework point of view...

    That makes your picture the default value in user table so it will be used for each new user

    ALTER TABLE `GDN_User` CHANGE `Photo` `Photo` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT 'http://forum.example.com/path/to/your/usericon.png'
    

    And that will update the picture for every user who has not set his profile picture yet

    UPDATE `GDN_User` SET `Photo` = 'http://forum.example.com/path/to/your/usericon.png' WHERE `Photo` IS NULL
    
  • Options

    @R_J said:
    I think this is a very important part of the sentence you're disagreeing: if you are changing the core you are technically forking the project. If you by any means want to fork the repo, do it in a way that you can track your changes easily. That's how I read x00s statement :wink:

    I guess that's technically true; it is now a fork. And I definitely agree tracking the changes would be a huge time (and sanity) saver. =)

    @R_J said:
    But originally I just wanted to give another solution for your problem. It might be the most dirtiest of all possibilities here, but it is the least obtrusive from the framework point of view...

    Ha, that would probably have been the easiest route! Silly I missed that; thanks for contributing!
    I still needed the function for the "standard" avatars though. =)

Sign In or Register to comment.