kolber / stacey

Cheap & easy content management
http://staceyapp.com
MIT License
1.04k stars 132 forks source link

Errors using Stacey 2.3 in PHP 7 #163

Closed desbest closed 4 years ago

desbest commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

working nicely :) thanks

ffd8 commented 4 years ago

@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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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!