Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors using Stacey 2.3 in PHP 7 #163

Closed
desbest opened this issue Jan 29, 2020 · 7 comments
Closed

Errors using Stacey 2.3 in PHP 7 #163

desbest opened this issue Jan 29, 2020 · 7 comments

Comments

@desbest
Copy link

desbest commented Jan 29, 2020

Hello I'm having problems using Stacey 2.3 in php7. I don't have the time to upgrade to Stacey 3.
When I download the demo site off staceyapp.com and run it in php7, I get these errors.

Notice: Array to string conversion in C:\Users\desbest\Documents\UniServerZ\www\staceyv2.3\app\page-data.inc.php on line 231
Notice: Array to string conversion in C:\Users\desbest\Documents\UniServerZ\www\staceyv2.3\app\page-data.inc.php on line 233
Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead in C:\Users\desbest\Documents\UniServerZ\www\staceyv2.3\app\page-data.inc.php on line 113

Also the variables on the page such as @name and @title are not printed on the screen.
Can anyone help?

@desbest
Copy link
Author

desbest commented Jan 29, 2020

I've fixed the issue. In the page-data.inc.php file there is a create_textfile_vars function.

Replace this

# set a variable with a name of 'key' on the page with a value of 'value'
# if the template type is xml or html & the 'value' contains a newline character, parse it as markdown
if(strpos($colon_split[1], "\n") !== false && preg_match('/xml|htm|html|rss|rdf|atom/', $split_path[1])) {
        $page->$colon_split[0] = Markdown(trim($colon_split[1]));
} else {
        $page->$colon_split[0] = trim($colon_split[1]);
}

With this

# set a variable with a name of 'key' on the page with a value of 'value'
# if the template type is xml or html & the 'value' contains a newline character, parse it as markdown
if(strpos($colon_split[1], "\n") !== false && preg_match('/xml|htm|html|rss|rdf|atom/', $split_path[1])) {
        $dakey = $colon_split[0];
        $page->$dakey = Markdown(trim($colon_split[1]));
} else {
        $dakey = $colon_split[0];
        $page->$dakey = trim($colon_split[1]);
}

And replace this in around Line 103

$page->page_name = ucfirst(preg_replace('/[-_](.)/e', "' '.strtoupper('\\1')", $page->data['@slug']));

with this

$page->page_name = ucfirst(preg_replace_callback('/[-_](.)/', function ($matches) { return "''.strtoupper('\\1')"; }, $page->data['@slug']));

I can't make a pull request because I was editing tag 2.3.0 and I'm not on a branch.

@frontism
Copy link

frontism commented Mar 2, 2020

working nicely :) thanks

@ffd8
Copy link

ffd8 commented Mar 10, 2020

@desbest you rock! This definitely needs to be a branch/release as 2.3.1. Had a few friends with websites still based on 2.3.0 (as more hosts shut down old PHP versions) and this is a huge help. Thanks for investigating!

While easy enough for one to implement, here's the patched file from a fresh 2.3.0 release:
page-data.inc.php.zip

@kolber – would you mind releasing the above patch as a 2.3.1 release?

@ludzeller
Copy link

hey, just wanted to add that in my case with migrating staceycms-2.3 from a php5 to a php7 environment I also had to patch the following lines in page-data.inc.php:

foreach($assets as $asset_type => $asset_files) eval('$page->'.$asset_type.'=$asset_files;');

to

`foreach($assets as $asset_type => $asset_files) $page->$asset_type = $asset_files;

and

foreach($asset_collections as $collection_name => $collection_files) eval('$page->'.$collection_name.'=$collection_files;');

to

foreach($asset_collections as $collection_name => $collection_files) $page->$collection_name = $collection_files;

Otherwise I would get parse errors with eval().

@lleigha
Copy link

lleigha commented Jan 20, 2021

These fixes don't seem to work for me. I'm not seeing any error messages, but the content in .txt files doesn't seem to be replacing the variables. Any thoughts? I'm totally lost..

UPDATE: This fixed the issue on some pages, but not all pages...

@desbest
Copy link
Author

desbest commented Jan 20, 2021

You're not seeing any php errors because your php settings is hiding the errors from being displayed in the web browser.
Edit php.ini and change display_errors to be On instead of Off

@lleigha
Copy link

lleigha commented Jan 20, 2021

Ah, OK. It turns out the reason was that a few of my template files and txt files had the word "page" in them. When I change the file name all seems well. Such a relief to find this thread. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants