Compare commits

...

10 Commits

Author SHA1 Message Date
Carly Ho d0ceae1e3a add config setting for image bg 2023-06-29 20:04:33 -05:00
Carly Ho 60cf2fe1c0 fix table name 2023-06-29 20:02:36 -05:00
Carly Ho d3b5107e62 set background image color to white 2023-06-29 20:01:37 -05:00
Carly Ho 18ab068947 fix column name 2023-06-29 20:00:27 -05:00
Carly Ho 8d11a9b3b3 fix existence checker 2023-06-29 19:10:40 -05:00
Carly Ho 64d1c721a1 more updates to the readme 2023-06-29 19:09:25 -05:00
Carly Ho 5fd814c215
Additional information for installation 2023-06-29 19:04:30 -05:00
Carly Ho 8ffa06dbcc
Add instructions for SQLite3 extension 2023-06-29 18:56:26 -05:00
Carly Ho f10960fc61 remove print_r 2023-06-29 18:54:13 -05:00
Carly Ho 4baf374f24 Add else case for giving kudos 2023-06-29 18:52:29 -05:00
3 changed files with 38 additions and 6 deletions

View File

@ -1,6 +1,12 @@
# How To
# Kudos
Basically, you can drop this onto a php-enabled webserver and have it Just Work, with **one caveat**. You have to have ImageMagick installed along with the php Imagick extension.
This is a small script that allows you to create arbitrary works that people can leave kudos on by clicking a link. Each work allows one kudos per IP address. You also get a url for each work to display the number of kudos that have been left as an image, which is easily include-able most places. You can use it on your writing! You can use it for scripts like this! You can do WHATEVER YOU WANT ✨
## How To
Basically, you can drop this onto a php-enabled webserver and have it Just Work, with **one caveat**. You have to have ImageMagick installed along with the php Imagick extension, and also make sure you have the Sqlite3 extension installed. This means you'll need a web host where you have admin access, or where you can get someone who has that access to install packages for you. [DigitalOcean](https://digitalocean.com/) will get you that hosting for $4 a month if you so choose—it'll run on the smallest specs they have.
(It's totally reasonable to also share one of these instances with a group of friends.)
Assuming you're on an Ubuntu box, this should do it:
@ -8,6 +14,25 @@ Assuming you're on an Ubuntu box, this should do it:
sudo apt-get install -y libmagickwand-dev
sudo apt-get install -y imagemagick
pecl install imagick
sudo apt-get install -y libsqlite3-0 libsqlite3-dev php-sqlite3
```
If it says to enable any modules for your web server, use the provided commands. Then, reload your web server to load all the new extensions.
## Using This Thing
The first thing you'll want to do is go to `[web root]/kudos.php?addwork` and, well, add some work IDs. These are arbitrary strings, so you can do numbers, or abbreviations, or whole-ass sentences, though they will get sanitized to prevent someone messing with your database. Once you submit the form, it'll give you a pair of links: one for people to visit to give kudos, and the other to an image that displays the number of kudos.
When you're linking to the `/kudos?give=[id]` link, you may want to add the `target="_blank"` attribute to the link so it opens in a new window and doesn't navigate people away from the page!
## Customizing
There are some customizable settings in config.php! You don't need to edit them to have it work, but you might want to. You can change the font by dropping additional font files into your install and changing the file in the text settings.
If you like, you can also change the look and feel of the interface by editing the html in `template.php` and the css in `style.css`. Just don't touch the line that says `<?= $content; ?>` since that prints the page content.
## Licensing, Modification, Etc
This is free! I may or may not make updates in the future to improve it and add functionality, but I wanted to make it as simple as possible so that the maximum number of people could use it easily. People are also welcome to fork it and adapt the code for their own purposes; no credit is required.

View File

@ -10,6 +10,11 @@ define("DB_LOCATION", "./kudos.db");
// Something to show in page titles. You could change this to "Kudos for [My Name]", etc.
define("SITE_NAME", "Kudos");
// This changes the image bgcolor! you probably want it to be something that the text will show up on.
// use "none" for transparent, but this might cause it to not show up if the background is the same color
// as the text.
define("IMAGE_BG", "white");
// Text Drawing Settings
$id = new ImagickDraw();
$id->setFont("./fonts/open-sans.ttf");

View File

@ -31,16 +31,18 @@ if (array_key_exists('give', $_GET)) {
$db->query("insert into kudos (workid, ipaddr) values (\"{$work}\", \"{$ip}\");");
$content = "Thanks for leaving kudos! You can now close this window.";
require("./template.php");
} else {
$content = "You've already left kudos on this work.";
require("./template.php");
}
} else if (array_key_exists('show', $_GET)) {
// We're showing the number of kudos
$work = filter_var($_GET['show'], FILTER_SANITIZE_STRING);
$res = $db->query("select count(*) from works where id=\"{$work}\";");
$res = $db->query("select count(*) from kudos where workid=\"{$work}\";");
if ($res) {
$res = $res->fetchArray();
$count = $res['count(*)'];
print_r($res);
} else {
$count = 0;
}
@ -48,7 +50,7 @@ if (array_key_exists('give', $_GET)) {
$image = new Imagick();
// writes the number
$id->annotation(50, 50, $count);
$image->newImage(100, 500, "none");
$image->newImage(100, 500, IMAGE_BG);
$image->setImageFormat("png");
$image->drawImage($id);
$image->trimImage(0);
@ -66,7 +68,7 @@ if (array_key_exists('give', $_GET)) {
// check if the work exists already since we can't do duplicates
$exists = $db->query("select count(*) from works where id=\"{$work}\";");
$content = "";
if ($exists == 0) {
if ($exists) {
// it doesn't already exist, so add it to the database
$result = $db->query("insert into works (id) values ('{$work}');");
// show a response with a message that tells us if it worked or not