Ejemplo n.º 1
0
/**
 * Looks up the avatar at Libravatar and returns the URL.
 *
 * @param $a array
 * @param &$b array
 */
function libravatar_lookup($a, &$b)
{
    $default_avatar = get_config('libravatar', 'default_img');
    if (!$default_avatar) {
        // if not set, look up if there was one from the gravatar addon
        $default_avatar = get_config('gravatar', 'default_img');
        // setting default avatar if nothing configured
        if (!$default_avatar) {
            $default_avatar = 'identicon';
        }
        // default image will be a random pattern
    }
    require_once 'Services/Libravatar.php';
    $libravatar = new Services_Libravatar();
    $libravatar->setSize($b['size']);
    $libravatar->setDefault($default_avatar);
    $avatar_url = $libravatar->getUrl($b['email']);
    $b['url'] = $avatar_url;
    $b['success'] = true;
}
Ejemplo n.º 2
0
 function libravatar_url($email, $size)
 {
     global $config;
     $defaultavatar = Avatar::defaultImage($size);
     if (isset($config['Libravatar']) && isset($config['Libravatar']['nocheck']) && $config['Libravatar']['nocheck'] === true) {
         include_once 'Services/Libravatar.php';
     } else {
         try {
             if (function_exists('stream_resolve_include_path') && stream_resolve_include_path('Services/Libravatar.php')) {
                 include_once 'Services/Libravatar.php';
             }
         } catch (exception $e) {
             return $defaultavatar;
         }
     }
     if (!class_exists('Services_Libravatar')) {
         return $defaultavatar;
     }
     $libravatar = new Services_Libravatar();
     $libravatar->setSize($size)->setDefault(Avatar::defaultImage($size))->setHttps(true);
     $url = $libravatar->getUrl($email);
     return $url;
 }
/**
 * Generates the output for a <libravatar/> tag during parsing.
 *
 * @param string      $content Content of the tag
 *                             (between opening and closing tag)
 * @param array       $params  Array of tag parameters.
 * @param Parser      $parser  MediaWiki parser object
 * @param PPFrame_DOM $frame   Context data with e.g. template variables
 *
 * @return string HTML representation of the libravatar tag.
 *
 * @throws MWException In case Services_Libravatar is not available
 */
function mwLibravatarTagParse($content, $params, $parser, $frame)
{
    include_once 'Services/Libravatar.php';
    if (!class_exists('Services_Libravatar')) {
        throw new MWException('Libravatar: Services_Libravatar not available');
    }
    $sla = new Services_Libravatar();
    $sla->detectHttps();
    $extra = '';
    try {
        // email attribute
        if (isset($params['email'])) {
            //all fine
        } else {
            if ($content != '') {
                $params['email'] = trim($content);
            } else {
                throw new InvalidArgumentException('email attribute missing');
            }
        }
        $params['email'] = $parser->recursiveTagParse($params['email'], $frame);
        // size attribute
        if (isset($params['size'])) {
            $params['size'] = (int) $params['size'];
        } else {
            if (isset($GLOBALS['wgLibravatarSize'])) {
                $params['size'] = (int) $GLOBALS['wgLibravatarSize'];
            }
        }
        $params['size'] = $parser->recursiveTagParse($params['size'], $frame);
        $sla->setSize($params['size']);
        $extra .= sprintf(' width="%d" height="%d"', $params['size'], $params['size']);
        // default attribute
        if (isset($params['default'])) {
            // ok
        } else {
            if (isset($GLOBALS['wgLibravatarDefault'])) {
                $params['default'] = $GLOBALS['wgLibravatarDefault'];
            }
        }
        if (isset($params['default'])) {
            $params['default'] = $parser->recursiveTagParse($params['default'], $frame);
            $sla->setDefault($params['default']);
        }
        // algorithm attribute
        if (isset($params['algorithm'])) {
            // ok
        } else {
            if (isset($GLOBALS['wgLibravatarAlgorithm'])) {
                $params['algorithm'] = $GLOBALS['wgLibravatarAlgorithm'];
            }
        }
        if (isset($params['algorithm'])) {
            $params['algorithm'] = $parser->recursiveTagParse($params['algorithm'], $frame);
            $sla->setAlgorithm($params['algorithm']);
        }
    } catch (Exception $e) {
        return sprintf('<span style="color:red">%s</span>', 'Libravatar error: ' . htmlspecialchars($e->getMessage()));
    }
    if (isset($params['title'])) {
        $extra .= sprintf(' title="%s"', htmlspecialchars($parser->recursiveTagParse($params['title'], $frame)));
    }
    if (isset($params['style'])) {
        $extra .= sprintf(' style="%s"', htmlspecialchars($parser->recursiveTagParse($params['style'], $frame)));
    }
    return sprintf('<img src="%s" alt="%s" width="%s"%s/>', htmlspecialchars($sla->getUrl($params['email'])), htmlspecialchars('Avatar of ' . str_replace(array('@', '.'), array(' at ', ' dot '), $params['email'])), htmlspecialchars($params['size']), $extra);
}