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.

Zooming on particular discussion from an external application embedding Vanilla

BeyBey
edited December 2011 in Vanilla 2.0 - 2.8

I am a novice Vanilla user, using Vanilla 2.18.1 on Windows, trying to get my feet wet on a locally hosted Vanilla.

What i am looking to do is have the application (within which Vanilla is embedded) issue a URL using a particular syntax that will be intercepted in Vanilla and based on the parameters specified in the incoming URL, redirect to either a new discussion (within a category - implied in the original URL) or join an existing discussion within that category.
I assume categories are implemented and user profile has sufficient access rights.

For obvious reasons, i would like to implement it as a plugin.

I think i understand well enough the structure of the URL i need to construct (in either case).
My attempts to implement this using discussions controller 'before render' failed because Vanilla issues a 404 before it even gets to display the main page's discussions.
I tested by issuing the URL directly on the browser just to get the concept going.

So, my thought was to implement it as a Vanilla search and use the searchcontroller before_render event.
I noticed that the search controller is not within the applications folder hierarchy (does that make a difference for the implementation?)

Is this a valid approach?
Is there a better way to doing that?

Much appreciated.

Bey

Best Answer

  • ToddTodd Vanilla Staff
    edited December 2011 Answer ✓

    I'm not sure what you're asking for exactly, but you should maybe just create a new url to do this. Here is a bit of starter code that you'd put into a discussion.

    public function DiscussionController_Presto_Create($Sender, $New = FALSE, $Slug = '') {
        if ($Slug) {
            // Look up discussion.
            Redirect("/discussion/$DiscussionID/x");
        } elseif ($New) {
            Redirect("/post/discussion");
        } else {
            throw NotFoundException();
        }
    }
    

    The url of this method would then be /discussion/presto?new=1&slug=xxx or /discussion/presto/1/xxx.

Answers

  • Great post , one for @todd and @lincoln me thinks

    There was an error rendering this rich post.

  • ToddTodd Vanilla Staff
    edited December 2011 Answer ✓

    I'm not sure what you're asking for exactly, but you should maybe just create a new url to do this. Here is a bit of starter code that you'd put into a discussion.

    public function DiscussionController_Presto_Create($Sender, $New = FALSE, $Slug = '') {
        if ($Slug) {
            // Look up discussion.
            Redirect("/discussion/$DiscussionID/x");
        } elseif ($New) {
            Redirect("/post/discussion");
        } else {
            throw NotFoundException();
        }
    }
    

    The url of this method would then be /discussion/presto?new=1&slug=xxx or /discussion/presto/1/xxx.

  • Thanks for the quick response.

    Is Presto here connotes a category?
    If so, wouldn't this mean that i would have to hard code a function for each category to benefit from this functionality?
    If so, what would that mean when a new Vanilla upgrade comes along?

    My imaginary approach was to try and avoid affecting the existing code.

    Here's what i was 'hallucinating':

    Suppose the application embedding vanilla and issuing the url 'knows' (because it was set up this way) that there is a category named 'foo' (and also 'baz') with the convention that the 'foo' and 'baz' categories in Vanilla correspond to 'foo' and 'baz' objects (tables / models) in the application.
    Further suppose that on the application's detail page for 'foo' objects there is a link to Vanilla (same for 'baz').
    The purpose of that link is to either join in a foo-based / baz-based discussion for a given instance or start a new discussion if none existed.

    So, on the 'foo' object details page for a foo object with id = 12345, the application will generate a url like (my invention - which needs adjustment, obviously):

    /discussion/foo=12345

    On the 'baz' detail object for baz with id = 23456 the application would issue something like (duh):

    /discussion/baz=23456

    Vanilla will act as indicated above (either join an existing one or display the post page for a new one in the respective category.

    Sorry for being so verbose.

  • ToddTodd Vanilla Staff

    Presto is a random name I made up. I was just trying to show you how method names map to urls. You can do exactly as you want and my sample code is pretty damn close to what you want.

  • BeyBey
    edited December 2011

    I understood the random aspect of Presto and placed the sample code in the DiscussionController (just to get that going).

    What I am not clear about (being new to both, Vanilla and PHP) is the semantics of Presto (is this a category?) and good old $Slug (is this a discussion id?, comment title?).
    Just to emphasize my ignorance, I am also not clear about the statement:

    'Redirect("/discussion/$DiscussionID/x");'

    Is $DiscussionID supposed to be set magically by Vanilla?
    Does the suffix of /x corresponds to the /xxx in the url?

    I did get the NotFound exception but i don't think it is because the method was executed.
    I surmized that by replacing the 'throw NotFoundException()' with '1/0' and still got a NotFoundException.
    Similarly, when i placed 'Die(); before the initial 'if ($Slug)' condition there was no death but a rather lively NotFoundException as in:

    "Not Found

    The requested URL /vanilla/discussion/presto was not found on this server."

    I definitely do not mean to dominate your time with ignoramus trivia and feel embarassed about those simpleton questions.

    Thanks for all the trouble.

  • ToddTodd Vanilla Staff

    You don't put that code in the discussion controller. You shouldn't ever modify the core. You put that code in a plugin.

    Please familiarize yourself with plugins a bit before asking further questions.

  • Thanks.

    I read the plugin documentation back and forth long before posting the first question. That is not to say I am fully conversant in plugins.

    Though i failed to implement what i wanted using your very elegant solution (that piece of code in a plugin never executed - must be my fault), i DID get my plugin approach implemented as a "Search Controller Render Before" to work.

    It is ugly and verbose but working.

    All your help and patience (even the impatience) are appreciated.
    Looking forward to learn more about the elegant magic of Vanilla...

    Bey

Sign In or Register to comment.