Kirby Ratings - Vote for a page with a 5 star scale

Because information changes, I’ll just give a teaser here and you will need to read more on Github.

Frontend

Click a trigger div to vote on a page, the current page or some other page.

Snippets

There are snippets to show the stars in your templates/snippets:

Page methods

There are some page methods as well:

<?php echo $page->ratingAverage(); ?>
<?php echo $page->ratingCount(); ?>

Panel

You probably want to see the ratings in the panel. A good use for the page methods.

Antispam

I started a discussion on Github about possible spam from not logged in users:

The result of that question was kind of that IP together together with time is the only protection and that there are no real good solutions (except for captchas that people hates).

But if you have alternative solutions I’m open to suggestions…

3 Likes

Very nice !! Thanks for sharing, I’m going to test it tonight :wink:

1 Like

:slight_smile:

Oh, I forgot to write. It does not yet work on multi language sites. I plan to make that work as well, but right now I just wanted it to be released.

This plugin was delayed by the fact that I did not want to use reCaptcha anymore. I have no idea who to blame for that awesome decision. :wink: It made me rewrite the plugin from scratch.

Anyway, I’ve tested it on a blank Kirby site with the instructions from my repo and it should work. Good habit: Even if it works on the development site, try it with a fresh install before release. :slight_smile:

1 Like

I think you made the right decision to avoid recaptcha although some awesome developer had made it easy by providing a plugin for it :wink:

I’m going to be active on this plugin repo. I hope to start today :slight_smile:

1 Like

Some updates has been done:

Changelog

0.5

  • Fixed bug with create blacklist.
  • Removed the go feature again. It was the wrong approach.

0.4

  • Fixed bug in js. Not multiple triggers can be added on a single page.
  • Font added to success message.
  • Box sizing added to submit button.
  • Updated docs with minor things.
  • Added the optional go argument to the modal.

0.3

  • Cleaned up some unused functions.
  • If rating is not set no stars are displayed.
  • If rating is not set the average is ? instead of 3.
  • Hidden in blueprint is now hidden in the panel. Bug fixed.

0.2

  • Config to manually block IP numbers in an array.
  • Added frensh translation. Thanks to Mathieu Etienne for that.
  • Added forgotten translation keys to the en and sv translations.
  • Added support for multi language setup.
  • Added global blueprint field definitions to make the blueprint shorter.
  • Minified frontend js and included the gulpfile.js.
  • Separated stars snippets into a panel snippet and a frontend snippet.

@jenstornell:

I have downloaded and installed version 0.5 at a local, new installed Kirby 2.3.2 on XAMPP/Windows (Apache/2.4.9 (Win32) PHP/5.4.27):

If I go to the homepage or to the panel, I now get an error message:

Fatal error: Can’t use function return value in write context in H:\xampp\htdocs\kirby-2.3.2\site\plugins\kirby-ratings\extensions\page-methods.php on line 21

[Added:]
I have no votes or ratings until now. I think but don’t know, whether this is important.

Crap! It works on my live + test sites. Will look into it tomorrow morning.

1 Like

I think I found the problem:

http://stackoverflow.com/questions/34433714/function-not-working-on-server-cant-use-function-return-value-in-write-context

Prior to PHP 5.5, empty() only supports variables;

It seems like it does not work with older PHP versions at the moment. I use 5.5.12. I have two choices:

  • Try to fix it without be able to test it. (I don’t want to downgrade my environment) Even if I do fix it, maybe there are more cases like it in the code.
  • Add PHP 5.5 as a requirement.
1 Like

I recorded a video of this plugin. It uses a swedish translation but I think you can still understand how it works. Works with PHP 5.5+.

1 Like

Even PHP 5.5 is end of life, so I think requiring that as a minimum is perfectly ok.

2 Likes

Yes that will be ok, I have not tested this yet. I am planing to do this next weekend…

While Kirby ships with

I try this PHP version, if the plugin has no own (higher) requirement.

PHP 5.4 is only a minimum requirement. We would recommend to always use the latest stable version available to you, Since 5.5 went out of life, that would be 5.6, or ideally PHP 7.

