Add Cat Avatar Generator Addon
authorfabrixxm <fabrix.xm@gmail.com>
Thu, 5 Apr 2018 08:56:36 +0000 (10:56 +0200)
committerfabrixxm <fabrix.xm@gmail.com>
Thu, 5 Apr 2018 08:56:36 +0000 (10:56 +0200)
77 files changed:
catavatar/README.md [new file with mode: 0644]
catavatar/avatars/accessorie_1.png [new file with mode: 0644]
catavatar/avatars/accessorie_10.png [new file with mode: 0644]
catavatar/avatars/accessorie_11.png [new file with mode: 0644]
catavatar/avatars/accessorie_12.png [new file with mode: 0644]
catavatar/avatars/accessorie_13.png [new file with mode: 0644]
catavatar/avatars/accessorie_14.png [new file with mode: 0644]
catavatar/avatars/accessorie_15.png [new file with mode: 0644]
catavatar/avatars/accessorie_16.png [new file with mode: 0644]
catavatar/avatars/accessorie_17.png [new file with mode: 0644]
catavatar/avatars/accessorie_18.png [new file with mode: 0644]
catavatar/avatars/accessorie_19.png [new file with mode: 0644]
catavatar/avatars/accessorie_2.png [new file with mode: 0644]
catavatar/avatars/accessorie_20.png [new file with mode: 0644]
catavatar/avatars/accessorie_3.png [new file with mode: 0644]
catavatar/avatars/accessorie_4.png [new file with mode: 0644]
catavatar/avatars/accessorie_5.png [new file with mode: 0644]
catavatar/avatars/accessorie_6.png [new file with mode: 0644]
catavatar/avatars/accessorie_7.png [new file with mode: 0644]
catavatar/avatars/accessorie_8.png [new file with mode: 0644]
catavatar/avatars/accessorie_9.png [new file with mode: 0644]
catavatar/avatars/body_1.png [new file with mode: 0644]
catavatar/avatars/body_10.png [new file with mode: 0644]
catavatar/avatars/body_11.png [new file with mode: 0644]
catavatar/avatars/body_12.png [new file with mode: 0644]
catavatar/avatars/body_13.png [new file with mode: 0644]
catavatar/avatars/body_14.png [new file with mode: 0644]
catavatar/avatars/body_15.png [new file with mode: 0644]
catavatar/avatars/body_2.png [new file with mode: 0644]
catavatar/avatars/body_3.png [new file with mode: 0644]
catavatar/avatars/body_4.png [new file with mode: 0644]
catavatar/avatars/body_5.png [new file with mode: 0644]
catavatar/avatars/body_6.png [new file with mode: 0644]
catavatar/avatars/body_7.png [new file with mode: 0644]
catavatar/avatars/body_8.png [new file with mode: 0644]
catavatar/avatars/body_9.png [new file with mode: 0644]
catavatar/avatars/eyes_1.png [new file with mode: 0644]
catavatar/avatars/eyes_10.png [new file with mode: 0644]
catavatar/avatars/eyes_11.png [new file with mode: 0644]
catavatar/avatars/eyes_12.png [new file with mode: 0644]
catavatar/avatars/eyes_13.png [new file with mode: 0644]
catavatar/avatars/eyes_14.png [new file with mode: 0644]
catavatar/avatars/eyes_15.png [new file with mode: 0644]
catavatar/avatars/eyes_2.png [new file with mode: 0644]
catavatar/avatars/eyes_3.png [new file with mode: 0644]
catavatar/avatars/eyes_4.png [new file with mode: 0644]
catavatar/avatars/eyes_5.png [new file with mode: 0644]
catavatar/avatars/eyes_6.png [new file with mode: 0644]
catavatar/avatars/eyes_7.png [new file with mode: 0644]
catavatar/avatars/eyes_8.png [new file with mode: 0644]
catavatar/avatars/eyes_9.png [new file with mode: 0644]
catavatar/avatars/fur_1.png [new file with mode: 0644]
catavatar/avatars/fur_10.png [new file with mode: 0644]
catavatar/avatars/fur_2.png [new file with mode: 0644]
catavatar/avatars/fur_3.png [new file with mode: 0644]
catavatar/avatars/fur_4.png [new file with mode: 0644]
catavatar/avatars/fur_5.png [new file with mode: 0644]
catavatar/avatars/fur_6.png [new file with mode: 0644]
catavatar/avatars/fur_7.png [new file with mode: 0644]
catavatar/avatars/fur_8.png [new file with mode: 0644]
catavatar/avatars/fur_9.png [new file with mode: 0644]
catavatar/avatars/mouth_1.png [new file with mode: 0644]
catavatar/avatars/mouth_10.png [new file with mode: 0644]
catavatar/avatars/mouth_2.png [new file with mode: 0644]
catavatar/avatars/mouth_3.png [new file with mode: 0644]
catavatar/avatars/mouth_4.png [new file with mode: 0644]
catavatar/avatars/mouth_5.png [new file with mode: 0644]
catavatar/avatars/mouth_6.png [new file with mode: 0644]
catavatar/avatars/mouth_7.png [new file with mode: 0644]
catavatar/avatars/mouth_8.png [new file with mode: 0644]
catavatar/avatars/mouth_9.png [new file with mode: 0644]
catavatar/avatars/zz_1.png [new file with mode: 0644]
catavatar/avatars/zz_2.png [new file with mode: 0644]
catavatar/avatars/zz_bg.png [new file with mode: 0644]
catavatar/cat_src.ora [new file with mode: 0644]
catavatar/catavatar.php [new file with mode: 0644]
catavatar/templates/settings.tpl [new file with mode: 0644]

