picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

Pico 2.1.4 problem with Pico.php / strftime #646

Closed maximalista closed 1 year ago

maximalista commented 1 year ago

Hello!!

Sorry for bothering, I wouldn't if I could find a solution by my own.

I am trying to install the new Pico 2.1.4 on Apache2 in Ubuntu 20.04. Everything is ok until I upload the index.md file. Then I get a white screen.

The Apache error logs points to Pico.php

[Mon Sep 05 22:00:52.876940 2022] [php:error] [pid 79888] [client XXXX.XXXX.XXXX.XXXX:XXXXX] 
PHP Fatal error:  Uncaught TypeError: strftime(): 
Argument #2 ($timestamp) must be of type ?int, string given in /..../pico/vendor/picocms/pico/lib/Pico.php:1527\n
Stack trace:\n
#0 /.../pico/vendor/picocms/pico/lib/Pico.php(1527): strftime()\n
#1 /.../pico/vendor/picocms/pico/lib/Pico.php(1760): Pico->parseFileMeta()\n
#2 /..../pico/vendor/picocms/pico/lib/Pico.php(493): Pico->readPages()\n
#3 /..../pico/index.php(33): Pico->run()\n#4 {main}\n  
thrown in /.../pico/vendor/picocms/pico/lib/Pico.php on line 1527

The date format I am using is the most common in Spain and Latin America date_format: '%d/%m/%Y'. I had some problems before with Pico page ordering, but I could solve them hacking a little bit the Pagination plugin to accept the data format. But this time it is not solvable with a touch in a plugin, it is a core issue...

Could you help me, please? Thanks a lot in advance!!

PS. If you are asking yourself about how I changed the Pagination plugin (which is independent of the problem now becasue I have not uploaded the pagination plugin and I am using the default theme) it was just a little change:

....
    // if filter_date is true, it filters so only dated items are returned.

        if ($this->config['filter_date']) {
            $show_pages = array();
            foreach($pages as $key=>$page) {

                if ($page['date']) {

                    $page['nuevafecha'] = str_replace("/", ".", $page[date]);
                    $page['nuevafecha'] = strtotime($page['nuevafecha']);
                    $page['nuevafecha'] = date("Y-m-d", $page['nuevafecha']);

                    $show_pages[$key] = $page; 
                }
            }
        } else {
            $show_pages = $pages;
        }
        // get total pages before show_pages is sliced
....
maximalista commented 1 year ago

I tried to solve it changing my date format to the default in Pico's config file... nothing happened

Then I tried changing the encoding detection order in php.ini (mbstring.detect_order = UTF-8,ASCII,JIS,SJIS,EUC-JP) in order to avoid the problematic condition in the «if» of Pico.php

Then, as the problem seems to be a time stamp, I tried to change it to en_US.UTF8 both in PHP (prepending a file in every .php file with <?php setlocale(LC_TIME, "en_US.UTF-8");?> and adding SetEnv LC_ALL en_US.UTF-8 in .htaccess...

...and syncronizing fpm with php changing its configuration ( clear_env = no)

but it did not worked neither... and of course I tried all together... but no.. it did not work.

Any way, it would be great to find a solution what does not imply to change the language (es_ES) or the date format (d/m/Y)

PhrozenByte commented 1 year ago

Somehow the time meta value receives a non-empty string as input. Did you add

---
time: some_string
---

to any of your pages? You're likely rather looking for

---
date: some_string
---

instead. The time meta value accepts a timestamp integer only, no date time string.

maximalista commented 1 year ago

Thanks a lot!!!

and then...

PHP Fatal error:  Unparenthesized `a ? b : c ? d : e` is not supported.
Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in 
/..../pico/vendor/twig/twig/lib/Twig/Node.php on line 42
maximalista commented 1 year ago

Following

https://github.com/twigphp/Twig/issues/3003

I changed lines 42 and 198. The default template index seems to work, but singles pages produce white page results

The error:

Fatal error:  Uncaught Twig_Error_Loader: Unable to find template "single.twig" 
(looked into: /.../pico/themes/default). in /.../pico/vendor/twig/twig/lib/Twig/Loader/Filesystem.php:195\n
Stack trace:\n
#0 /.../pico/vendor/twig/twig/lib/Twig/Loader/Filesystem.php(150): Twig_Loader_Filesystem->findTemplate()\n
#1 /.../pico/vendor/twig/twig/lib/Twig/Environment.php(330): Twig_Loader_Filesystem->getCacheKey()\n
#2 /.../pico/vendor/twig/twig/lib/Twig/Environment.php(424): Twig_Environment->getTemplateClass()\n
#3 /.../pico/vendor/twig/twig/lib/Twig/Environment.php(363): Twig_Environment->loadTemplate()\n
#4 /.../pico/vendor/picocms/pico/lib/Pico.php(514): Twig_Environment->render()\n
#5 /.../pico/index.php(39): Pico->run()\n
#6 {main}\n  thrown in /.../pico/vendor/twig/twig/lib/Twig/Loader/Filesystem.php on line 195

Maybe the twig version used by pico is not compatible with php 7.4?

PhrozenByte commented 1 year ago

Modifying the PHP sources can be tricky, I'd not recommend doing this. Try upgrading to v3.0.0-alpha.2. Don't worry the "alpha", it's stable, you just have to take some precautions (namely the same as when upgrading from v2.1) when the final v3.0.0 is released. This should solve the Unparenthesized a ? b : c ? d : e error. The later Unable to find template "single.twig" error is about Twig being unable to find the template simple.twig. Make sure that there actually is a simple.twig in your theme and that PHP can read that file (i.e. check file permissions).

maximalista commented 1 year ago

It works!!! Thanks a lot!!! Really!! Is there any area where an amateur not very good at system administration or coding (as you see) could contribute to Pico needs? I love Pico and I would love to contribute. Translations to Spanish or Esperanto? Testing? Template adaptation? Organization of crowdfunding campaigns and/or camps?

PhrozenByte commented 1 year ago

Glad to hear that @maximalista :smiley:

Another helping hand is very welcome! :+1: If you're not really confident in programming, you might want to help improving our docs.

Our docs aren't the best, because they were mostly written by programmers. Programmers like myself aren't the best people for writing docs for non-developers I'm afraid. :see_no_evil: @mayamcdougall started rewriting most of the docs from scratch, but her time is very limited too. I'm sure she's very glad about any help. Most of her work can be found in her rewrite branch. Maybe Maya can give some hints where you could help?

I'm sure that a rewrite from scratch can look a bit overwhelming. If you don't want to take such a deep dive into the docs, you could skim through the existing docs to see where stuff can be improved more gradually. It's quite simple: If you don't understand it at first glance, then it isn't written well and needs improvement. Same is true for stuff you didn't find easily when you started experimenting with Pico. Improving the docs gradually is very welcome, too! :+1:

Besides, adapting new themes is always welcome, too. The more templates, the more attractive Pico gets. :+1: This can even be combined with improving the docs: We don't really have any developers docs right now. So, if you want to, you might wanna start with writing some (theme) developers docs? There's no need to even mention plugins, you can focus entirely on themes if you want to. This doesn't have to be "the definitive guide" either, just explaining the basics would be a huge improvement.

maximalista commented 1 year ago

Everything sounds great!!

I have a great experience doing things wrongly, so I guess I can contribute with some improvements «for dummies» :-) And I love to adapt new themes, too.

