• Resolved purbeckpixels

    (@purbeckpixels)


    Hello,

    Firstly, great plugin. Thank you.

    I’ve just built a website for a friend – https://bittybot.co.uk/ – and am having trouble getting the date modified time of the table to be accurate, to show the actual time the data was modified.

    Setup: Every five minutes my friend’s home server uploads a .csv file to my server and TablePress auto imports it (I’ve modified the plugin code from the default 15 minutes). This works well.

    The issue I’m having is that the last modified time of the table is being set to/displayed as the time that wp-cron.php fires and not the actual time the table was modified. At the moment I have wp-cron.php disabled in wp-config.php and am manually calling wp-cron.php via a real cronjob every few minutes but again the last modified time is set to the time of the cronjob and not the time the table was modified (occasionally my friend’s server won’t upload the .csv file and no data will change in the table but the last modified time will still show that it was modified because it’s using the time wp-cron.php is fired). If I enable wp-cron.php in wp-config.php the last modified time is displayed as the time of the page load because page loads fire wp-cron.php.

    Any idea why this is happening? The nature of the data means that an accurate last modified time is important.

    Here’s the shortcode I’m currently using:

    [table-info id=1 field="last_modified" format="human" /]

    Thanks.

    https://www.ads-software.com/plugins/tablepress/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    “Last Modified” in TablePress means when the table was last saved to the database. This happens during every manual edit on the “Edit” screen and during every import (either manually or with the Auto Import Extension).

    If that’s not the date/time that you want to see as “Last Modified”, I suggest a workaround here: You could add a new first row to the table where you (or your friend) manually update the desired “Last Modified” date in a cell.
    Then, after an import of that table, hide that row on the “Edit” screen via the “Selected rows: Hide” button.
    Then, use the TablePress Extension from https://tablepress.org/extensions/table-cell-shortcode/ to have a way to get that content from the table and display it in the desired place on the page.

    Regards,
    Tobias

    Thread Starter purbeckpixels

    (@purbeckpixels)

    Ah. That explains it.

    Thanks for the workaround, it sounds perfect if I can get my friend to include a ‘Last Modified’ row/column in the .csv file his bot/program is generating…

    Thanks for the prompt reply.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? I hope that this won’t be a problem in the generating program.

    Best wishes,
    Tobias

    Thread Starter purbeckpixels

    (@purbeckpixels)

    Hello,

    The workaround you suggested works perfectly. Thank you.

    One issue, though, is that I would like the ‘Last Modified’ timestamp to be relative. I suggested to my friend that we could use the ‘PHP code in table cells’ extension and the following code:

    <?php echo human_time_diff(1392322879, current_time('timestamp')); ?>

    … in the ‘Last Modified’ column cells .csv file that his program generates (which works well). The issue is that the ‘Single Cell Content Shortcode’ extension outputs a string so the PHP code isn’t being executed, nothing is being outputted, there’s just a blank space.

    Is there a workaround for this? Something I can change in the ‘Single Cell Content Shortcode’ plugin code?

    Thanks again.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    good to hear that the workaround helped!

    That PHP problem is tricky, indeed. A quick solution would probably be to just take the relevant code from the “PHP code in tables Extension” and add it to the Single Cell Shortcode Extension. That should not be that much extra work.

    A different approach would be to use a WordPress Page Template, where you put that PHP code, and then just to grab the Unix timestamp via the Single Cell Shortcode and pass it as a parameter to the PHP code.

    Or, which is also not that hard, you could create a custom small Shortcode that executes that PHP code and internally executes the Single Cell Shortcode to get that timestamp.

    Regards,
    Tobias

    Thread Starter purbeckpixels

    (@purbeckpixels)

    Thanks for the prompt reply.

    I got it to work by using the code from the ‘PHP code in table cells’ extension (lines 49-58 of the edited ‘Single Cell Content Shortcode’ extension below):

    if ( isset( $table['data'][ $row ] ) && isset( $table['data'][ $row ][ $column ] ) ) {
    		$cell_content = $table['data'][ $row ][ $column ];
    		// /* original code */ $cell_content = preg_replace( '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/', '&', $cell_content );
                    ob_start();
                    eval( '?>' . $cell_content );
    		$cell_content = do_shortcode( $cell_content );
    		return ob_get_clean();
    	} else {
    		return "[table “{$table_id}” does not have that cell /]<br />\n";
    	}

    Look OK to you?

    Thread Starter purbeckpixels

    (@purbeckpixels)

    Hello again.

    Asked my friend, who wrote the bot/program (he’s by far the better programmer), for his input and he recommended commenting out line 54:

    if ( isset( $table['data'][ $row ] ) && isset( $table['data'][ $row ][ $column ] ) ) {
    		$cell_content = $table['data'][ $row ][ $column ];
    		// /* original code */ $cell_content = preg_replace( '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};)/', '&', $cell_content );
                    ob_start();
                    eval( '?>' . $cell_content );
    		// /* original code */ $cell_content = do_shortcode( $cell_content );
    		return ob_get_clean();
    	} else {
    		return "[table “{$table_id}” does not have that cell /]<br />\n";
    	}

    Thanks again for all your help. Will push my friend to drop you a donation for what is a great plugin.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    yes, that looks great ?? Very nice! That line with do_shortcode() is indeed not necessary in your case, as you are just dealing with text/code.

    And thanks for wanting to donate, I really appreciate it!

    Best wishes,
    Tobias

    Thread Starter purbeckpixels

    (@purbeckpixels)

    In the end we decided to have the bot/program output an integer in the ‘Last Updated’ column and do the PHP processing in the ‘Single Cell Content Shortcode’ extension, thus dropping the need for the ‘PHP code in table cells’ extension. Here’s the code for anyone else looking to achieve something similar:

    if ( isset( $table['data'][ $row ] ) && isset( $table['data'][ $row ][ $column ] ) ) {
    		        $cell_content = $table['data'][ $row ][ $column ];
    	      	        ob_start();
    	      	        echo human_time_diff( (int)$cell_content, current_time('timestamp'));
    	      	        return ob_get_clean();
    		} else {
    			return "[table “{$table_id}” does not have that cell /]<br />\n";
    		}

    Thanks again. (I believe my friend sent you a donation earlier this evening.)

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    that’s even better! Great idea! That way, the table content will be much cleaner. Nice! ??
    And yes, I received a donation from your friend. Thank you very much, I really appreciate it!

    Best wishes,
    Tobias

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Last Modified time inaccurate’ is closed to new replies.