Static Pages Plugin - a humble suggestion

Creating and modifying plugins.
Post Reply
kybernator
Regular
Posts: 135
Joined: Sat Sep 22, 2012 10:15 pm

Static Pages Plugin - a humble suggestion

Post by kybernator »

In the static pages plugin, there is no way to set the date, like there is in the article input form.

I like to set some pages, as I do with some articles, to a "symbolic" date, regardless of when I actually created or last modified them, like the "Impressum" (imprint) always showing the day when the website was launched.

This is probably not an important feature, and I was able to fix the date by editing the time stamp in mysql, but if there is an update to the plugin, could you please consider to include a date field like the article has, provided it is not too much work?

BTW, s9y is terrific. I have in the past used it to enable three folks of my acquaintance to establish their own websites (four, actually, but one site went offline again), but only used the standard functions of an out-of-the-box installation. Now, I am setting up a site of my own and get to know the possibilities a little better (with considerable help on this forum) - what a great piece of software! Thanks a lot!

Regards, Bernhard
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Static Pages Plugin - a humble suggestion

Post by garvinhicking »

kybernator wrote:In the static pages plugin, there is no way to set the date, like there is in the article input form.
Good catch. I now added this capability to include the date/timestamp in version 3.94 of the plugin and committed to git. Please check out if this works for you.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
kybernator
Regular
Posts: 135
Joined: Sat Sep 22, 2012 10:15 pm

Re: Static Pages Plugin - a humble suggestion

Post by kybernator »

Extremely cool, thanks.

Could you please give a link, or update method?

Google sends me here https://github.com/ophian/s9y-plugins/t ... staticpage, but that does not seem to be the right place since it has not been updated for a while.

Regards, Bernhard
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Static Pages Plugin - a humble suggestion

Post by garvinhicking »

Hi!

Our full repository including plugins is here:

https://github.com/s9y

From there, go to "additional_plugins" and then "serendipity_event_staticpage".

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
kybernator
Regular
Posts: 135
Joined: Sat Sep 22, 2012 10:15 pm

Re: Static Pages Plugin - a humble suggestion

Post by kybernator »

OK, I installed it in my testblog.

I see the field now, but what I enter there gets happily overwritten with the actual time and date when saving.

Also, for the sake of consistency, may I suggest to use the same date format as in the article form? That one uses ISO

YYYY-MM-DD HH:SS

- the new one here has German

DD.MM.YYYY HH:SS

Cheers, Bernhard
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Static Pages Plugin - a humble suggestion

Post by garvinhicking »

Hi!

That's odd, it worked properly in my installation. Let's see if we can find out why, I suppose because your PHP version is different than mine, and one of the different methods is used for you (on my install, Method 1 was used).

In the serendipity_event_staticpage.php file you should see a function checkPage at around line 1394.

Below you see some code that does the date parsing. Modify that to:

Code: Select all

// Try to auto-detect a timestamp
if (preg_match('@[:\.]@i', $this->staticpage['timestamp'])) {
    echo "Found timestamp, try to convert " . $this->staticpage['timestamp'] . "...<br />\n";
    if (function_exists('date_parse_from_format')) {
        // Need to convert strftime format (with %) to plain date format (without %)
        $d = DATE_FORMAT_SHORT;
        $d = str_replace('%M', 'i', $d); // Minute is %M in one and i in the other format
        $d = str_replace('%', '', $d); // All other modifiers (%d, %m, %Y %H) stay the same

        $t = date_parse_from_format($d, $this->staticpage['timestamp']);
        $this->staticpage['timestamp'] = mktime($t['hour'], $t['minute'], $t['second'], $t['month'], $t['day'], $t['year']);

        echo "Method 1, Parsed: " . $print_r($t, true) . "<br />\n";
    } elseif (function_exists('strptime')) {
        $t = strptime($this->staticpage['timestamp'], DATE_FORMAT_SHORT);
        $this->staticpage['timestamp'] = mktime($t['tm_hour'], $t['tm_min'], $t['tm_sec'], $t['tm_mon'], $t['tm_mday'], $t['tm_year']);

        echo "Method 2, Parsed: " . $print_r($t, true) . "<br />\n";
    } else {   
        $this->staticpage['timestamp'] = strtotime($this->staticpage['timestamp']);

        echo "Method 3, strtotime<br />\n";
    }

    echo "Parsed: " . date('d.m.Y H:i', $this->staticpage['timestamp']) . "(" . $this->staticpage['timestamp'] . ")<br />\n";
}

When you now save the entry, you should get some extra output that I need to see.
Also, for the sake of consistency, may I suggest to use the same date format as in the article form? That one uses ISO
It always bugged me that this language format was not internationalized, which is why I wrote some code for the staticpage plugin to make it better at that place. I would really prefer to make it easier for that date format; but changing it in the main blog entry form is considerably more work, and could not be solved in the plugin. If it properly works in the plugin, we could use similar code for the s9y core in the future, so I'd like to use that as a testbed. :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
kybernator
Regular
Posts: 135
Joined: Sat Sep 22, 2012 10:15 pm

Re: Static Pages Plugin - a humble suggestion

Post by kybernator »

OK. I get:

Code: Select all

Found timestamp, try to convert 03.10.2012 22:20...
Fatal error: Function name must be a string in /myInstallation/serendipity/plugins/serendipity_event_staticpage/serendipity_event_staticpage.php on line 1421
line 1421 says

Code: Select all

 echo "Method 2, Parsed: " . $print_r($t, true) . "<br />\n";
I do hope that I identified the part to overwrite correctly. Does this help?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Static Pages Plugin - a humble suggestion

Post by garvinhicking »

Hi!

Sorry for that, I made a typo there. It needs to read "print_r" and not "$print_r"...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
kybernator
Regular
Posts: 135
Joined: Sat Sep 22, 2012 10:15 pm

Re: Static Pages Plugin - a humble suggestion

Post by kybernator »

OK, this gets me:

Code: Select all

Found timestamp, try to convert 01.10.2012 13:07...
Method 2, Parsed: Array ( [tm_sec] => 0 [tm_min] => 7 [tm_hour] => 13 [tm_mday] => 1 [tm_mon] => 9 [tm_year] => 112 [tm_wday] => 1 [tm_yday] => 274 [unparsed] => ) 
Parsed: 01.01.1970 01:00()
and an unchanged date.

BTW, I will certainly test this with you as long as you are game, but the more I test the staticpage plugin, the less I am prone to keep it myself. Presently, it looks like it does strange things with the formatting (http://board.s9y.org/viewtopic.php?f=10 ... p=10432254, last post) and also the plugin to tarn e-mail adresses does not seem to work for static pages. Maybe I am mistaken, which is not altogether unlikely, but if both are true, I will rather use articles without categories assigned and link to those.

Regards, Bernhard
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Static Pages Plugin - a humble suggestion

Post by garvinhicking »

Hi!

Hhhm. That sucks; seems the PHP strptime() function does not properly work on your machine, and you are running an older PHP that does not have the "date_parse_from_format" function. Creating a custom parsing routine for any date format would really be too much off a hassle.... :-/

About the email thing; actually this should work, if you make sure the option to apply markup plugins is enabled in your staticpage...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
kybernator
Regular
Posts: 135
Joined: Sat Sep 22, 2012 10:15 pm

Re: Static Pages Plugin - a humble suggestion

Post by kybernator »

OK, I worked my way around it, so,as far as I am concerned, please consider this solved. Thanks!
Post Reply