HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

QuotedMentionUserImageRecognition Plugin Coop

vrijvlindervrijvlinder Papillon-Sauvage MVP

I decided to open this discussion here because I need input from you about this latest endeavor , which is to add the Authors avatar to the Quotes plugin and make a version for 2.1 and 2.0.

So far I have been able to get this going but with a few bugs.

I suppose this began as a bit of a joke but I thought, It helps to see who the author of the quote is much better when their picture is on the hew said she said.

If you don't think so, just wait until you need reading glasses and remember me...

List of reason to make this work

There is nothing like it out there like this (except on facebook :())

It helps to recognize the Author and relates the content better than with a name prevents mixups of who quoted who.

Gives the content in the quote a more personal touch to see the image of the author as one reads .

I could think of more...

I got this to work on 2.1 and 2.0 yes 2.0 you just need to scale down on the spritefest and change one handler from AfterFlags Handler to AfterComment handler . Insert the @ for 2.0 to link the name in the blockquote section

Then comes the tricky part being we deal with formatting . So apparently all the available types of possible formatting combos need to be applied also adding this to all and inserting into the code where necessary

$photo = UserPhoto(Gdn::Session()->User->QuoteAuthor);

This is the callback function for the author notice where I inserted the $photo

 protected function QuoteAuthorCallback($Matches) {
      $photo = UserPhoto(Gdn::Session()->User->QuoteAuthor);   
      $Attribution = T('%s said:');
      $Link = Anchor($Matches[2], '/profile/' . $Matches[2], '', array('rel' => 'nofollow'));
      $Attribution = sprintf($photo, $Attribution, $Link);
      return <<<BLOCKQUOTE
      < blockquote class="UserQuote" >< div class="UserPhoto" >{$photo}< /div >< div class="QuoteAuthor" >{$Attribution}< /div >< div class="QuoteText" >< p >
BLOCKQUOTE;
   }

Here is the Format selection part depending on the chosen format