diff --git a/catavatar/README.md b/catavatar/README.md
new file mode 100644 (file)
index 0000000..c79c0de
--- /dev/null
@@ -0,0 +1,13 @@
+# Friendica Cat Avatar Generator Addon
+
+Generate a default avatar based on David Revoy's cat-avatar-generator https://framagit.org/Deevad/cat-avatar-generator
+
+## License:
+
+**Artworks:**
+PNG and ORA files licensed under: [CC-By 4.0](https://creativecommons.org/licenses/by/4.0/) 
+attribution: David Revoy with the following exception: 
+Generated cats used as Avatar (for blog,forum,social-network) don't need direct 
+attribution and so, can be used as regular avatars without pasting David Revoy's 
+name all over the place.
+
diff --git a/catavatar/avatars/accessorie_1.png b/catavatar/avatars/accessorie_1.png
new file mode 100644 (file)
index 0000000..8fed4e4
Binary files /dev/null and b/catavatar/avatars/accessorie_1.png differ
diff --git a/catavatar/avatars/accessorie_10.png b/catavatar/avatars/accessorie_10.png
new file mode 100644 (file)
index 0000000..fb0535b
Binary files /dev/null and b/catavatar/avatars/accessorie_10.png differ
diff --git a/catavatar/avatars/accessorie_11.png b/catavatar/avatars/accessorie_11.png
new file mode 100644 (file)
index 0000000..6a8256d
Binary files /dev/null and b/catavatar/avatars/accessorie_11.png differ
diff --git a/catavatar/avatars/accessorie_12.png b/catavatar/avatars/accessorie_12.png
new file mode 100644 (file)
index 0000000..778ac13
Binary files /dev/null and b/catavatar/avatars/accessorie_12.png differ
diff --git a/catavatar/avatars/accessorie_13.png b/catavatar/avatars/accessorie_13.png
new file mode 100644 (file)
index 0000000..ed193b6
Binary files /dev/null and b/catavatar/avatars/accessorie_13.png differ
diff --git a/catavatar/avatars/accessorie_14.png b/catavatar/avatars/accessorie_14.png
new file mode 100644 (file)
index 0000000..5533875
Binary files /dev/null and b/catavatar/avatars/accessorie_14.png differ
diff --git a/catavatar/avatars/accessorie_15.png b/catavatar/avatars/accessorie_15.png
new file mode 100644 (file)
index 0000000..3a481b6
Binary files /dev/null and b/catavatar/avatars/accessorie_15.png differ
diff --git a/catavatar/avatars/accessorie_16.png b/catavatar/avatars/accessorie_16.png
new file mode 100644 (file)
index 0000000..2016061
Binary files /dev/null and b/catavatar/avatars/accessorie_16.png differ
diff --git a/catavatar/avatars/accessorie_17.png b/catavatar/avatars/accessorie_17.png
new file mode 100644 (file)
index 0000000..85572a9
Binary files /dev/null and b/catavatar/avatars/accessorie_17.png differ
diff --git a/catavatar/avatars/accessorie_18.png b/catavatar/avatars/accessorie_18.png
new file mode 100644 (file)
index 0000000..85572a9
Binary files /dev/null and b/catavatar/avatars/accessorie_18.png differ
diff --git a/catavatar/avatars/accessorie_19.png b/catavatar/avatars/accessorie_19.png
new file mode 100644 (file)
index 0000000..85572a9
Binary files /dev/null and b/catavatar/avatars/accessorie_19.png differ
diff --git a/catavatar/avatars/accessorie_2.png b/catavatar/avatars/accessorie_2.png
new file mode 100644 (file)
index 0000000..e6d2a82
Binary files /dev/null and b/catavatar/avatars/accessorie_2.png differ
diff --git a/catavatar/avatars/accessorie_20.png b/catavatar/avatars/accessorie_20.png
new file mode 100644 (file)
index 0000000..85572a9
Binary files /dev/null and b/catavatar/avatars/accessorie_20.png differ
diff --git a/catavatar/avatars/accessorie_3.png b/catavatar/avatars/accessorie_3.png
new file mode 100644 (file)
index 0000000..27132b6
Binary files /dev/null and b/catavatar/avatars/accessorie_3.png differ
diff --git a/catavatar/avatars/accessorie_4.png b/catavatar/avatars/accessorie_4.png
new file mode 100644 (file)
index 0000000..42f36b2
Binary files /dev/null and b/catavatar/avatars/accessorie_4.png differ
diff --git a/catavatar/avatars/accessorie_5.png b/catavatar/avatars/accessorie_5.png
new file mode 100644 (file)
index 0000000..80def59
Binary files /dev/null and b/catavatar/avatars/accessorie_5.png differ
diff --git a/catavatar/avatars/accessorie_6.png b/catavatar/avatars/accessorie_6.png
new file mode 100644 (file)
index 0000000..23d64e8
Binary files /dev/null and b/catavatar/avatars/accessorie_6.png differ
diff --git a/catavatar/avatars/accessorie_7.png b/catavatar/avatars/accessorie_7.png
new file mode 100644 (file)
index 0000000..7bc0445
Binary files /dev/null and b/catavatar/avatars/accessorie_7.png differ
diff --git a/catavatar/avatars/accessorie_8.png b/catavatar/avatars/accessorie_8.png
new file mode 100644 (file)
index 0000000..b75675b
Binary files /dev/null and b/catavatar/avatars/accessorie_8.png differ
diff --git a/catavatar/avatars/accessorie_9.png b/catavatar/avatars/accessorie_9.png
new file mode 100644 (file)
index 0000000..3b33209
Binary files /dev/null and b/catavatar/avatars/accessorie_9.png differ
diff --git a/catavatar/avatars/body_1.png b/catavatar/avatars/body_1.png
new file mode 100644 (file)
index 0000000..9733137
Binary files /dev/null and b/catavatar/avatars/body_1.png differ
diff --git a/catavatar/avatars/body_10.png b/catavatar/avatars/body_10.png
new file mode 100644 (file)
index 0000000..a6c348d
Binary files /dev/null and b/catavatar/avatars/body_10.png differ
diff --git a/catavatar/avatars/body_11.png b/catavatar/avatars/body_11.png
new file mode 100644 (file)
index 0000000..d2dca09
Binary files /dev/null and b/catavatar/avatars/body_11.png differ
diff --git a/catavatar/avatars/body_12.png b/catavatar/avatars/body_12.png
new file mode 100644 (file)
index 0000000..b1070c0
Binary files /dev/null and b/catavatar/avatars/body_12.png differ
diff --git a/catavatar/avatars/body_13.png b/catavatar/avatars/body_13.png
new file mode 100644 (file)
index 0000000..80be4e4
Binary files /dev/null and b/catavatar/avatars/body_13.png differ
diff --git a/catavatar/avatars/body_14.png b/catavatar/avatars/body_14.png
new file mode 100644 (file)
index 0000000..42dd0a0
Binary files /dev/null and b/catavatar/avatars/body_14.png differ
diff --git a/catavatar/avatars/body_15.png b/catavatar/avatars/body_15.png
new file mode 100644 (file)
index 0000000..9597ba8
Binary files /dev/null and b/catavatar/avatars/body_15.png differ
diff --git a/catavatar/avatars/body_2.png b/catavatar/avatars/body_2.png
new file mode 100644 (file)
index 0000000..4f207ec
Binary files /dev/null and b/catavatar/avatars/body_2.png differ
diff --git a/catavatar/avatars/body_3.png b/catavatar/avatars/body_3.png
new file mode 100644 (file)
index 0000000..7314d76
Binary files /dev/null and b/catavatar/avatars/body_3.png differ
diff --git a/catavatar/avatars/body_4.png b/catavatar/avatars/body_4.png
new file mode 100644 (file)
index 0000000..4237aaf
Binary files /dev/null and b/catavatar/avatars/body_4.png differ
diff --git a/catavatar/avatars/body_5.png b/catavatar/avatars/body_5.png
new file mode 100644 (file)
index 0000000..2e066e0
Binary files /dev/null and b/catavatar/avatars/body_5.png differ
diff --git a/catavatar/avatars/body_6.png b/catavatar/avatars/body_6.png
new file mode 100644 (file)
index 0000000..1d90743
Binary files /dev/null and b/catavatar/avatars/body_6.png differ
diff --git a/catavatar/avatars/body_7.png b/catavatar/avatars/body_7.png
new file mode 100644 (file)
index 0000000..786eddc
Binary files /dev/null and b/catavatar/avatars/body_7.png differ
diff --git a/catavatar/avatars/body_8.png b/catavatar/avatars/body_8.png
new file mode 100644 (file)
index 0000000..ba9dce4
Binary files /dev/null and b/catavatar/avatars/body_8.png differ
diff --git a/catavatar/avatars/body_9.png b/catavatar/avatars/body_9.png
new file mode 100644 (file)
index 0000000..62f9287
Binary files /dev/null and b/catavatar/avatars/body_9.png differ
diff --git a/catavatar/avatars/eyes_1.png b/catavatar/avatars/eyes_1.png
new file mode 100644 (file)
index 0000000..f724b67
Binary files /dev/null and b/catavatar/avatars/eyes_1.png differ
diff --git a/catavatar/avatars/eyes_10.png b/catavatar/avatars/eyes_10.png
new file mode 100644 (file)
index 0000000..33f1aa7
Binary files /dev/null and b/catavatar/avatars/eyes_10.png differ
diff --git a/catavatar/avatars/eyes_11.png b/catavatar/avatars/eyes_11.png
new file mode 100644 (file)
index 0000000..5596fe8
Binary files /dev/null and b/catavatar/avatars/eyes_11.png differ
diff --git a/catavatar/avatars/eyes_12.png b/catavatar/avatars/eyes_12.png
new file mode 100644 (file)
index 0000000..8f15efc
Binary files /dev/null and b/catavatar/avatars/eyes_12.png differ
diff --git a/catavatar/avatars/eyes_13.png b/catavatar/avatars/eyes_13.png
new file mode 100644 (file)
index 0000000..0480bbc
Binary files /dev/null and b/catavatar/avatars/eyes_13.png differ
diff --git a/catavatar/avatars/eyes_14.png b/catavatar/avatars/eyes_14.png
new file mode 100644 (file)
index 0000000..c7f9621
Binary files /dev/null and b/catavatar/avatars/eyes_14.png differ
diff --git a/catavatar/avatars/eyes_15.png b/catavatar/avatars/eyes_15.png
new file mode 100644 (file)
index 0000000..876ddc5
Binary files /dev/null and b/catavatar/avatars/eyes_15.png differ
diff --git a/catavatar/avatars/eyes_2.png b/catavatar/avatars/eyes_2.png
new file mode 100644 (file)
index 0000000..fa46f1f
Binary files /dev/null and b/catavatar/avatars/eyes_2.png differ
diff --git a/catavatar/avatars/eyes_3.png b/catavatar/avatars/eyes_3.png
new file mode 100644 (file)
index 0000000..4cee32d
Binary files /dev/null and b/catavatar/avatars/eyes_3.png differ
diff --git a/catavatar/avatars/eyes_4.png b/catavatar/avatars/eyes_4.png
new file mode 100644 (file)
index 0000000..642a36b
Binary files /dev/null and b/catavatar/avatars/eyes_4.png differ
diff --git a/catavatar/avatars/eyes_5.png b/catavatar/avatars/eyes_5.png
new file mode 100644 (file)
index 0000000..b41c9c6
Binary files /dev/null and b/catavatar/avatars/eyes_5.png differ
diff --git a/catavatar/avatars/eyes_6.png b/catavatar/avatars/eyes_6.png
new file mode 100644 (file)
index 0000000..3511828
Binary files /dev/null and b/catavatar/avatars/eyes_6.png differ
diff --git a/catavatar/avatars/eyes_7.png b/catavatar/avatars/eyes_7.png
new file mode 100644 (file)
index 0000000..b971e00
Binary files /dev/null and b/catavatar/avatars/eyes_7.png differ
diff --git a/catavatar/avatars/eyes_8.png b/catavatar/avatars/eyes_8.png
new file mode 100644 (file)
index 0000000..f54f041
Binary files /dev/null and b/catavatar/avatars/eyes_8.png differ
diff --git a/catavatar/avatars/eyes_9.png b/catavatar/avatars/eyes_9.png
new file mode 100644 (file)
index 0000000..19373a2
Binary files /dev/null and b/catavatar/avatars/eyes_9.png differ
diff --git a/catavatar/avatars/fur_1.png b/catavatar/avatars/fur_1.png
new file mode 100644 (file)
index 0000000..3a627f7
Binary files /dev/null and b/catavatar/avatars/fur_1.png differ
diff --git a/catavatar/avatars/fur_10.png b/catavatar/avatars/fur_10.png
new file mode 100644 (file)
index 0000000..c253156
Binary files /dev/null and b/catavatar/avatars/fur_10.png differ
diff --git a/catavatar/avatars/fur_2.png b/catavatar/avatars/fur_2.png
new file mode 100644 (file)
index 0000000..8f042df
Binary files /dev/null and b/catavatar/avatars/fur_2.png differ
diff --git a/catavatar/avatars/fur_3.png b/catavatar/avatars/fur_3.png
new file mode 100644 (file)
index 0000000..85572a9
Binary files /dev/null and b/catavatar/avatars/fur_3.png differ
diff --git a/catavatar/avatars/fur_4.png b/catavatar/avatars/fur_4.png
new file mode 100644 (file)
index 0000000..85fe1dd
Binary files /dev/null and b/catavatar/avatars/fur_4.png differ
diff --git a/catavatar/avatars/fur_5.png b/catavatar/avatars/fur_5.png
new file mode 100644 (file)
index 0000000..76a9efd
Binary files /dev/null and b/catavatar/avatars/fur_5.png differ
diff --git a/catavatar/avatars/fur_6.png b/catavatar/avatars/fur_6.png
new file mode 100644 (file)
index 0000000..144daca
Binary files /dev/null and b/catavatar/avatars/fur_6.png differ
diff --git a/catavatar/avatars/fur_7.png b/catavatar/avatars/fur_7.png
new file mode 100644 (file)
index 0000000..85572a9
Binary files /dev/null and b/catavatar/avatars/fur_7.png differ
diff --git a/catavatar/avatars/fur_8.png b/catavatar/avatars/fur_8.png
new file mode 100644 (file)
index 0000000..fd9028d
Binary files /dev/null and b/catavatar/avatars/fur_8.png differ
diff --git a/catavatar/avatars/fur_9.png b/catavatar/avatars/fur_9.png
new file mode 100644 (file)
index 0000000..ab44aea
Binary files /dev/null and b/catavatar/avatars/fur_9.png differ
diff --git a/catavatar/avatars/mouth_1.png b/catavatar/avatars/mouth_1.png
new file mode 100644 (file)
index 0000000..a0f13b7
Binary files /dev/null and b/catavatar/avatars/mouth_1.png differ
diff --git a/catavatar/avatars/mouth_10.png b/catavatar/avatars/mouth_10.png
new file mode 100644 (file)
index 0000000..4e93195
Binary files /dev/null and b/catavatar/avatars/mouth_10.png differ
diff --git a/catavatar/avatars/mouth_2.png b/catavatar/avatars/mouth_2.png
new file mode 100644 (file)
index 0000000..8b22601
Binary files /dev/null and b/catavatar/avatars/mouth_2.png differ
diff --git a/catavatar/avatars/mouth_3.png b/catavatar/avatars/mouth_3.png
new file mode 100644 (file)
index 0000000..ade5123
Binary files /dev/null and b/catavatar/avatars/mouth_3.png differ
diff --git a/catavatar/avatars/mouth_4.png b/catavatar/avatars/mouth_4.png
new file mode 100644 (file)
index 0000000..84e2bfe
Binary files /dev/null and b/catavatar/avatars/mouth_4.png differ
diff --git a/catavatar/avatars/mouth_5.png b/catavatar/avatars/mouth_5.png
new file mode 100644 (file)
index 0000000..44faf27
Binary files /dev/null and b/catavatar/avatars/mouth_5.png differ
diff --git a/catavatar/avatars/mouth_6.png b/catavatar/avatars/mouth_6.png
new file mode 100644 (file)
index 0000000..bd7008b
Binary files /dev/null and b/catavatar/avatars/mouth_6.png differ
diff --git a/catavatar/avatars/mouth_7.png b/catavatar/avatars/mouth_7.png
new file mode 100644 (file)
index 0000000..20183dc
Binary files /dev/null and b/catavatar/avatars/mouth_7.png differ
diff --git a/catavatar/avatars/mouth_8.png b/catavatar/avatars/mouth_8.png
new file mode 100644 (file)
index 0000000..c316f7f
Binary files /dev/null and b/catavatar/avatars/mouth_8.png differ
diff --git a/catavatar/avatars/mouth_9.png b/catavatar/avatars/mouth_9.png
new file mode 100644 (file)
index 0000000..497aefe
Binary files /dev/null and b/catavatar/avatars/mouth_9.png differ
diff --git a/catavatar/avatars/zz_1.png b/catavatar/avatars/zz_1.png
new file mode 100644 (file)
index 0000000..a3b254f
Binary files /dev/null and b/catavatar/avatars/zz_1.png differ
diff --git a/catavatar/avatars/zz_2.png b/catavatar/avatars/zz_2.png
new file mode 100644 (file)
index 0000000..3fd02fa
Binary files /dev/null and b/catavatar/avatars/zz_2.png differ
diff --git a/catavatar/avatars/zz_bg.png b/catavatar/avatars/zz_bg.png
new file mode 100644 (file)
index 0000000..5fbac19
Binary files /dev/null and b/catavatar/avatars/zz_bg.png differ
diff --git a/catavatar/cat_src.ora b/catavatar/cat_src.ora
new file mode 100644 (file)
index 0000000..2fc2560
Binary files /dev/null and b/catavatar/cat_src.ora differ
diff --git a/catavatar/catavatar.php b/catavatar/catavatar.php
new file mode 100644 (file)
index 0000000..f8a6d2f
--- /dev/null
@@ -0,0 +1,306 @@
+<?php
+/**
+ * Name: Cat Avatar Generator
+ * Description: Generate a default avatar based on David Revoy's cat-avatar-generator https://framagit.org/Deevad/cat-avatar-generator
+ * Version: 1.1
+ * Author: Fabio <https://kirgroup.com/profile/fabrixxm>
+ */
+use Friendica\Core\Addon;
+use Friendica\Core\Config;
+use Friendica\Core\L10n;
+use Friendica\Core\Worker;
+use Friendica\Core\PConfig;
+use Friendica\Util\DateTimeFormat;
+use Friendica\Network\HTTPException\NotFoundException;
+
+define("CATAVATAR_SIZE", 256);
+
+/**
+ * Installs the addon hook
+ */
+function catavatar_install() {
+       Addon::registerHook('avatar_lookup', 'addon/catavatar/catavatar.php', 'catavatar_lookup');
+       Addon::registerHook('addon_settings', 'addon/catavatar/catavatar.php', 'catavatar_addon_settings');
+       Addon::registerHook('addon_settings_post', 'addon/catavatar/catavatar.php', 'catavatar_addon_settings_post');
+
+       logger("registered catavatar");
+}
+
+/**
+ * Removes the addon hook
+ */
+function catavatar_uninstall() {
+       Addon::unregisterHook('avatar_lookup', 'addon/catavatar/catavatar.php', 'catavatar_lookup');
+       Addon::unregisterHook('addon_settings', 'addon/catavatar/catavatar.php', 'catavatar_addon_settings');
+       Addon::unregisterHook('addon_settings_post', 'addon/catavatar/catavatar.php', 'catavatar_addon_settings_post');
+       
+       logger("unregistered catavatar");
+}
+
+
+function catavatar_addon_settings(&$a, &$s) {
+       if(! local_user())
+               return;
+
+       $t = get_markup_template("settings.tpl", "addon/catavatar/" );
+       $s = replace_macros ($t, [
+               '$postpost' => x($_POST,"catavatar-morecat") || x($_POST,"catavatar-emailcat"),
+               '$uncache' => time(),
+               '$uid' => local_user(),
+               '$usecat' => L10n::t('Use Cat as Avatar'),
+               '$morecat' => L10n::t('More Random Cat!'),
+               '$emailcat' => L10n::t('Reset to email Cat'),
+               '$seed' => PConfig::get(local_user(), "catavatar", "seed", false),
+               '$header' => L10n::t('Cat Avatar').' '.L10n::t('Settings'),
+       ]);
+       return;
+}
+
+function catavatar_addon_settings_post(&$a, &$s) {
+       if(! local_user())
+               return;
+               
+       // delete the current cached cat avatar
+       $user = dba::selectFirst('user', ['email'],
+               [
+                       'uid' => $uid,
+                       'blocked' => 0,
+                       'account_expired' => 0,
+                       'account_removed' => 0,
+               ]
+       );
+       $seed = PConfig::get(local_user(), "catavatar", "seed", md5(trim(strtolower($user['email']))));
+       $imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $seed); 
+       $imageurl = substr($imageurl,0,35).'';
+       $cachefile = get_cachefile($imageurl);
+       if ($cachefile != "" && file_exists($cachefile)) {
+               unlink($cachefile);
+       }
+               
+               
+       if (x($_POST,"catavatar-usecat")) {
+               $url = $a->get_baseurl()."/catavatar/".local_user();
+               
+               // set the catavatar url as avatar url in contact and default profile
+               // and set profile to 0 to current photo
+               // I'm not sure it's the correct way to do this...
+               $r = dba::update('contact', 
+                       ['photo'=>$url."/4", 'thumb'=>$url."/5", 'micro'=>$url."/6", 'avatar-date'=>DateTimeFormat::utcNow()], 
+                       ['uid'=>local_user(), 'self'=>1]
+               );
+               if ($r===false) {
+                       notice(L10n::t('There was an error, the cat ran away.'));
+                       return;
+               }
+
+               $r = dba::update('profile', 
+                       ['photo'=>$url."/4", 'thumb'=>$url."/5"], 
+                       ['uid'=>local_user(), 'is-default'=>1]
+               );
+               if ($r===false) {
+                       notice(L10n::t('There was an error, the cat ran away.'));
+                       return;
+               }
+
+               $r = dba::update('photo', 
+                       ['profile'=>0], 
+                       ['uid'=>local_user(), 'profile'=>1]
+               );
+               if ($r===false) {
+                       notice(L10n::t('There was an error, the cat ran away.'));
+                       return;
+               }
+
+
+               // Update global directory in background
+               $url = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
+               if ($url && strlen(Config::get('system','directory'))) {
+                       Worker::add(PRIORITY_LOW, "Directory", $url);
+               }
+
+               Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
+               
+               info(L10n::t("Meow!"));
+               return;
+       }
+       
+
+
+       if (x($_POST,"catavatar-morecat")) {
+               PConfig::set(local_user(), "catavatar", "seed", time());
+       }
+
+       if (x($_POST,"catavatar-emailcat")) {
+               PConfig::delete(local_user(), "catavatar", "seed");
+       }
+}
+
+
+/**
+ * Returns the URL to the cat avatar
+ *
+ * @param $a array
+ * @param &$b array
+ */
+function catavatar_lookup($a, &$b) {
+       $user = dba::selectFirst('user', ['uid'],['email'=>$b['email']]);
+       
+       $url = $a->get_baseurl().'/catavatar/'.$user['uid'];
+
+       switch($b['size']) {
+               case 175: $url.="/4"; break;
+               case 80: $url.="/5"; break;
+               case 47: $url.="/6"; break;
+       }
+
+       $b['url'] = $url;
+       $b['success'] = true;
+}
+
+
+function catavatar_module(){}
+
+
+/**
+ * Returns image for user id
+ *
+ * @throws NotFoundException
+ *
+ * @TODO: support sizes
+ */
+function catavatar_content($a) {
+       if ($a->argc < 2 || $a->argc > 3)
+               throw new NotFoundException(); // this should be catched on index and show default "not found" page.
+
+       $uid = intval($a->argv[1]);
+       
+       $size = 0;
+       if ($a->argc == 3) {
+               $size = intval($a->argv[2]);
+       }
+       
+       $user = dba::selectFirst('user', ['email'],
+               [
+                       'uid' => $uid,
+                       'blocked' => 0,
+                       'account_expired' => 0,
+                       'account_removed' => 0,
+               ]
+       );      
+       
+       if ($user === False)
+               throw new NotFoundException();
+       
+       $seed = PConfig::get(local_user(), "catavatar", "seed", md5(trim(strtolower($user['email']))));
+       //echo "<pre>"; var_dump($hash); killme();
+
+       
+       // from cat-avatar-generator.php
+
+       $imageurl = $seed."-".$size;
+       $imageurl = preg_replace('/[^A-Za-z0-9\._-]/', '', $imageurl); 
+       $imageurl = substr($imageurl,0,35).'';
+       $cachefile = get_cachefile($imageurl);
+       $cachetime = 604800; # 1 week (1 day = 86400)
+
+       // Serve from the cache if it is younger than $cachetime
+       if ($cachefile != "" && file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) {
+               header('Pragma: public');
+               header('Cache-Control: max-age=86400');
+               header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
+               header('Content-Type: image/jpg');
+               readfile($cachefile);
+               exit;
+       }
+
+       // ...Or start generation
+       ob_start(); 
+
+       // render the picture:
+       build_cat($seed, $size);
+
+       // Save/cache the output to a file
+       if ($cachefile!=""){
+               $savedfile = fopen($cachefile, 'w+'); # w+ to be at start of the file, write mode, and attempt to create if not existing.
+               fwrite($savedfile, ob_get_contents());
+               fclose($savedfile);
+               chmod($cachefile, 0755);
+       }
+       ob_end_flush();
+
+       killme();
+}
+
+
+
+/**
+ * ====================
+ * CAT-AVATAR-GENERATOR
+ * ====================
+ * 
+ * @authors: Andreas Gohr, David Revoy
+ * 
+ * This PHP is licensed under the short and simple permissive:
+ * [MIT License](https://en.wikipedia.org/wiki/MIT_License)
+ * 
+**/
+
+function build_cat($seed='', $size=0){
+
+       // init random seed
+       if($seed) srand( hexdec(substr(md5($seed),0,6)) );
+
+       // throw the dice for body parts
+       $parts = array(
+               'body' => rand(1,15),
+               'fur' => rand(1,10),
+               'eyes' => rand(1,15),
+               'mouth' => rand(1,10),
+               'accessorie' => rand(1,20)
+       );
+
+       // create backgound
+       $cat = @imagecreatetruecolor(CATAVATAR_SIZE, CATAVATAR_SIZE)
+               or die("GD image create failed");
+       $white = imagecolorallocate($cat, 255, 255, 255);
+       imagefill($cat,0,0,$white);
+
+       // add parts
+       foreach($parts as $part => $num){
+               $file = dirname(__FILE__).'/avatars/'.$part.'_'.$num.'.png';
+
+               $im = @imagecreatefrompng($file);
+               if(!$im) die('Failed to load '.$file);
+               imageSaveAlpha($im, true);
+               imagecopy($cat,$im,0,0,0,0,CATAVATAR_SIZE,CATAVATAR_SIZE);
+               imagedestroy($im);
+       }
+
+       // scale image
+       if ($size > 3 && $size < 7) {
+               switch($size) {
+                       case 4: $size = 175; break;
+                       case 5: $size = 80; break;
+                       case 6: $size = 48; break;
+               }
+       
+               $dest = imagecreatetruecolor($size, $size);
+               imagealphablending($dest, false);
+               imagesavealpha($dest, true);
+               imagecopyresampled($dest, $cat, 0, 0, 0, 0, $size, $size, CATAVATAR_SIZE, CATAVATAR_SIZE);
+               imagedestroy($cat);
+               $cat = $dest;
+       }
+       
+       // restore random seed
+       if($seed) srand();
+
+       header('Pragma: public');
+       header('Cache-Control: max-age=86400');
+       header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 86400));
+       header('Content-Type: image/jpg');
+       imagejpeg($cat, NULL, 90);
+       imagedestroy($cat);
+}
+
+
diff --git a/catavatar/templates/settings.tpl b/catavatar/templates/settings.tpl
new file mode 100644 (file)
index 0000000..19f5f0b
--- /dev/null
@@ -0,0 +1,24 @@
+<span id="settings_catavatar_inflated" class="settings-block fakelink" 
+       style="{{if $postpost}}display: none;{{else}}display: block;{{/if}}" 
+       onclick="openClose('settings_catavatar_expanded'); openClose('settings_catavatar_inflated');">
+               <h3>{{$header}}</h3>
+</span>
+<div id="settings_catavatar_expanded" class="settings-block" 
+       style="{{if $postpost}}display: block;{{else}}display: none;{{/if}}">
+       <span class="fakelink" onclick="openClose('settings_catavatar_expanded'); openClose('settings_catavatar_inflated');">
+               <h3>{{$header}}</h3>
+       </span>
+       <img src="{{$basepath}}/catavatar/{{$uid}}?{{$uncache}}">
+       <p>Set default profile avatar or randomize the cat</p>
+       <div class="settings-submit-wrapper" >
+               <input type="submit" name="catavatar-usecat" 
+                       class="btn btn-primary settings-submit" value="{{$usecat}}" />
+               
+               <div class="btn-group" role="group" aria-label="...">
+                       <input type="submit" name="catavatar-morecat" 
+                               class="btn btn-default settings-submit" value="{{$morecat}}" />
+                       <input type="submit" name="catavatar-emailcat" {{if !$seed}}disabled{{/if}}
+                               class="btn btn-default settings-submit" value="{{$emailcat}}" />
+               </div>
+       </div>
+</div>