lloydsargent / GrabAssets

PHP plugin to the PicoCMS to make an array of all assets (images, documents, etc.)
MIT License
2 stars 1 forks source link

typo in php file #1

Open JnsVttr opened 1 year ago

JnsVttr commented 1 year ago

Thanks for this nice plugin! After installing the plugin in pico's plugins folder the site won't render - there is a typo on line 102 $base_dir .= '/'; should be: $base_dir = '/';

lloydsargent commented 1 year ago

Okay, reedit because I forgot a lot of PHP.

.= is what it’s supposed to be. I’m not sure why it doesn’t render. I just checked my site and it renders just fine.

Huh… this is very odd.

.= is assignment in PHP.

If = works for you, then go for it. I’m a bit perplexed why .= doesn’t.

Please see the following for valid assignment under PHP.

https://www.php.net/manual/en/language.operators.assignment.php

PS Okay, I was using 7.2 and .= works just fine. HOWEVER, 8.2 makes it very, very sad. Thanks! I’ll update the code when I assure that it runs under PHP 8.2.

lloydsargent commented 1 year ago

Okay, I was wrong. I literally have forgotten most (not all) of the PHP I learned after four hours of intense scrutiny.

The “./“ is a concatenation operator and it perfectly legal under 8.2.

The code AS-IS works just fine with PHP 7.2 and the older form of PicoCMS.

With the Alpha-2 of PicoCMS and PHP 8.2, things have changed for it to work (never mind there is a crap-ton of things that need to be fixed in PicoCMS).

Changing these lines:

//----- create our assets directory
$base_dir = $twigVariables['base_dir'];
$base_dir .= '/';
$assets_dir = $base_dir.$twigConfig['assets_dir’];

To the following gets it working correctly.

 //----- create our assets directory
 $base_dir = $twigVariables['base_dir'];
 $base_dir .= '/';

 $assets_dir = $twigVariables['base_dir'];
 $assets_dir .= '/';
 $assets_dir .= $selectedAssetDirectory;

Part of the problem is that things apparently changed in the Twig variables.

This is PROBABLY way more information that you wanted, but if you are using PHP 8.2 and the Alpha version of PicoCMS (which you should for security), then these are the changes you need.

Sorry for being addled about what I did before. Let me know if any of this fixes your issues.

lloydsargent commented 1 year ago

Plese see above comment regarding the changes to get this working under PHP 8.2 and Alpha-2 of PicoCMS.

JnsVttr commented 1 year ago

Hi, sorry for confusing you with the typo - I didn't know the ".=" expression and I am also no php user, it just seemed to be the problem. But thanks for looking into it and I can confirm that it now works. I am on PHP 7.4 with PicoCMS 2.1.4.

lloydsargent commented 1 year ago

Glad it works for you! I have moved to PHP 8.2 and, to be honest, running into a soot-ton of problems (the goal is to avoid dealing with PHP for the next four years — it’s okay, just not my preferred language). Right now I’m puzzled as it runs just fine on my local system and gives me a “Forbidden You don't have permission to access this resource. Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.”

I hate that! :)

P.S. I have updated my code to run on PHP 8.2. There are a TON of security issues with 7.x that have been resolved in 8.2… But in the meantime, a lot changed under the hood which is worrisome.