aerni / statamic-advanced-seo

Comprehensive SEO addon for Statamic with flexibility in mind
https://statamic.com/addons/aerni/advanced-seo
11 stars 6 forks source link

Error on sitemap syntax error, unexpected identifier "version" #81

Closed JoeriE closed 1 year ago

JoeriE commented 1 year ago

Hi,

I get this error on a few sites of mine: syntax error, unexpected identifier "version". Both in the last Statamic 3 version as in the latest version (Statamic 4).

image

It's strange because on other sites the sitemap is working.

Thanks!

aerni commented 1 year ago

I'm going to need some more information. Please run php please support:details and post it here. Also, please provide detailed explanation of how to reproduce this issue. Best would be a repo to a test site. And what is in your laravel.log?

aerni commented 1 year ago

I'm closing this issue as I haven't heard back from you. Feel free to comment on it and I'll open the issue again.

St3Ko commented 1 year ago

I have the same problem on a clean statamic install. When i try to to get /sitemap.xml i get the same error as above mentioned.

statamic new composer require aerni/advanced-seo

php please support:details output:

Environment
Application Name: Statamic
Laravel Version: 10.18.0
PHP Version: 8.1.22
Composer Version: 2.5.5
Environment: local
Debug Mode: ENABLED
URL: seo-addon.test
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 1
Antlers: runtime
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.17.0 Solo

Statamic Addons
aerni/advanced-seo: 2.1.3

if you need more information please let me know

aerni commented 1 year ago

I just created a new Statamic installation, installed the addon, and visited /sitemap.xml. No issues here. Anything in your logs?

St3Ko commented 1 year ago

Ok so i did some digging and it turns out that this error only occurs when you have short_open_tag = on in your php.ini.

I use Laravel Herd for my dev env. When i use php --ini i get this output:

Configuration File (php.ini) Path: /lib
Loaded Configuration File:         (none)
Scan for additional .ini files in: /Users/----/Library/Application Support/Herd/config/php/81/
Additional .ini files parsed:      /Users/----/Library/Application Support/Herd/config/php/81/php.ini

It states that the Loaded Configuration File is none which i think means that it loads the default where short_open_tag is on. So the parsing of <?xml version="1.0" encoding="utf-8"?> (in resources/views/sitemaps/index.blade.php and resources/views/sitemaps/show.blade.php) fails with the error above.

A fix is to set short_open_tag = off in your php.ini.

Another way, which i think would be better because it works with short_open_tag on and off, is stated here. Use raw php in you blade template and output the xml header like this:

@php
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<?xml-stylesheet type="text/xsl" href="/sitemap.xsl"?>';
@endphp

This approach will also work with short_open_tag = on.

aerni commented 1 year ago

Thanks a lot for digging deeper. I can confirm the fix and will release an update shortly.