I agree, but many cheap webservers don’t show this new versions.

So I have to try the version of the oldest live PHP version of my clients.

It would be easy to find cheap hosting providers who offer up to date PHP versions. Of course, it’s up to your clients, but security should be first.

Edit:

I’d recommend to always test with the version on the live server, i.e. use a different test environment for each client with a different setup.

@jenstornell

This plugin looks great and I really would like to use it, but I can’t get it to work neither with my current setup nor with a fresh starterkit! :frowning: In both cases the trigger initially looks like in your video but does not trigger anything and the “modal” gets rendered at the bottom inside the page.

I placed the kirby-ratings-folder in site/plugins/ and followed all your steps (adding css to header, script to footer, fields to blueprint and using the original trigger).

When I looked into the plugin I thought some parts need to be not in the plugin-folder but the coresponding site-folders itself - this is not working either (and of course would confuse plugin parts with everything else).

Then I noticed that the plugin-urls in <?php echo css('assets/plugins/kirby-ratings/css/style.css'); ?> and <?php echo js('assets/plugins/kirby-ratings/js/script.min.js'); ?> seem not right:

Instead of assets/plugins/kirby-ratings/.. a path like plugins/kirby-ratings/assets/.. to point to the plugin assets (and not a plugins/kirby-ratings folder in my assets-folder) would make more sense, but it does not work either.

I’m using PHP 7 which should work, right?
Please help me understand and get this correct, am I missing anything?

Best regards

I’ve had a few issues reported to me lately that has to do with paths/urls with Kirby 2.4. Can you test it in Kirby 2.3?

The assets url feature with plugins is working in a special way, that might not seem correct at first, but if you read this you can see that it should be correct:

https://getkirby.com/docs/developer-guide/plugins/assets

What are your domain url? Is it like http://localhost:8080? On localhost and some port number? That’s what I’ve got reports about before.

If you press F12 (Developer Tools) in Google Chrome and then go to console, is there an error message (it should be)? What does it say?

Thanks for your reply @jenstornell!

Actually, my current setup uses still Kirby 2.3.2 and only the clean starterkit was 2.4.
And after reading about the plugin-assets structure, that makes sense :wink:

Yes I’m working on localhost in Linux (http://localhost:8000/local-test-site-name) but I also copied the 2.4 starterkit with the rating plugin to a live server with the same results where it is working!

In the console I get the following errors:

ERROR: GET http://localhost:8000/kirby-ratings-test/assets/plugins/kirby-ratings/css/style.css   @ kirby-ratings-test:12
ERROR: GET http://localhost:8000/kirby-ratings-test/assets/plugins/kirby-ratings/js/script.min.js   @ kirby-ratings-test:154
ERROR: GET http://localhost:8000/kirby-ratings-test/assets/plugins/kirby-ratings/js/script.min.js   @ kirby-ratings-test:154
ERROR: Uncaught ReferenceError: kirbyRatings is not defined
       (anonymous function)   @ kirby-ratings-test:155

Because of the first three lines I thought the url to the assets might be wrong.
And the last error (line 155) is the init-function-call in the footer:

<script>
    kirbyRatings.init('<?php echo u(); ?>');
</script>

which resolves to this, when clicked on the error in the console:

kirbyRatings.init('http://localhost:8000/kirby-ratings-test');

kirbyRatings.init(’<?php echo u(); ?>’);

This line of code call the plugin and send the domain url to the javascript.

Does this url work when you copy/paste it directly into the browser?

http://localhost:8000/kirby-ratings-test/assets/plugins/kirby-ratings/css/style.css

It’s hard for me to debug the code like this. Maybe you could send the installation (without a user account) as ZIP and I can look into it?

I’ve sent a PM.

But since the assets cannot be found/accessed this is not working, right?! :wink:

The requested resource /kirby-ratings-test/assets/plugins/kirby-ratings/css/style.css was not found on this server.
when following the url directly…

I’m curious, does it work for you with a clean 2.4 starterkit?

Okay, thanks to @jenstornell’s help/testing we confirmed that it is working as it should - also with my setup.

The problem has something to do with the localhost+ports-setup and it IS working on my server!

1 Like