[libravatar] Add addon config

- Update mentions of .htconfig.php
This commit is contained in:
Hypolite Petovan 2018-06-27 23:14:39 -04:00
parent 858d09e865
commit 8220a78a71
3 changed files with 35 additions and 16 deletions

View 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. 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.) 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. 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]. See examples at [Libravatar][1].
## Alternative Configuration ## 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" [1]: http://wiki.libravatar.org/api/ "See API documentation at Libravatar for more information"

View file

@ -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

View file

@ -14,12 +14,7 @@ use Friendica\Core\L10n;
*/ */
function libravatar_install() function libravatar_install()
{ {
if (! version_compare(PHP_VERSION, '5.3.0', '>=')) { Addon::registerHook('load_config', 'addon/libravatar/libravatar.php', 'libravatar_load_config');
info(L10n::t('Could NOT install Libravatar successfully.<br>It requires PHP >= 5.3') .EOL);
// avoid registering the hook
return false;
}
Addon::registerHook('avatar_lookup', 'addon/libravatar/libravatar.php', 'libravatar_lookup'); Addon::registerHook('avatar_lookup', 'addon/libravatar/libravatar.php', 'libravatar_lookup');
logger("registered libravatar in avatar_lookup hook"); logger("registered libravatar in avatar_lookup hook");
} }
@ -29,10 +24,16 @@ function libravatar_install()
*/ */
function libravatar_uninstall() function libravatar_uninstall()
{ {
Addon::unregisterHook('load_config', 'addon/libravatar/libravatar.php', 'libravatar_load_config');
Addon::unregisterHook('avatar_lookup', 'addon/libravatar/libravatar.php', 'libravatar_lookup'); Addon::unregisterHook('avatar_lookup', 'addon/libravatar/libravatar.php', 'libravatar_lookup');
logger("unregistered libravatar in avatar_lookup hook"); 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. * Looks up the avatar at Libravatar and returns the URL.
* *
@ -41,11 +42,11 @@ function libravatar_uninstall()
*/ */
function libravatar_lookup($a, &$b) function libravatar_lookup($a, &$b)
{ {
$default_avatar = Config::get('libravatar', 'default_img'); $default_avatar = Config::get('libravatar', 'default_avatar');
if (! $default_avatar) { if (! $default_avatar) {
// if not set, look up if there was one from the gravatar addon // 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 // setting default avatar if nothing configured
if (!$default_avatar) { if (!$default_avatar) {
$default_avatar = 'identicon'; // default image will be a random pattern $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"); $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 // set default values for first configuration
if (!$default_avatar) { if (!$default_avatar) {
@ -117,6 +118,6 @@ function libravatar_addon_admin_post(&$a)
check_form_security_token('libravatarrsave'); check_form_security_token('libravatarrsave');
$default_avatar = ((x($_POST, 'avatar')) ? notags(trim($_POST['avatar'])) : 'identicon'); $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); info(L10n::t('Libravatar settings updated.') .EOL);
} }