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

Is there a webservice plugin example?

GaryFunkGaryFunk Senior Application Developer ✭✭

I have looked through many of the plugins hoping to find one that called a webservice that I might use as an example. I'm asking if any of you know of such a plugin that might point me in the right direction.

If the user is logged in, I want to call a webservice, passing the DiscussionID and a cookie. The service in return, will pass back a simple string, which I want to add to the end of the discussion.

I write code in one of those dead languages so I am not a PHP developer but I can read and write the code.

Thank you.

Comments

  • Options
    GaryFunkGaryFunk Senior Application Developer ✭✭

    Maybe I need to start putting bonk inbevery title.

  • Options
    GaryFunkGaryFunk Senior Application Developer ✭✭
    edited January 2013

    Holy Simple, Batman, this is way easy.

    So this ended up being very simple and easy to do. In fact, I did exactly what I wanted and it only took about an hour and 21 lines of blotted code.

    public function DiscussionController_AfterDiscussionBody_Handler($Sender) {
      // Allow disabling of inline tags.
      if (C('Plugins.HaveBadge.DisableInline', FALSE))
        return;
    
      if (!property_exists($Sender->EventArguments['Object'], 'CommentID')) {
        $DiscussionID = property_exists($Sender, 'DiscussionID') ? $Sender->DiscussionID : 0;
    
        if (!$DiscussionID || $DiscussionID > 2000)
          return;
    
        $FS_USERID = GetValue('FS_USERID', $_COOKIE, NULL);
        if (!$FS_USERID)
          return;
    
        $Url = "http://example.com/z/c.cfc?method=badge&discussionID=$DiscussionID&fUserID=$FS_USERID";         
        $Contents = file_get_contents($Url);
    
        echo '<div style="color:#ffff00">'.$Contents.'</div>';
      }
    } 
    
  • Options
    x00x00 MVP
    edited January 2013

    I'd advise against file_get_contents in favour curl. You might put some caching as well, just a suggestion.

    Also if at all possible I'd defer these operations to the client side, such as using jsonp service.

    grep is your friend.

  • Options
    GaryFunkGaryFunk Senior Application Developer ✭✭

    @xoo Thank you for your advice. I know little of file_get_contents vs curl, so I will research and understand what each does.

    I concur about with the use of json and letting the client do the work. I wrote the code last night just before I forced myself to bed.

  • Options
    businessdadbusinessdad Stealth contributor MVP

    @x00 gave great advice. I just would like to point out that it's worth considering that not every client might have JavaScript enabled. In such case, you would have to rely on the backend doing the job, or the files would not be downloaded.

    That might be an acceptable limitation, but it's good too keep it in mind.

  • Options
    GaryFunkGaryFunk Senior Application Developer ✭✭

    @businessdad I am going to push this even more.

    By default It will state:

    If you enable javascript, you will receive additional information.

    If they are not logged in:

    If you login, you will receive additional information.

    And of course:

    This is the additional information.

  • Options
    GaryFunkGaryFunk Senior Application Developer ✭✭
    edited January 2013

    And one question. What event do I want to place the JavaScript in the head? I know I can do this in the body, but I prefer to be as clean as I can.

  • Options

    Just include the script with $Sender->AddJsFile() or $Sender->Head->AddScript() for external usually you will add it late which would be_Render_Before choosing the relevant controller.

    grep is your friend.

  • Options
    GaryFunkGaryFunk Senior Application Developer ✭✭
    edited January 2013

    @x00 Thank You. That is what I need to know to move forward.

Sign In or Register to comment.