// Format the quote according to the format.
         switch ($Format) {
            case 'Html':   // HTML
                $photo = UserPhoto(Gdn::Session()->User->QuoteAuthor);  
               $Quote = '< blockquote class="Quote" rel="' .$photo. htmlspecialchars($Data->InsertName) . '">' . $Data->Body . '< /blockquote >' . "\n";
               break;

            case 'BBCode':
               $photo = UserPhoto(Gdn::Session()->User->QuoteAuthor);  
               $Author = htmlspecialchars($Data->InsertName);
               if ($ID)
                  $IDString = ';' . htmlspecialchars($ID);

               $QuoteBody = $Data->Body;

               // TODO: Strip inner quotes...
//                  $QuoteBody = trim(preg_replace('`(\[quote.*/quote\])`si', '', $QuoteBody));

               $Quote = <<<BQ
[quote="{$photo}{$Author}{$IDString}"]{$QuoteBody}[/quote]

BQ;
               break;

            case 'Markdown':
            case 'Display':
            case 'Text':
               $QuoteBody = $Data->Body;

               // Strip inner quotes and mentions...
               $QuoteBody = self::_StripMarkdownQuotes($QuoteBody);
               $QuoteBody = self::_StripMentions($QuoteBody);

               $Quote = '> ' . sprintf(T('%s said:'), '@' . $Data->InsertName) . "\n" .
               '> ' . str_replace("\n", "\n> ", $QuoteBody);

               break;
            case 'Wysiwyg':
               $photo = UserPhoto(Gdn::Session()->User->QuoteAuthor);  
               $Attribution = sprintf(T('%s said:'), UserAnchor($Data, NULL, array('Px' => 'Insert')));
               $QuoteBody = $Data->Body;

               // TODO: Strip inner quotes...
//                  $QuoteBody = trim(preg_replace('`()`si', '', $QuoteBody));

               $Quote = <<<BLOCKQUOTE
< blockquote class="Quote" >
< div class="UserPhoto">$photo< /div >
< div class="QuoteAuthor">$Attribution
 < div class="QuoteText">$QuoteBody
< /blockquote >

BLOCKQUOTE;

               break;

at the moment I am having some odd things happen, with the vanillicons and the name of the author being switched when the quote has nested quotes see pic below.

Comments

  • peregrineperegrine MVP
    edited June 2013

    what problem with vanillicons - the wrong ones all the time if so, you need to stuff the email address in the array.

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

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    I think it is grabbing profile zero vanillicon because that is what it's link says.

    I think I may need to specify more about the AuthorPhoto as you say ....

    The text links go to the right place but the last quote used my name but it was not me who said, unless that is how this works, it quotes the last quoter of a certain quote .... not necessarily the original quoter ?

    I think that is an issue with allowing 5 nested quotes. Works ok using one or even two the it wigs out

  • peregrineperegrine MVP
    edited June 2013

    you can tell if the vanillicons are correct or not, use the memberslistenhanced and compare vanillicons to the same user you are displaying the vanillicon in the plugin. if none of the vanillicons are correct you have to build your own user array.

    this is the only thing I'm talking about is correct display of vanillicon

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

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited June 2013

    Will try that although I am not using a vanillicon and it puts one in the same default orange one. For one I don't have vanillicon plugin how odd and I don't have an email with vanillicons either , lol I have Gravatar

    Unless vanillicons are standard in 2.1 ?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    It is definitely tied to the $photo line

    $photo = UserPhoto(Gdn::Session()->User->QuoteAuthor);

    when I remove the QuoteAuthor it uses the current user photo with the QuoteAuthor it gets vanillicon for profile 0

  • peregrineperegrine MVP
    edited June 2013

    like I said, if you don't have the proper email tied to user. userphoto will not work with vanillicons and probably not with gravatars.

    you need to user UserBuilder first or create a user object that includes email.

    UserPhoto - expects a User object

    /**
    * Takes a user object, and writes out an anchor of the user's icon to the user's profile.
    */

    look at UserPhoto routine in core - you will learn.

    e.g.
    http://vanillaforums.org/discussion/comment/177316/#Comment_177316

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

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Excellent resource !! yea it needs something like that , I think it only works if user uploaded image. Have not tested with gravatar, where do the vanilicons come from ? normally it is a default user gif if they don't have a pic uploaded....

  • @vrijvlinder

    where do the vanilicons come from ?

    the mothership.

    http://vanillaforums.org/addon/vanillicon-plugin

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

  • Vanillicons come with the Gravatar plugin in 2.1.

    Add Pages to Vanilla with the Basic Pages app

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited June 2013

    Oh no wonder !! That explains it , thanks Shadowdare , yea p I know there is a plugin but I did not install it only have Gravatar enabled. That is the source for these . Cool I had no idea it came in a package. So I guess if there is no gravatar image the default is vanillicon .

    I will be working on these modes taken from the who's online example. I need go out and take care of something but will work on it tonight. Last night I was too tired to continue.

  • LincLinc Detroit Admin

    There's a config setting in Gravatar to disable Vanillicon.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    @Lincoln

    Ah thanks , I like the vanillicons I think I will keep them , just for now I will disable them so I can figure this out. for this plugin's mods.

    Off topic , it is amazing how close the vanillicon resembles the personality of the poster. If that is not it, then it is a psychological thing that we tend to relate personality based on a picture.

    Some vanillicon really match the person !

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited June 2013

    @peregrine

    I was able to get the photo wrap going to at least link the user image. Although I am still trying to match the image with the author. It seems that the way it is the author of the quote it the one quoting the quoter. This is what the link look like after formatting.

    < div class="QuoteAuthorPhoto" >< a title="Admin" href="/foro/profile/4/Admin" class="PhotoWrap" >< img src="http://www.fumamx.org/foro/uploads/userpics/623/nQ7VX4NGUHAE2.png" alt="Admin" class="ProfilePhoto ProfilePhotoMedium" >< /a >< /div >
    < div class="QuoteAuthor" >< a href="/foro/profile/4/Admin" >Admin< /a > said:< /div >
     < div class="QuoteText" >Que bien funciona Soundcloud  :X < /div >
    
    

    and this is what it looks like when it is quoted

    
    
    < blockquote class="Quote" >
    < div class="QuoteAuthor" >< a title="Blunt" href="/foro/profile/5/Blunt" class="PhotoWrap" >< img src="http://www.fumamx.org/foro/uploads/userpics//hermes/waloraweb093/b2019/moo.vrijvlinder/fumamx/foro/uploads/nDBH0XTC1KLBU.jpeg" alt="Blunt" class="ProfilePhoto ProfilePhotoMedium" / >< /a >< a href="/foro/profile/4/Admin">Admin< /a > said:< /div >
     < div class="QuoteText">Que bien funciona Soundcloud  :X < /div >
    < /blockquote >
    

    I think I need to modify the ARguments somewhere in here to add the image. Then the callback would match 3 instead of 2 and hopefully match the author and their image. is this logic correct ?

    $Sender->EventArguments['Object']->Body = preg_replace_callback("/(< blockquote\s+(?:class=\"(?:User)?Quote\")?\s+rel=\"([^\"]+)\">)/ui", array($this, 'QuoteAuthorCallback'), $Sender->EventArguments['Object']->Body);
                $Sender->EventArguments['Object']->Body = str_ireplace('< /blockquote >','< /blockquote >',$Sender->EventArguments['Object']->Body);
    
    
  • peregrineperegrine MVP
    edited June 2013

    V,

    I would recommend:

    since preg_replace_callback is matching a pattern and then performing a function on the matched pattern. Dump what is happening in the call back function. test the pattern, understand the pattern match and dump the match array. Also nothing is stopping you from doing a preg match or multiple preg functions in the callback itself and storing intermediate variables.

    I would put some variable dumps in a test program outside of vanilla and see what you get.
    also dump the matches - you might not have what you think you have until you break it down.

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

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    preg_replace_callback("/(< blockquote\s+(?:class=\"(?:User)?Quote\")?\s+rel=\"([^\"]+)\">)/ui"

    is

    div class QuoteAuthor plus div class QuoteText linked to User Id

    dump the match array

    yes I thought about that, my brain is fried :(

    It would be great if it could just clone the whole thing including the AuthorWrap which I found resides in discussions.php

    Instead of just the author link. Or replace the author link with the author avatar.

    I will get back to it later , I have reached max saturation point

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited June 2013

    ok I came up with an idea for this, since there is no specific class for the link of the author besides quote Author and that only happens after being quoted, it is a temporary state and the only constant is the link to the user profile the quoted author.

    UserPhoto calls the user photo so that is not working.

    What if I can substitute the link of the author using pregreplace for the image

     case 'Wysiwyg':
                $Sender->EventArguments['Object']->Body = preg_replace_callback("/(< blockquote\s+(?:class=\"(?:User)?Quote\")?\s+rel=\"([^\"]+)\">)/ui", array($this, 'QuoteAuthorCallback'), $Sender->EventArguments['Object']->Body);
    
    $Sender->EventArguments['Object']->Body =if (preg_match('#(http://[^\s]+(?=\.(jpe?g|png|gif)))#i', array($this, 'QuoteAuthorCallback'), $Sender->EventArguments['Object']->Body);
        {            
    
    $Sender->EventArguments['Object']->Body = preg_replace('#(http://[^\s]+(?=\.(jpe?g|png|gif)))(\.(jpe?g|png|gif))#i', '< img src="$1.$2" alt="$1.$2" / >',  array($this, 'QuoteAuthorCallback'), $Sender->EventArguments['Object']->Body);
        else
    }
    
    $Sender->EventArguments['Object']->Body =preg_replace('#(http://[^\s]+(?!\.(jpe?g|png|gif)))#i', '< a href="$1" rel="nofollow" target="_blank" title="$1" class="ProfileLink">$1< /a >',  array($this, 'QuoteAuthorCallback'), $Sender->EventArguments['Object']->Body);
    
    
    
    $Sender->EventArguments['Object']->Body = str_ireplace('< /blockquote >','< /p >< /div >< /blockquote >',$Sender->EventArguments['Object']->Body);
                break;
    

    Hope something good happens :)

Sign In or Register to comment.