Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to make a topic invisible until topic_start_time?

  • I want to be able to post date some topics and keep them invisible until the topic_start_time I specify has passed.

    I’ve modified the topic_start_time using phpmyadmin but this doesn’t do the job – it still displays the topic and makes freshness -1 year

    Anyone got an idea on how to hack the script to make it so?

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

  • _ck_
    Participant

    @_ck_

    In theory it should be possible to use the topic_status field to set a future topics flag ie. “4″ and check the database everytime bbpress runs for that flag, then change it to 0 when the time has passed.

    I don’t see this as a big need for forums (wordpress is another matter) but it’s a simple enough plugin so maybe I’ll try later this weekend.

    Thanks _ck_

    After a day of hacking around (my php handicap is 27 afterall), it has been done :o)

    To cut a long story short…

    I added time and date fields to the post form (visible to moderators only)

    Told functions php to carry on as usual unless it sees a year value – otherwise it uses the value it’s given.

    The sql query that spits out the posts now only returns a row if the topic_start_time is lower than the time the request was made.

    I can supply (very fugly) code if anyone wants to do the same thing.

    The reason I wanted this is so I could start a topic or topics – and walk away. As you can with future posts in WP.


    _ck_
    Participant

    @_ck_

    I don’t think your technique will work universally.

    I bet your early posts still show up in search before they are “published”. Maybe even the rss feeds too.

    By tinkering with the topic_status field it will make sure virtually all routines in bbpress will hide the post from visitors until set down to zero.

    You are quite correct – the RSS feed is showing the “hidden” post…

    The handicap stays at 27 lol

    Apart from search and RSS – anywhere else you can think of that it may appear?

    It’s also affecting the Post Count on the front page – ie for that forum the post count is 8 instead of 7.


    _ck_
    Participant

    @_ck_

    See that’s the thing, you won’t be able to pre-guess everywhere it will show up. Any future plugins will not know to obey your time logic.

    However most code should know to check for topic_status==0

    If you set it higher and then set it back when the time is right, then you should be able to get around all functions. Just don’t use 1 or 2 as a marker.

    Then every few minutes do a mysql check for any topics that have that unique number set in topic_status and if their time has past, set topic_status to zero.

    That reminds me, bbpress will need a pseudo-cron that can be hooked with a real cron job if so desired.

    You’re spot on – the flag approach it must be…

    Topic Count (and probably Post Count) is driven by a hard coded sql value that is incremented each time a topic is added a decremented when one is deleted…


    _ck_
    Participant

    @_ck_

    You can hook add_new_topic in such a way that the topic_status is changed and the counters won’t go up.

    Very true – thanks for mentioning the plugin angle – hadn’t thought of it…

    This is beyond my capabilities – should you decide to work on a plugin for this, I will certainly be in your debt.


    _ck_
    Participant

    @_ck_

    Show me the code how you are exposing the time/date fields to the moderators on a new post?

    template/post-form.php gets a section for normal users

    <?php if ( !is_topic() && !bb_current_user_can('moderate') ) { ?>

    and for mods

    <?php } elseif ( !is_topic() && bb_current_user_can('moderate') ) { ?>

    It’s in this section that I’ve added the year, month, day etc form fields

    Sorry for the time it took to get back to you… Only just fired up my RSS reader…

    I’d decided to kill off my main RSS feed (to get around the RSS visibility issue) and not to sweat over the post/topic count being out by one.


    _ck_
    Participant

    @_ck_

    I’d actually make this plugin for you as it doesn’t take much for it to happen – I just wanted to save some time by understanding how you are sending bbpress a predetermined future time and date rather than the current time and date for a new post. I haven’t looked at the core code but I didn’t think it was looking for time/date fields in a new post.

    a quick look shows bb_new_post posting post_time as bb_current_time(‘mysql’) – so it’s not even checking if a different time has been submitted, it’s forcing it to use the time it calculates…

    The names of the inputs on post-form.php are year, month etc

    bb-includes/functions.php

    new_topic becomes

    function bb_new_topic( $title, $forum, $tags = '', $year, $month, $day, $hour, $minute, $second ) {

    and $now

    if ($year == NULL )
    {
    $now = bb_current_time('mysql');
    }
    else
    {
    $now = $year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $minute . ':' . $second;
    }

    bb_new_post becomes the same

    function bb_new_post( $topic_id, $bb_post, $year, $month, $day, $hour, $minute, $second ) {

    and $now is calculated in the same way

    Also in bb-includes/functions.php

    function get_latest_topics – added $now and tweaked $where

    $now = bb_current_time('mysql');
    $where = "WHERE topic_status = 0 AND topic_start_time <= '$now'";


    _ck_
    Participant

    @_ck_

    Oh… you’re hacking the core, that’s easy but not good.

    I am desperately trying not to touch the bbpress core which was a huge mistake I did with wordpress and made it impossible to upgrade even when there were critical security fixes.

    bbpress is in such a state of flux right now it would be crazy to hack the core, updates with major changes can be expected almost every other month.

    I’ll put this on my scary growing list of things to look at. To be honest it’s not a huge priority but you might want to seriously consider my idea of messing with the topic_status flag. You already are halfway there.

    Oh yeah… the core be hacked good LOL

    I agree that it’s not a good idea, but I wouldn’t have a clue even where to start on writing a plugin… and I wouldn’t know a pseudo-cron if I tripped and fell on one ;o)

    I’m in the same boat with WP on another site… stuffed if I know what I’ve touched and what I haven’t…

    When I spotted the plugin on your site to change nofollow etc – I almost died… hacked the core to do that 2 days before I spotted it lol

    Thanks again for all your help

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

You must be logged in to reply to this topic.