pivotx / PivotX

GNU General Public License v2.0
4 stars 5 forks source link

Uncaught TypeError: count() in module_smarty.php:3467 #7

Closed Darkseid1981 closed 1 year ago

Darkseid1981 commented 1 year ago

I don't know if I did something wrong or what but now I'm getting this, and the template are not rendering correctly.

PHP_error_log:

PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /opt/lampp/htdocs/projects/pivotx-3/pivotx/modules/module_smarty.php:3467
Stack trace:
#0 /opt/lampp/htdocs/projects/pivotx-3/pivotx/db/cache/%%D1^D16^D1683F74%%front_2.tpl.php(29): smarty_paging(Array, Object(PivotxSmarty))
#1 /opt/lampp/htdocs/projects/pivotx-3/pivotx/modules/smarty/Smarty.class.php(1275): include('/opt/lampp/htdo...')
#2 /opt/lampp/htdocs/projects/pivotx-3/pivotx/modules/module_smarty.php(241): Smarty->fetch('default/front_2...', '', NULL, false)
#3 /opt/lampp/htdocs/projects/pivotx-3/pivotx/modules/module_parser.php(1357): PivotxSmarty->fetch('default/front_2...', '')
#4 /opt/lampp/htdocs/projects/pivotx-3/pivotx/modules/module_parser.php(365): Parser->parseTemplate('default/front_2...')
#5 /opt/lampp/htdocs/projects/pivotx-3/pivotx/modules/module_parser.php(105): Parser->renderWeblog()
#6 /opt/lampp/htdocs/projects/pivotx-3/pivotx/render.php(268): Parser->render()
#7 /opt/lampp/htdocs/projects/pivotx-3/index.php(23): require_once('/opt/lampp/htdo...')
#8 {main}
  thrown in /opt/lampp/htdocs/projects/pivotx-3/pivotx/modules/module_smarty.php on line 3467

Not sure if I'm barking up the wrong tree, but this happened after I edited the form.php and changes the int + to intval() so I can make new weblogs and change the templates. Am I on to something?

hansfn commented 1 year ago

It's very unlikely that this is related to the change you did :-) I'll check the problem tomorrow. Can you give more details about when it happens.

PS! There are probably many of these bugs, but I don't mind fixing them as we go along. Very few are using PivotX actively on PHP 8.

Darkseid1981 commented 1 year ago

It started yesterday, and all I changed were lines 1616 and 1628 of forms.php and nothing else.

hansfn commented 1 year ago

What you were doing? Editing something or viewing?

hansfn commented 1 year ago

If you modified front_2.tpl, you need to post it so I can reproduce the problem. I can only guess what the fix is:

On line 3467 of pivotx/modules/module_smarty.php replace

if (count($subweblog['categories']) > 0) {

with

if (is_array($subweblog['categories']) && (count($subweblog['categories'])) > 0) {
Darkseid1981 commented 1 year ago

No, I just edited forms.php, otherwise it would give me a blank page when I click on the edit button for the weblog. I downloaded the PivotX master but I would get blank page if I try to edit the weblog. This is an issue we already addressed and should be in the current PivotX master, unless I'm wrong.

hansfn commented 1 year ago

Trying again ...

1) What action on the website did you do before the error appeared? 2) Did you test my suggestion?

Darkseid1981 commented 1 year ago

I was working on my own template, but something seemed off, way off. As in none of the changes I made to my template were taking effect any more. Even after clearing the cache, it still had no effect. So I though, OK, let's see what happens if I switch templates and that's when I saw it. No footer on the two column template. It seem to work on Byethost, sort of, it has the footer but the side bar looks off. But I'm fine with that, it just need to work on xampp. I thought I messed up the DB so I cleared out the workbench folder and copied over fresh files from the PivotX master zip and found out that the forms.php was still unmodified, so I just went to the issue post with the fix and made the changes, and I could now make a new weblog or even edit it. I change the template from skinny to the two column template and it was still the same. I tried it with the RC2 zip, same issue.

I have know idea what I did, or if I did any thing to cause this. Unless it's my template that did this, but that might be unlikely, I think, take a look at it: flat.zip

I'm still figuring things out regarding templates. I can always wait with my template until we have debugged PivotX for PHP 8.

Darkseid1981 commented 1 year ago

The only templates that don't produce any errors is bares_bones, mobile and the skinny templates. I also did a complete reinstall of xampp in the hopes that in might be xampp messing around, but I still have the same issue. The only other thing I can try is running fsck, it could be just a corrupt FS node causing this. Scanning and fixing it, then reinstalling pivotx, might solve the issue.

Darkseid1981 commented 1 year ago

I saw the commit, now I feel like I have to apologize for the massive workload I inadvertently dumped on you. But I do understand that you made a promise to maintain PivotX. I still feel responsible. I guess if it wasn't me someone else would have found these bugs.

hansfn commented 1 year ago

No worries, the clean-up was needed. Anyway, let us get back on topic:

  1. The master.zip file is updated automatically. I just tested now and all the changes I did earlier today is present. Please try again.
  2. I'm not able to reproduce your problem - even tested with the template (flat.zip) that you posted. Did you try my suggestion above?
  3. And again: When do the error appear - while editing your weblog or viewing it? What is the URL?

PS! Upgrading to a new master version is very easy. Basically:

  1. Rename the old PivotX installation from pivotx to pivotx.old.
  2. Unzip the new (master) version (and rename / move so the new pivotx folder is in the same directory as pivotx.old - the same location as before.
  3. Delete the new db and templates folder and move the old db and templates folder to the new PivotX folder:
    rm -rf pivotx/db
    rm -rf pivotx/templates
    mv pivotx.old/db pivotx/
    mv pivotx.old/templates pivotx/
Darkseid1981 commented 1 year ago

OK, I'll test it and let you know what happens. And those errors appeared while I was working on my template, on xampp.

hansfn commented 1 year ago

And those errors appeared while I was working on my template, on xampp.

That still doesn't answer my question: "While editing your weblog or viewing it? What is the URL?" I assume it's while viewing the weblog. (By "Editing" I mean the administrativ / internal pages of PivotX.)

Darkseid1981 commented 1 year ago

I honestly don't get it, it still doesn't render the two column and 3 column templates correctly. And I didn't edit them either. Here is the php_error_log php_error_log.txt

What we can do is use teamviewer or anydesk, so you can see what my xampp and pivotx config look like. I just don't get it, and I have no idea what could have changed to get this issue. It's giving me a migraine.

Darkseid1981 commented 1 year ago

One thing I have to mention is that my template seems to be rendering correctly, for the moment. It's just the two and three column templates that are not rendering correctly. and if they're not rendering correctly then any of the features they use would have the same rendering errors if I were to try them in a template.

On a side note, where are all the other templates from pivotx.net? I'd like to have a look at there tpl files and see how others made their own templates, you know, learn by example.

hansfn commented 1 year ago

I finally was able to reproduce it. My initial suggestion should have worked. Anyway, the fix I applied is found in this commit. I recommend grabbing the master.zip again.

The problem is caused by switching templates for existing weblogs. If the new template has more subweblogs, the new subweblog isn't correctly setup - missing all settings. (You need to add categories and then number of entries.)

I have saved all the themes for themes.pivotx.net (from archive.org actually) and will add them to GitHub later this week.

hansfn commented 1 year ago

I closed the issue with a fix. Please don't waste my time answering prior questions now.

If the fix didn't work, reopen the issue with a new error report.