@mayamcdougall: I am at your service!! Please tell me what could be more useful in your work planning.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1:

PhrozenByte commented 1 year ago

Looks like Maya's time is very limited and she has no free capacities to coordinate things right now. So, if you still want to help @maximalista, you might wanna start with the existing docs, or with porting new themes? :heart: You find our online docs here, and in Pico's content-sample dir. Neither the existing docs, nor theme development require much coordination with @mayamcdougall for now :+1:

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1:

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1:

mayamcdougall commented 1 year ago

Hey @maximalista, sorry for the delay on this. 👋🏻

I've just been kind of behind on everything lately.

My current Work-In-Progress effort is trying to rewrite the docs using more natural sounding, less technical language. Learning to use Pico should be as simple as it is. 😉

I've broken this rewrite up into more manageable sections, where a user can go to learn a single topic. I feel like this would help a user work through the current mammoth of a single-page doc without getting intimidated by it. (Though, having an optional, single-page view where all these sections are combined would probably also be good for finding things quickly with CTRL+F.)

I'll probably also provide a minimalist "Quick Start" guide, for those allergic to reading (😂).

The repo for that is here, however it's not really meant for collaboration. All the work so far has just been squashed into a single "TEMP COMMIT" for posting to GitHub Pages.

I only ever work on the rewrite sporadically, and as a project it's changed shape a couple times, so I never really had good source control over it. Most of the content has lived as individual files that weren't suitable for directly merging with the existing docs.

Anyway. Most of what's there is content-complete if you wanted to give it a read. See how it compares to the current Documentation.

If you want, you can let me know if you have any feedback, positive or negative. Or, you can just look it over for personal-use and see if it clarifies anything you found confusing in the current docs. I've been linking it out for a while as an "Optional" resource for new users. 😉

No pressure. It's taken me a month to reply here, so maybe you've moved on to other things by now. No worries, I just wanted to finally address this before it got closed by the GitHub Bot. 😅


@PhrozenByte, I don't know how in-depth you've been able to look at the rewrite, but it has come along quite a bit since it's early days (eg, since I revived it). Not promising it would free my schedule to work on it right away, but, it would be nice to know if you thought it was roughly heading in the right direction. 👀

I was going to brag about how I wrote most of the plugins page (all of? I can't remember, but I don't think it was entirely done)...

But then I saw that it says the name of your file, folder, and main class "much all match!" and now I think it needs some proofreading first. 🙈 🫣 😂

PhrozenByte commented 1 year ago

@PhrozenByte, I don't know how in-depth you've been able to look at the rewrite, but it has come along quite a bit since it's early days (eg, since I revived it). Not promising it would free my schedule to work on it right away, but, it would be nice to know if you thought it was roughly heading in the right direction. :eyes:

Basically anything is better than the current docs, so, yeah, this is an easy answer: Yes :laughing:

Jokes aside, the idea of splitting things up into more natural "topics" is a good one for sure. The topics should be self-containing and thus rather small. Apart from that I'd rather not get involved too deeply here, simply because I believe that my deeper involvement is one of the major reasons why the current docs aren't suitable for non-developers. So, I'd like to suggest that non-developers (like you folks :+1:) overhaul the docs and I rather just check for misunderstandings in the end. Surely I can - only if desired! - add a few notes about possible additions in the end, but I'd still like to leave things up to you whether these should be included or not, and if yes, where.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1: