Skip to:
Content
Pages
Categories
Search
Top
Bottom

Which filter/action hook should I use?

  • I’m trying to write a better quote plugin, but I’m still trying to figure out where to hook this in.

    I’m thinking that the quote button will post back the topic page in order to fill in the previous post into the reply box. This is pretty standard for other forums.

    While I might also add an ajax mode, I’d prefer to start off with a post back.

Viewing 13 replies - 1 through 13 (of 13 total)

  • _ck_
    Participant

    @_ck_

    To change text you either have to use “pre_post” which is a permanent change saved back to the database (ie. auto close tags) or “post_text” which only affects the outputted text and leaves the source alone (ie. smilies typically use this cause you don’t want the image tags back into the text upon re-editing).

    IMHO “post_text” is an “expensive” operation in that it has to be generated on the text each and every time it’s displayed but sometimes there is no other choice.

    If you are asking how to automatically insert the button, that’s very tricky because somethings still don’t have hooks in bbpress, ie.

    https://trac.bbpress.org/ticket/720

    (ironically that’s where I’d put a quote button)

    The trick is to start a new post with the old text as a quote. I have no idea how that would be done in bbpress because I don’t think you can have existing text on a new post, old an old one, and you really don’t want to pre-create a post in case the user cancels.

    I’d love to see this plugin happen, I just don’t know enough to help you more – hope someone else can help.

    ps please make it trim the old post for people who like to quote posts, who quote posts, who quote posts and it ends up being 10 pages long, LOL!

    What I think you should do is use a bit of nifty javascript, like so:

    <a href="" onclick="somequote( /* post_id */ ); return false;">Quote</a>

    Then the somequote function finds the li with id post-#, extracts the post text (this depends somewhat on the page HTML but should work) and puts it in the post box at the bottom. The somequote function can also use the DOM probably to take out blockquotes. Quoting people isn’t something that needs bookmarking, at least not for my tastes, and reloading the page is annoying. But then quoting people is usually annoying anyway. You’re on a forum, why do you have to quote someone else’s post if other people can see it just above? Meh, personal preference :P

    There’s another plugin that already does the javascript quote post. The problem with javascript is that you effectively end up doubling the page size by duplicating every post on the page, and there’s not a good reason for that.

    I may end up going with an ajax route, but another problem that you end up with is that you can only reply to posts on the current page.

    I figured the quote post should probably strip out any of the prior quotes.

    I’m sorry if I just copy and paste what I said before but I’m not sure you saw. :/

    Then the somequote function finds the li where id is post-#, extracts the post text (this depends somewhat on the page HTML but should work) and puts it in the post box at the bottom. The somequotefunction can also use the DOM probably to take out blockquotes.

    The key bit is that the function is only passed the post ID. It can get the post HTML perfectly simply itself with the getElementById method. And then remove the <blockquote> elements.

    Ah, sorry, I read that too quickly.

    The only issue with that is that what if there are two pages, and I want to respond to a post on the first page? It would simply be broken… clicking on the reply button there wouldn’t do anything.

    I originally was thinking that an ajax method might work, but I think even so it has to be combined with something on the server side.

    Now I’m just thinking to send the user to a url like:

    /topic/my-cool-topic?replyto=381#reply

    That way I can load up the reply in the box no matter where they click the reply link from.


    _ck_
    Participant

    @_ck_

    1. insert “quote” button on every post like my “report” button

    2. don’t use javascript, use the arg add function and build a simple url for each quote button which references the source post id #

    3. clicking said url button does a get from the server/bbpress

    4. look for and capture the $_GET (ie. &quotepost=1327)

    5. now the hard part, tell bbpress to start a new reply post in the topic and insert the formatted text from the quoted post. I have no clue how to pass bbpress existing text to a new post. Not even sure it has the action/filter to do it. I would bet not :-(


    _ck_
    Participant

    @_ck_

    Look again at this tonight I see all the magic would have to happen in “post-form.php” and unfortunately it would need a simple edit.

    <textarea name="post_content" cols="50" rows="8" id="post_content" tabindex="3"></textarea>

    would have to be edited to something like

    <textarea name="post_content" cols="50" rows="8" id="post_content" tabindex="3"><? quote_post(); ?> </textarea>

    Even though there is do_action( 'post_form_pre_post' ); just above it, there is no way to manipulate the textarea content without javascript. It’s a shame they didn’t think of that.

    So quote_post() could just look for the added arg to the URL and insert the formatted quoted text in the textarea. Then a simple quote button on each post in the topic to trigger the new post.

    ie.

    ?new=1&quote_post=1873

    If you don’t write it, I’ll take a shot at it.

    I am pretty busy at the moment… and you are rather amazing at creating these plugins…

    I was thinking that when generating the quoted text it would show up at the top of the textarea like this:


    |

    Quote:
    so you really like ascii?

    | that’s pretty cool

    |

    | Yeah, I love ascii… I’m a geek, afterall


    When generating that quoted text, it would be necessary to find an existing quote within the post and remove that, so the quote of a post that quotes another post then would only have the actual post. (boy was that confusing) It should be simple enough to remove anything between

    Quote:

    Then on display there should be a hook to find a pair of

    Quote:

    and replace it with a div that we can then style correctly. By only allowing a pair then you would prevent breaking divs. If the post submitter screwed up the

    Quote:
    tags, then their post would just not make sense, but wouldn’t break the design of the page.

    This is similar to the way invision does it, and it seems like a reasonable way to handle it.

    Make sense?


    _ck_
    Participant

    @_ck_

    Oh wait, there’s a plugin that does this already, though it needs to be seriously enhanced:

    https://bbpress.org/plugins/topic/38?replies=17

    And they came to the same conclusions that I did, you have to place the “quote” link and insert the quoted text the exact way I described.


    _ck_
    Participant

    @_ck_

    Well you’d have to use an existing html tag like blockquote and map it to a bbcode tag via another plugin.

    But blockquote can have made-up attributes.

    ie.

    <blockquote post="1824" author="_ck_">blah blah</blockquote>

    But it’s much more simple to start with non-intelligent quoting. You can place the post reference but to look for it and analyse it is much more difficult.

    Stripping nested blockquotes will be very easy.

    Well fairly easy.

    I’d think it would work out much better to use something other than blockquote… that’s the whole idea behind the

    Quote:
    tag… it should be accepted by bbpress perfectly fine, and not used for any other reason.

    There’s no reason to have full bbcode support if you don’t need it, all we need is the

    Quote:
    tag.

    One of the problems with using blockquote is that somebody might already use blockquote in their posts. It would also make any old posts using blockquote completely incompatible with the new plugin.

    Otherwise you could use another tag, but then you have to modify the bbpress allowed tags list.

    And the issue here is that we are trying to indicate to the system that we are quoting something, not just trying to format the display. It’s this that gives us the ability to filter out the first quote in a multiple-quote scenario that probably happens very often.


    _ck_
    Participant

    @_ck_

    Just remember some people use the bbcode plugin so it would have to peacefully get along with that.

    That got me thinking… why reinvent the wheel when I can just use the bbcode plugin.

    What I did was change the current quote plugin to insert the quote with

    Quote:
    instead of the other syntax, as well as strip out any blockquotes from the original post that you are quoting, which eliminates the multiple levels of quoting.

    So here’s my new bb_quote_message() function:

    function bb_quote_message() {
    global $bbdb, $topic;
    $post_id = (int)$_GET['quote'];
    if ($post_id) {
    $row = $bbdb->get_row("SELECT * FROM $bbdb->posts WHERE post_id={$post_id} AND topic_id={$topic->topic_id} AND post_status=0");
    $row->post_text = preg_replace( '(<p>|</p>)', '', $row->post_text );
    $ret = preg_replace("/<blockquote>((.|[nr])*?)</blockquote>/", "",$row->post_text);
    if ($row) echo htmlentities('
    Quote:
    '.$ret.'
    ', ENT_COMPAT, 'UTF-8');
    }
    }

    So far it works great… except it’s annoying that the cursor isn’t positioned at the end of the textbox… I’m gonna look for some javascript to fix that.

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.
Skip to toolbar