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

Insert data from Profile Extender fields into Discussion Header

meshugymeshugy Musician/Hacker ✭✭
edited January 2014 in Vanilla 2.0 - 2.8

I successfully placed users location field data into the Discussion Header using this code in the class.profilecontroller.php file (see image):

echo WrapIf(htmlspecialchars(GetValue('Location', $Author)), 'span', array('class' => 'MItem AuthorLocation'));

The RoleTitle plugin inserts the user's role into the Discussion Header.

Now, I'd like to insert a field into the Discussion Header from the Profile Extender plugin. The Profile Extender data is stored in the UserMeta database and I'm not sure how to get that to display. Does anyone have a clue as how this might be done?

«1

Comments

  • Options
    peregrineperegrine MVP
    edited January 2014

    try looking at other plugins. you could to do something like this
    Basically...

    1. You need to get the UserID of user in the Discussion. and the Name of the Profile field
    2. Pick an Event to trigger on
      DiscussionController_AuthorInfo_Handler or something else
    3. Get data via a method you can use in the event if you can find one
      like GetUserMeta

    or if you have to read database directly...

    something like this

    $SQL = Gdn::SQL();
    $this->PfeData = $SQL
    ->Select('*')
    ->From('UserMeta')
    ->Where(array('UserID' =>$UserIDfromDiscussion,'Name' => $NameofProfileField )
    ->Get()->ResultArray();
    }
    your data would be in here (extract as you want.
    $this->PfeData;
    
    1. echo out the data.

    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
    peregrineperegrine MVP
    edited January 2014

    I used profileextender - added a field called Testing.

    entered some values in Testing field for several users.

    modified the roletitle plugin and it displayed fine. There may be a better way to do it. and you may need to adjust accordingly, but it works.

    this is the code for the function.

      public function DiscussionController_AuthorInfo_Handler($Sender) {
        $this->_AttachTitle($Sender);
        $Author = $Sender->EventArguments['Discussion'];
        $AuthorID = $Author->InsertUserID;
        $NameofProfileField = "Profile.Testing";
    
        $SQL = Gdn::SQL();
        $this->PfeData = $SQL
        ->Select('*')
        ->From('UserMeta')
        ->Where(array('UserID' =>$AuthorID,'Name' => $NameofProfileField ))
        ->Get()->ResultArray();
        echo WrapIf(htmlspecialchars(GetValue('Value', $this->PfeData["0"])), 'span', array('class' => 'MItem AuthorTesting'));
    
    
        }
    

    there may be a better way getting db data by joining meta with discussion model and getting it all in fell swoop. i'll leave that to someone else.

    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

    shazam was the value in Testing Field in profile extender.

    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
    peregrineperegrine MVP
    edited January 2014

    @meshugy.

    As an alternative if you have a field that you would like an image for, you could also use
    http://vanillaforums.org/addon/symboledit-plugin
    It is the plugin I most enjoyed writing. You could have images for different types of guitars user plays.

    @phreak did a beautiful job with icon placement by positioning it abutting the user avatar on one of his websites with it. I don't know if he still uses it but if he does, maybe he will post a screenshot with it.

    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
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    I was going to mention the symbol edit plugin too, but I did not want to risk it being a red herring... :)

  • Options
    meshugymeshugy Musician/Hacker ✭✭

    @peregrine wow, this was nice to wake up to! thanks for figuring this out. I'm not sure where to insert the code you posted into the roletitle plugin. I tried a few places and it didn't work. Any clues?

    Also, the symboledit plugin is a great idea. I'll look into that. I had seen it before but it hadn't occurred to me to use it with guitars, nice idea!

  • Options
    peregrineperegrine MVP
    edited January 2014

    you could change around line 33 in class.roletitle.plugin.php

     public function DiscussionController_AuthorInfo_Handler($Sender) {
          $this->_AttachTitle($Sender);
       }
    
    
    to
    
         public function DiscussionController_AuthorInfo_Handler($Sender) {
            $this->_AttachTitle($Sender);
            $Author = $Sender->EventArguments['Discussion'];
            $AuthorID = $Author->InsertUserID;
            // change this to the field name you want 
           $NameofProfileField = "Profile.Testing";
    
            $SQL = Gdn::SQL();
            $this->PfeData = $SQL
            ->Select('*')
            ->From('UserMeta')
            ->Where(array('UserID' =>$AuthorID,'Name' => $NameofProfileField ))
    
            ->Get()->FirstRow(DATASET_TYPE_ARRAY);
            echo WrapIf(htmlspecialchars(GetValue('Value', $this->PfeData)), 'span', array('class' => 'MItem AuthorTesting'));
    
    }
    

    the sql could be changed to do multiples fields if you wanted to use like

    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
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    @meshugy here are some free icons of guitars

    http://findicons.com/search/guitar

    this one reminds me of someone....

  • Options
    meshugymeshugy Musician/Hacker ✭✭

    @peregrine thanks, that worked! But one problem, it doesn't properly map the ProfileExtender field data to the corresponding user. For example, if I have "Busato" in the "My Guitar" field of the ProfileExtender, every user on the page also gets "Busato" posted in the Discussion Header, regardless of whether they have any data in that field or not. Do you know what the problem is?

  • Options
    meshugymeshugy Musician/Hacker ✭✭

    Here is what I mean....

  • Options
    meshugymeshugy Musician/Hacker ✭✭
    edited January 2014

    @vrijvlinder thanks, however the guitars we Gypsy jazzers play are a bit different: http://www.djangobooks.com/Category/handbuilt-guitars

    I think a user defined text field is the best way for people to indicate which guitar they own. I like the idea of the symboledit plugin, but I'd have to create a hundred icons to represent all the different models of guitars my users play.

  • Options
    peregrineperegrine MVP
    edited January 2014

    @meshugy - you are too good at QC :)

       public function DiscussionController_AuthorInfo_Handler($Sender) {
            $this->_AttachTitle($Sender);
    
           $Type= $Sender->EventArguments['Type'];
            if ($Type == 'Discussion') {
            $Author = $Sender->EventArguments['Discussion'];
            } else {
            $Author = $Sender->EventArguments['Comment'];
            }
            $AuthorID = $Author->InsertUserID;
            $NameofProfileField = "Profile.Testing";
    
            $SQL = Gdn::SQL();
            $this->PfeData = $SQL
            ->Select('*')
            ->From('UserMeta')
            ->Where(array('UserID' =>$AuthorID,'Name' => $NameofProfileField ))  
            ->Get()->FirstRow(DATASET_TYPE_ARRAY);
            echo WrapIf(htmlspecialchars(GetValue('Value', $this->PfeData)), 'span', array('class' => 'MItem AuthorTesting'));  
            }
    

    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
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited January 2014

    yikes, 36,000 smackers !! for that Selmer !! I thought gypsies were frugal ...

    Yes the symbol edit can be used to select a type of instrument, for example a bass or drums etc. I am modifying that for myself.

    However you can simply take all the images of the 100's of guitars and batch edit them to a certain size, it would be worth it in the end as long as the icons were large enough to discern between models.

  • Options
    meshugymeshugy Musician/Hacker ✭✭

    @peregrine Perfect, thanks!

  • Options
    meshugymeshugy Musician/Hacker ✭✭
    edited January 2014

    @vrijvlinder Yeah, the old vintage Selmer guitars sell for a lot. But nothing compared to what people pay for pre-CBS stratocasters and D'Angelico archtops. Those goes into the 6 and 7 figures!

    I'll think about a way to use the symboledit, but think the details of each guitar are so specific that an image can't represent all the variations clearly.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    You could use the names of the models linked to a gallery image of the guitar. When people hover over the name of the model an image can pop up. That would be a cool thing for sure.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    John D'Angelico

    The brand has passed many hands, I tried those at a NAMM show. Very nice guitars for sure. But I would stop short of paying those figures. I am not a gypsy but I am frugal ;)

  • Options
    meshugymeshugy Musician/Hacker ✭✭

    @vrijvlinder said:
    You could use the names of the models linked to a gallery image of the guitar. When people hover over the name of the model an image can pop up. That would be a cool thing for sure.

    Now we're talking! But there a number of problems, biggest of which is creating a database of images that would correctly map to the 100s of possible guitar variations. I still think it's probably not that practical for me, but could work for others. I'll think about it some more and see if I can think of a way something like that would work.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    There are several ways to do it. You could start with known models of your users.
    Then you can poll the users to see what other brands or models to add. Good way to test for participation.

    You can collect as many images as you can, then batch convert them and name them. So they can be organized.

    Check these out could help you get an idea , could be done with just css and html or using js. I have hover zoom in my browser which allows me to see the images in an image link when I hover. This is pretty much the same idea. The biggest part of this job will be creating the image pool and linking the names of the models to the images.

    http://www.dynamicdrive.com/style/csslibrary/item/css-popup-image-viewer/

    http://www.scientificpsychic.com/etc/css-mouseover.html

    http://www.nicolashoening.de/?twocents&nr=8

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited January 2014

    Maybe an easier way would be to let them put an image link to their model of choice then use hover zoom type js to target those links to pop up the image.

    to minimize external requests you could have them upload their image into the Galleries plugin and link to the image.They Put the link in the field for profile extender or role title you modified to take the link and add a class to it so the popup on hover can have something to latch on to.

    All you would need to do is add the javascript to your master to target the image links/names of models to popup on hover.

    a simple way to do it

         the css
    
         a img.guitar { display:none; }
         a:hover img.guitar { display:block; }
    
    the way the links would look    
    
          <a href="#">Selmer model xxx<img class="guitar" src="http://image of the guitar" /></a>
    

    See how it work here

    https://sites.google.com/site/annuairevin/test-over

    These are other examples using mostly css to get that effect however the crucial thing to do in these is to add the class to the link. So for that field you would have to give whatever link they add in that field, a class so the css can target that specific type of link.

    http://www.code-sucks.com/code/css/popup-images-on-rollover.php

Sign In or Register to comment.