From 8220a78a712adf9aee072d477f90200faa1a95a5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 27 Jun 2018 23:14:39 -0400 Subject: [PATCH] [libravatar] Add addon config - Update mentions of .htconfig.php --- libravatar/README.md | 12 ++++++------ libravatar/config/libravatar.ini.php | 18 ++++++++++++++++++ libravatar/libravatar.php | 21 +++++++++++---------- 3 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 libravatar/config/libravatar.ini.php diff --git a/libravatar/README.md b/libravatar/README.md index d535aa07..99cddefc 100644 --- a/libravatar/README.md +++ b/libravatar/README.md @@ -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 index 00000000..fccf6753 --- /dev/null +++ b/libravatar/config/libravatar.ini.php @@ -0,0 +1,18 @@ +=')) { - info(L10n::t('Could NOT install Libravatar successfully.
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); }