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.

Facebook, Twitter and GooglePlus for Articles


I would like to offer Facebook, Twitter and GooglePlus share buttons beneath articles (from the articles application) in the same way as they appear beneath discussions and comments.

However, after looking into the code of the respective social plugins as well as the vanilla core (on version 2.2b1), I would like to hear your opinion on how to proceed.

The problem is as follows (same as

Each of these social plugins declares a method on the PostController e.g. PostController_Facebook_Create($Sender, $RecordType, $ID) that makes a call to a function GetRecord($RecordType, $ID) which is defined in library/core/functions.general.php.

The GetRecord() function only supports "discussion", "activity" or "comment" for the RecordType argument, which are from the Vanilla app.

If I could just extend this function and add support for the "article" RecordType, everything would be fine, the social plugins would work without modification. However, I found out that functions from library/core/functions.general.php cannot be overwritten by plugins.

I really don't like adding code to the global bootstrap.*.php, also it is not recommended to overwrite functions from functions.general.php. Do I then really have to clone all the existing social plugins just to replace the GetRecord($RecordType, $ID) call in one of their methods?

Any ideas would be appreciated!



  • Options
    mtschirsmtschirs ✭✭✭

    @Bleistivt Thanks! However, I would like to offer exactly the same functionality, look & feel as the social react buttons beneath discussions. This plugin seems just to inject the standard facebook, twitter & co iframes to the articles (which is a bit critical due to the German data protection laws...). Therefore I would be very happy to reuse the functionality offered by the existing social plugins provided by Vanilla.

  • Options
    hgtonighthgtonight ∞ · New Moderator

    @mtschirs said:

    If I could just extend this function and add support for the "article" RecordType, everything would be fine, the social plugins would work without modification. However, I found out that functions from library/core/functions.general.php cannot be overwritten by plugins.

    While it is technically true that you cannot override functions via the framework, most functions have include guards so you can define the functions before and take precedent.

    Add your function definition to /conf/bootstrap.before.php to change it how you want. E.g.:

    function GetRecord($RecordType, $ID) {
       switch(strtolower($RecordType)) {
          case 'discussion':
             $Model = new DiscussionModel();
             $Row = $Model->GetID($ID);
             $Row->Url = DiscussionUrl($Row);
             $Row->ShareUrl = $Row->Url;
             return (array)$Row;
          case 'comment':
             $Model = new CommentModel();
             $Row = $Model->GetID($ID, DATASET_TYPE_ARRAY);
             $Row['Url'] = Url("/discussion/comment/$ID#Comment_$ID", TRUE);
             $Model = new DiscussionModel();
             $Discussion = $Model->GetID($Row['DiscussionID']);
             $Discussion->Url = DiscussionUrl($Discussion);
             $Row['ShareUrl'] = $Discussion->Url;
             $Row['Name'] = $Discussion->Name;
             $Row['Discussion'] = (array)$Discussion;
             return $Row;
          case 'CustomType':
              echo 'supp';
             throw new Gdn_UserException(sprintf("I don't know what a %s is.", strtolower($RecordType)));

    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
    mtschirsmtschirs ✭✭✭
    edited July 2015

    @hgtonight Thank you! That is what I will do for now. It would be nice to have the option to somehow extend the getRecord functionality in the future. In my opinion all those *Record functions in library/core/functions.general.php that deal with application specific data such as discussions from the Vanilla application do not really belong into the core library anyway...

    Oh, and by the way, I really appreciate the quick and helpful responses I got on all my questions so far from all of you!

  • Options
    BleistivtBleistivt Moderator

    But even without using the bootstrap.before everride, you don't need to clone the existing social plugins. You could make a plugin just for the social react buttons and put the getRecord logic there as you probably need to create a new method on the ArticleController anyway.

  • Options
    mtschirsmtschirs ✭✭✭

    I just uploaded the Articles Vanilla Social Reacions plugin: :hurrah:

    It works by making use of the public interfaces of the Twitter, Facebook and Google+ plugins as well as their configuration.

    @R_J: The shariff project is very interesting, but I was looking for a more unified look & feel to integrate with the rest of vanilla.

  • Options
    ShadowdareShadowdare r_j MVP
    edited July 2015

    With my "Articles - Social Reactions" plugin that currently only adds social sharing buttons for articles, I decided to go with the bigger buttons because articles are more prominent per se than comments. For comments, I plan to make it look like same as how the social sharing icons show up under Vanilla comments. However, I don't want the plugin to be dependent on Vanilla being enabled. The social plugins bring up a dependency on the Vanilla application.

    Your plugin looks awesome. I like how you made it work with the built-in Vanilla social plugins. Welcome to the community and thank you for trying out the Articles app and contributing to it, @mtschirs! :D

    Add Pages to Vanilla with the Basic Pages app

  • Options
    mtschirsmtschirs ✭✭✭

    That is why I called my plugin 'Articles Vanilla Social Reactions' :pleased:

    Actually, I think that the social plugins should / will technically work without Vanilla being installed. At least in the way I use them: as a basic social integration mechanism that can be extended to work with all kinds of content types and applications. It would be nice to strip out the Vanilla specific functionallity of the core and these plugins and put them in their own 'Vanilla' specific plugins.

    Nevertheless, you are right, my intension was to match the 'look & feel' of the Vanilla application or rather the social reaction buttons provided by these social plugins for the Vanilla application. It also reduces the configuration complexity.

    Also, in my current project, I consider articles and discussions equally important. However, it is just a matter of choosing the right CSS styling.

    Anyway, I am very happy you put so much work into the articles application and share it with us. Thank you for your welcome :smile:

Sign In or Register to comment.