X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=gravatar%2Fgravatar.php;h=894abda6d748c7dace81010926f3084defce3036;hb=a0344101f122248c3069a5dcfa3ebfcb67215d5a;hp=a0b5a02b3ff3c4c72c845b22730aa018a2718163;hpb=75f47b74d2295f82fa28abe06a3d18662cc42c5f;p=friendica-addons.git diff --git a/gravatar/gravatar.php b/gravatar/gravatar.php index a0b5a02b..894abda6 100644 --- a/gravatar/gravatar.php +++ b/gravatar/gravatar.php @@ -1,27 +1,34 @@ */ +use Friendica\App; +use Friendica\BaseModule; +use Friendica\Core\Hook; +use Friendica\Core\Logger; +use Friendica\Core\Renderer; +use Friendica\Database\DBA; +use Friendica\DI; +use Friendica\Util\ConfigFileLoader; +use Friendica\Util\Strings; + /** - * Installs the plugin hook + * Installs the addon hook */ function gravatar_install() { - register_hook('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup'); + Hook::register('load_config', 'addon/gravatar/gravatar.php', 'gravatar_load_config'); + Hook::register('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup'); - logger("registered gravatar in avatar_lookup hook"); + Logger::log("registered gravatar in avatar_lookup hook"); } -/** - * Removes the plugin hook - */ -function gravatar_uninstall() { - unregister_hook('avatar_lookup', 'addon/gravatar/gravatar.php', 'gravatar_lookup'); - - logger("unregistered gravatar in avatar_lookup hook"); +function gravatar_load_config(App $a, ConfigFileLoader $loader) +{ + $a->getConfigCache()->load($loader->loadAddonConfig('gravatar')); } /** @@ -31,8 +38,8 @@ function gravatar_uninstall() { * @param &$b array */ function gravatar_lookup($a, &$b) { - $default_avatar = get_config('gravatar', 'default_img'); - $rating = get_config('gravatar', 'rating'); + $default_avatar = DI::config()->get('gravatar', 'default_avatar'); + $rating = DI::config()->get('gravatar', 'rating'); // setting default value if nothing configured if(! $default_avatar) @@ -42,23 +49,23 @@ function gravatar_lookup($a, &$b) { $hash = md5(trim(strtolower($b['email']))); - $url = 'http://www.gravatar.com/avatar/' .$hash .'.jpg'; + $url = 'https://secure.gravatar.com/avatar/' .$hash .'.jpg'; $url .= '?s=' .$b['size'] .'&r=' .$rating; if ($default_avatar != "gravatar") $url .= '&d=' .$default_avatar; - $b['url'] = $url; + $b['url'] = $url; $b['success'] = true; } /** * Display admin settings for this addon */ -function gravatar_plugin_admin (&$a, &$o) { - $t = get_markup_template( "admin.tpl", "addon/gravatar/" ); +function gravatar_addon_admin (&$a, &$o) { + $t = Renderer::getMarkupTemplate( "admin.tpl", "addon/gravatar/" ); - $default_avatar = get_config('gravatar', 'default_img'); - $rating = get_config('gravatar', 'rating'); + $default_avatar = DI::config()->get('gravatar', 'default_avatar'); + $rating = DI::config()->get('gravatar', 'rating'); // set default values for first configuration if(! $default_avatar) @@ -67,53 +74,45 @@ function gravatar_plugin_admin (&$a, &$o) { $rating = 'g'; // suitable for display on all websites with any audience type // Available options for the select boxes - $default_avatars = array( - 'mm' => t('generic profile image'), - 'identicon' => t('random geometric pattern'), - 'monsterid' => t('monster face'), - 'wavatar' => t('computer generated face'), - 'retro' => t('retro arcade style face'), - ); - $ratings = array( + $default_avatars = [ + 'mm' => DI::l10n()->t('generic profile image'), + 'identicon' => DI::l10n()->t('random geometric pattern'), + 'monsterid' => DI::l10n()->t('monster face'), + 'wavatar' => DI::l10n()->t('computer generated face'), + 'retro' => DI::l10n()->t('retro arcade style face'), + ]; + $ratings = [ 'g' => 'g', 'pg' => 'pg', 'r' => 'r', 'x' => 'x' - ); + ]; // Check if Libravatar is enabled and show warning $r = q("SELECT * FROM `addon` WHERE `name` = '%s' and `installed` = 1", - dbesc('libravatar') + DBA::escape('libravatar') ); if (count($r)) { - $o = '
' .t('Libravatar addon is installed, too. Please disable Libravatar addon or this Gravatar addon.
The Libravatar addon will fall back to Gravatar if nothing was found at Libravatar.') .'
' .DI::l10n()->t('Libravatar addon is installed, too. Please disable Libravatar addon or this Gravatar addon.
The Libravatar addon will fall back to Gravatar if nothing was found at Libravatar.') .'