Nja plugin for images

I’m using Kirby Nja, and it’s working very well on pages, but I’m trying to make it work for images !

I tried to replace 'page' => $page, by 'page' => $image but the result isn’t saved in history.

<?php foreach($project->images()->sortBy('sort', 'asc') as $image): ?>
            <a data-caption="<?php echo $image->legende()->html() ?>" href="<?php echo $image->url() ?>">
                <img class="b-lazy" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=" data-src="<?php echo $image->resize(500)->url() ?>" width="<?php echo $image->resize(500)->width() ?>" height="<?php echo $image->resize(500)->height() ?>">
            <figcaption class="heart"><?php snippet('nja', array(
    'page' => $image,
    'likeButton' => true,
    'dislikeButton' => false
        <?php endforeach ?>

The plugin seems to create a folder named “nja” for each pages where the snippet is called, what’s why I’m wondering if it could be possible to make it work for images ??

I don’t think it makes sense to use the plugin as is. If you want to store the likes with each image, you have to store them in the image meta data, not in the page? (or does it create a subpage for each page where the data is stored? I’m not familiar with this plugin)

I know it wasn’t done for that goal but I tought it could be easy to settle this. Indeed, the plugin create a subpage for each page for meta data like so : 07.

Maybe I’m asking too much and I have to re-write entirely the plugin…

The least you have to do is somehow store an image name together with a score in that subpage. But in my opinion it would make more sense to store this information in the image metadata. But that might be difficult, because the plugin seems to generate some sort of token file or whatever that is. Then you would need an additional folder for every image. Hm…

I totally like the idea, maybe ask plugin author @jenstornell about this …

I will ! (thx for your support). After some reflexions, I think this plugin is great and simple, but highly restrictive : we can’t set multiple “nja” in one template (one page website with different article for example), but the token system is maybe the strongest. Every cookies system/JS solution are not good enough.

In my case, I would love to let the visitor set a “like” to my images, with a counter.

You can have multiple like counters in your website, guess @jenstornell is using his own plugin here, for example. But these counters are easy enough to manipulate, for example if you change your IP via a VPN service. So you really have to look closely what is happening on your site. I’m wondering if this might actually get dangerous (legally) if counters are manipulated and some companies get bad scores because of it.

As long as you use this on your own portfolio, it doesn’t matter, of course.

I’m a bit late. Hi!

Kirby Nja is built for 1 counter group for each page. As @texnixe said, it’s possible to have multiple counter groups on a page, but to do that it needs to be an “archive” of multiple pages, like https://lånera.se/.

The hash files that are created are hashed IP numbers to prevent multiple votes. Without register accounts for users, the data is never fully protected from spam. You could have captchas, honeypots, cookies etc, but all of them have flaws.

About the images, it’s not supported and probably will not be. If you really want counters for images, you need to create a new page for each image, but I would say that it’s a bad practice and probably not worth it.

Kirby Nja is MIT, so you can take the code and try to make it fit your need but it require some Kirby and JS knowledge.

I regret it couldn’t be done, but I understand. Even a big service like Likebtn doesn’t support this (I tried). Ok so I think I will turn into a JS with cookies solutions. Because in my case, I don’t think that people would cheat about my images. This could be important for a contest or something like that.