1 (edited by guardian34 2006-07-09 16:45)

Topic: Edit Post Date/Time

##
##
##        Mod title:  Edit Post Time
##
##      Mod version:  1.2
##   Works on PunBB:  1.2.* (Only tested on 1.2.12)
##     Release date:  2006-07-09
##           Author:  guardian34 (publicbox@fmguy.com)
##
##      Description:  Provides admins and moderators a way to change the date
##                    and time of their posts. (Only works with silent edits.)
##
##   Affected files:  edit.php
##
##       Affects DB:  no
##
##  Version History:
##              1.2:  Proper timezone support, bugfix
##              1.1:  Tries to account for timezone difference, bugfix
##              1.0:  Initial release
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup your forum database and any and all
##                    applicable files before proceeding.
##
##

Download: http://www.punres.org/files.php?pid=270

Re: Edit Post Date/Time

good mod, but i found a small bug, when a date/time is changed for a post that is the last post someone posted, the time showing for this users last post is not updated. an updated step 6 to fix this minor error is below:

#
#---------[ 6. BEFORE, ADD ]-----------------------------------------------
#

    // mod: edit date/time
    if ($is_admmod && isset($_POST['silent']))
    {
        $new_posted = mktime(
            intval($_POST['req_posted_hour']), 
            intval($_POST['req_posted_minute']),
            intval($_POST['req_posted_second']),
            intval($_POST['req_posted_month']),
            intval($_POST['req_posted_day']),
            intval($_POST['req_posted_year']));

        if ($new_posted == false || $new_posted == -1) // -1 before PHP 5.1
            $errors[] = "Invalid post date/time.";
        else
        {
            $new_posted -= $tz_diff;
        
            // Updated with the rest of the post
            $new_posted_sql = ', posted='.$new_posted;
                        
            // Is this the "topic post"?
            if ($id == $topic_post_id)
                $db->query('UPDATE '.$db->prefix.'topics SET posted = '.$new_posted.' WHERE id = '.$cur_post['tid']) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
                
            // Try to update topic
            $db->query('UPDATE '.$db->prefix.'topics SET last_post = '.$new_posted.' WHERE last_post_id = '.$id) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
            
            update_forum($cur_post['fid']);

            // Fetch the post ID of the last post from the user who posted this post that is being edited
            // and if this post is the last post he/she posted, then change his/her last post time
            $userLastPostIDCheck = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE poster_id = '.$cur_post['poster_id'].' ORDER BY posted DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
            if (!$db->num_rows($userLastPostIDCheck)) {
                message($lang_common['Bad request']);
            }
            $userLastPostID = $db->fetch_assoc($userLastPostIDCheck);
            if ($userLastPostID['id'] == $id) {
                $low_prio = ($db_type == 'mysql') ? 'LOW_PRIORITY ' : '';
                $db->query('UPDATE '.$low_prio.$db->prefix.'users SET last_post='.$new_posted.' WHERE id='.$cur_post['poster_id']) or error('Unable to update user', __FILE__, __LINE__, $db->error());
            }
        }
    }
    else
        $new_posted_sql = '';

3

Re: Edit Post Date/Time

Is there anyway someone could make this into just an administrative plugin?

4 (edited by zetrader 2016-05-18 17:36)

Re: Edit Post Date/Time

I would be interested too as an extension, but looking at edit.php the code has changed a lot in punbb 1.4.4 so i guess it wouldn't work anymore with the latest version of punbb (downgrade to punbb 1.2 would be a problem with php 5.6 i guess, so i want to avoid this).