Kirby Nja - Likes and dislikes - Version 0.7

A bigger version of Kirby Nja is now released:

0.4

  • Added a new field called nja. It contains counters, delete records button and reset counter button.
  • Removed blueprint field definition because of the new field.
  • Removed option plugin.nja.definitions
  • New option plugin.nja.likes.key
  • New option plugin.nja.dislikes.key
  • New option plugin.nja.panel.uri
  • New option plugin.nja.records.page.slug
  • New option plugin.nja.records.page.title
  • Fixed javascript bug with like/dislike a subpage. It requires the script to be updated.
  • Fixes minor issues.
  • Multi language support

Be aware of the removed and new options. It also require a change in the inline javascript for it to work. In short, double check the changes and instructions.

@SandroIeva I found a javascript issue that probably caused the error. It should be solved now. Just make sure to update the javascript. If you don’t want to read the docs, it looks like this now:

<?php echo js('assets/plugins/kirby-nja/js/dist/script.min.js'); ?>
<script>
nja.init({root: '<?php echo u(); ?>'});
</script>
2 Likes

Cool! Seems to work me :slight_smile: Just one question. How can i add this to my own div or button?
I think you asign a class to it, right?

Ok, so found it in the snippet. i try also to dele the dislike button, so is this just this code?


  <div data-nja-item="-1"<?php e($page->disliked(), ' class="nja-active"'); ?>>
  	<div class="nja-icon"></div>
  	<div data-nja-count><?php e($page->dislikes() != '', $page->dislikes(), 0); ?></div>
  </div>

I’m not sure how the javascript will handle it if one element is missing. Try it! If it does not work you can add display: none; in the css of the dislike item as a workaround.

Anyway, I think it’s a good feature, to be able to disable the dislike button. :slight_smile:

@jenstornell:

Thank you very much for this plugin!

Within my tests, I have found that you can change kirby-nja-master\registry\snippet.php to


<div data-nja-group="<?php echo $page->id(); ?>" data-nja-value="<?php echo $page->nja(); ?>">
  <div data-nja-item="1" <?php e($page->liked(), ' class="nja-active"'); ?>>
    <div class="nja-icon"></div>
    <div data-nja-count><?php e($page->likes() != '', $page->likes(), 0); ?></div>
  </div>
  <div data-nja-item="-1" <?php e($page->disliked(), ' class="nja-active"'); ?>>
    <div class="nja-icon"></div>
    <div data-nja-count><?php e($page->dislikes() != '', $page->dislikes(), 0); ?></div>
  </div>
</div>

Hint: add one space two times.:slight_smile:

If you want to add “Multi language support”:
I have translated the file kirby-nja-master\registry\nja\template.php to German:


<?php snippet('nja', ['page' => $page]); ?>
<div class="nja">
  <div class="nja-reset btn btn-rounded btn-negative">
    ZurĂŒcksetzen der ZĂ€hler
  </div>
  <div class="nja-delete btn btn-rounded btn-negative">
    Lösche EintrÀge
  </div>
</div>
<div class="nja-message-reset">
  <div class="nja-question">
    <strong>ZurĂŒcksetzen</strong> der 'like' und 'dislike' ZĂ€hler. Dieses kann nicht rĂŒckgĂ€ngig gemacht werden. Fortsetzen?
  </div>
  <div class="nja-group">
    <a target="_top" href="<?php echo url('nja/reset/' . $page->id()); ?>?redirect=true" class="btn btn-rounded">Ok</a>
    <div class="nja-abort btn btn-rounded">Abbrechen</div>
  </div>
</div>
<div class="nja-message-delete">
  <div class="nja-question">
    <strong>Lösche</strong> die 'like' und 'dislike' Registrierung. Dieses kann nicht rĂŒckgĂ€ngig gemacht werden. Fortsetzen?
  </div>
  <div class="nja-group">
    <a target="_top" href="<?php echo url('nja/delete/' . $page->id()); ?>?redirect=true" class="btn btn-rounded">Ok</a>
    <div class="nja-abort btn btn-rounded">Abbrechen</div>
  </div>
</div>

HeinerEF

What’s the point? (and some more chars)

Thank you very much for this plugin!

Thanks for trying it out. :slight_smile:

Hint: add one space two times

I wonder the same thing. Why is that better? Do you want more space between the buttons? In that case css would probably be better.

I have translated the file kirby-nja-master\registry\nja\template.php to German:

I agree. When I wrote “Multi language support” I meant that it works well even on a multi language site. I should have support for multiple translations as well to make it easier for non english people. Your template.php is probably very helpful with the german translation. Thanks! :slight_smile: Multiple translations · Issue #10 · kirby-deprecated-plugins/kirby-nja · GitHub

Version 0.5 is out

Changelog

0.5

  • Option added plugin.nja.buttons.like
  • Option added plugin.nja.buttons.dislike
  • Method added nja::value($page)
  • Method added nja::isLiked($page)
  • Method added nja::isDisliked($page)
  • Added hook nja.create
  • Added hook nja.delete
  • Added hook nja.reset
  • Added snippet argument likeButton
  • Added snippet argument dislikeButton
  • Changed snippet to reflect the changes.
  • Field accordions now works with toggling.

@SandroIeva There are now more ways to disable a button, for example in the config:

c::set('plugin.nja.buttons.like', true);
c::set('plugin.nja.buttons.dislike', false);
2 Likes

If I include the snippet <?php snippet('nja'); ?> (Version 0.4 - Beta) e.g. in the homepage of a local website and view the rendered source code in Firefox 51.0.1, I see some red lines:

If I add my spaces “in front of sant-1” like in my older post, the error is gone.

Apache/2.4.23 (Win32) PHP/7.0.13 - Win10 - XAMPP - Kirby-Version: 2.4.1

Where does sant-1 come from? It’s not in the snippet.

@anon77445132 I agree with @texnixe that you see a very odd snippet in your Firefox. Make sure you don’t use any bad Firefox extensions that mess with the html. Also you probably should update to Kirby Nja 0.7. It will probably not solve this problem but you get some nice features and even some bug fixes.

Version 0.6 + 0.7 released

In general it includes these new features:

  • Jumpback - If ajax fails, it jumps back to the previous value after a number of seconds.
  • Cleanup - It’s possible to set a data cleanup of ip numbers by interval (days)
  • Uninstall - It’s possible to delete all data (ip numbers) from all pages

For more info read the changelog.

1 Like

With the new version 0.7 the error

has gone.

Thanks.

Added:
With the old version of this plugin, I still get this error. No change.
But now all is ok.

HeinerEF

1 Like

Hi,
I installed the plugin but I have some problems.
In the footer.php file I added:

<?php echo js('assets/js/script.min.js'); ?>
<script>
nja.init({root: '<?php echo u(); ?>'});
</script>

I’ve integrated the .css file into my template css file
in the article.php page I entered:

<?php snippet('nja'); ?>

If I open an article I see the 2 icons, Like and Dislike.
If I click, for example on Like, in Console Chrome I see the following error:

script.min.js:1 
GET https://www.mydomain.com/nja/add/-1/blog/article-test 500 ()
e.ajax @ script.min.js:1
e.action @ script.min.js:1

and the Like icon has the value 0.

If I open the file content/2-blog/article-test/article.txt

at the bottom I see:

----
Likes: 1

----

Dislikes: 0

If I reload the page, the Like icon displays 1, the color of the icon also changes.
What did I do wrong?

Thanks