[libravatar] Add addon config
authorHypolite Petovan <mrpetovan@gmail.com>
Thu, 28 Jun 2018 03:14:39 +0000 (23:14 -0400)
committerHypolite Petovan <mrpetovan@gmail.com>
Tue, 10 Jul 2018 12:39:48 +0000 (08:39 -0400)
- Update mentions of .htconfig.php

libravatar/README.md
libravatar/config/libravatar.ini.php [new file with mode: 0644]
libravatar/libravatar.php

index d535aa0..99cddef 100644 (file)
@@ -9,8 +9,6 @@ This addon allows you to look up an avatar image for new users and contacts at [
 Libravatar is a free and open replacement for Gravatar. It is a service where people can store an avatar image for their email-addresses. These avatar images can get looked up for example in comment functions, profile pages, etc. on other sites. There exists a central installation at [www.libravatar.com](http://www.libravatar.com), but you can also host it on your own server. If no avatar was found Libravatar will look up at Gravatar as a fallback.
 There is no rating available, as it is on Gravatar, so all avatar lookups are g-rated. (Suitable for all audiences.)
 
-PHP >= 5.3 is required for this addon!
-
 You can not use the Libravatar and Gravatar addon at the same time. You need to choose one. If you need other ratings than g you better stay with Gravatar, otherwise it is safe to use Libravatar, because it will fall back to Gravatar if nothing was found at Libravatar.
 
 * * *
@@ -28,12 +26,14 @@ If no avatar was found for an email Libravatar can create some pseudo-random gen
 See examples at [Libravatar][1].
 
 ## Alternative Configuration
-Open the .htconfig.php file and add "libravatar" to the list of activated addons:
+Open the config/local.ini.php file and add "libravatar" to the list of activated addons:
 
-        $a->config['system']['addon'] = "..., libravatar";
+        [system]
+               addon = ...,libravatar
 
-You can add one configuration variable for the addon:
+You can add one configuration variables for the addon:
 
-        $a->config['libravatar']['default_avatar'] = "identicon";
+        [libravatar]
+               default_avatar = identicon
 
 [1]: http://wiki.libravatar.org/api/ "See API documentation at Libravatar for more information"
diff --git a/libravatar/config/libravatar.ini.php b/libravatar/config/libravatar.ini.php
new file mode 100644 (file)
index 0000000..fccf675
--- /dev/null
@@ -0,0 +1,18 @@
+<?php return <<<INI
+
+; Warning: Don't change this file! It only holds the default config values for this addon.
+; Instead overwrite these config values in config/local.ini.php in your Friendica directory
+
+[libravatar]
+; default_avatar (String)
+; If no avatar was found for an email Gravatar can create some pseudo-random generated avatars based on an email hash.
+; You can choose between these presets:
+; - mm       : (mystery-man) a static image
+; - identicon: a generated geometric pattern based on email hash
+; - monsterid: a generated 'monster' with different colors, faces, etc. based on email hash
+; - wavatar  : faces with different features and backgrounds based on email hash
+; - retro    : 8-bit arcade-styled pixelated faces based on email hash
+default_avatar = identicon
+
+INI;
+//Keep this line
\ No newline at end of file
index dd1d613..14bc035 100644 (file)
@@ -14,12 +14,7 @@ use Friendica\Core\L10n;
  */
 function libravatar_install()
 {
-       if (! version_compare(PHP_VERSION, '5.3.0', '>=')) {
-               info(L10n::t('Could NOT install Libravatar successfully.<br>It requires PHP >= 5.3') .EOL);
-               // avoid registering the hook
-               return false;
-       }
-
+       Addon::registerHook('load_config',   'addon/libravatar/libravatar.php', 'libravatar_load_config');
        Addon::registerHook('avatar_lookup', 'addon/libravatar/libravatar.php', 'libravatar_lookup');
        logger("registered libravatar in avatar_lookup hook");
 }
@@ -29,10 +24,16 @@ function libravatar_install()
  */
 function libravatar_uninstall()
 {
+       Addon::unregisterHook('load_config',   'addon/libravatar/libravatar.php', 'libravatar_load_config');
        Addon::unregisterHook('avatar_lookup', 'addon/libravatar/libravatar.php', 'libravatar_lookup');
        logger("unregistered libravatar in avatar_lookup hook");
 }
 
+function libravatar_load_config(\Friendica\App $a)
+{
+       $a->loadConfigFile(__DIR__. '/config/libravatar.ini.php');
+}
+
 /**
  * Looks up the avatar at Libravatar and returns the URL.
  *
@@ -41,11 +42,11 @@ function libravatar_uninstall()
  */
 function libravatar_lookup($a, &$b)
 {
-       $default_avatar = Config::get('libravatar', 'default_img');
+       $default_avatar = Config::get('libravatar', 'default_avatar');
 
        if (! $default_avatar) {
                // if not set, look up if there was one from the gravatar addon
-               $default_avatar = Config::get('gravatar', 'default_img');
+               $default_avatar = Config::get('gravatar', 'default_avatar');
                // setting default avatar if nothing configured
                if (!$default_avatar) {
                        $default_avatar = 'identicon'; // default image will be a random pattern
@@ -69,7 +70,7 @@ function libravatar_addon_admin(&$a, &$o)
 {
        $t = get_markup_template("admin.tpl", "addon/libravatar");
 
-       $default_avatar = Config::get('libravatar', 'default_img');
+       $default_avatar = Config::get('libravatar', 'default_avatar');
 
        // set default values for first configuration
        if (!$default_avatar) {
@@ -117,6 +118,6 @@ function libravatar_addon_admin_post(&$a)
        check_form_security_token('libravatarrsave');
 
        $default_avatar = ((x($_POST, 'avatar')) ? notags(trim($_POST['avatar'])) : 'identicon');
-       Config::set('libravatar', 'default_img', $default_avatar);
+       Config::set('libravatar', 'default_avatar', $default_avatar);
        info(L10n::t('Libravatar settings updated.') .EOL);
 }