Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

gravatar.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 5.29 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\avatar\driver;
 015   
 016  /**
 017  * Handles avatars hosted at gravatar.com
 018  */
 019  class gravatar extends \phpbb\avatar\driver\driver
 020  {
 021      /**
 022      * The URL for the gravatar service
 023      */
 024      const GRAVATAR_URL = '//secure.gravatar.com/avatar/';
 025   
 026      /**
 027      * {@inheritdoc}
 028      */
 029      public function get_data($row)
 030      {
 031          return array(
 032              'src' => $row['avatar'],
 033              'width' => $row['avatar_width'],
 034              'height' => $row['avatar_height'],
 035          );
 036      }
 037   
 038      /**
 039      * {@inheritdoc}
 040      */
 041      public function get_custom_html($user, $row, $alt = '')
 042      {
 043          return '<img src="' . $this->get_gravatar_url($row) . '" ' .
 044              ($row['avatar_width'] ? ('width="' . $row['avatar_width'] . '" ') : '') .
 045              ($row['avatar_height'] ? ('height="' . $row['avatar_height'] . '" ') : '') .
 046              'alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
 047      }
 048   
 049      /**
 050      * {@inheritdoc}
 051      */
 052      public function prepare_form($request, $template, $user, $row, &$error)
 053      {
 054          $template->assign_vars(array(
 055              'AVATAR_GRAVATAR_WIDTH' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_width']) ? $row['avatar_width'] : $request->variable('avatar_gravatar_width', 0),
 056              'AVATAR_GRAVATAR_HEIGHT' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar_height']) ? $row['avatar_height'] : $request->variable('avatar_gravatar_width', 0),
 057              'AVATAR_GRAVATAR_EMAIL' => (($row['avatar_type'] == $this->get_name() || $row['avatar_type'] == 'gravatar') && $row['avatar']) ? $row['avatar'] : '',
 058          ));
 059   
 060          return true;
 061      }
 062   
 063      /**
 064      * {@inheritdoc}
 065      */
 066      public function process_form($request, $template, $user, $row, &$error)
 067      {
 068          $row['avatar'] = $request->variable('avatar_gravatar_email', '');
 069          $row['avatar_width'] = $request->variable('avatar_gravatar_width', 0);
 070          $row['avatar_height'] = $request->variable('avatar_gravatar_height', 0);
 071   
 072          if (empty($row['avatar']))
 073          {
 074              return false;
 075          }
 076   
 077          if (!function_exists('validate_data'))
 078          {
 079              require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
 080          }
 081   
 082          $validate_array = validate_data(
 083              array(
 084                  'email' => $row['avatar'],
 085              ),
 086              array(
 087                  'email' => array(
 088                      array('string', false, 6, 60),
 089                      array('email'),
 090                  ),
 091              )
 092          );
 093   
 094          $error = array_merge($error, $validate_array);
 095   
 096          if (!empty($error))
 097          {
 098              return false;
 099          }
 100   
 101          // Make sure getimagesize works...
 102          if (function_exists('getimagesize') && ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0))
 103          {
 104              /**
 105              * default to the minimum of the maximum allowed avatar size if the size
 106              * is not or only partially entered
 107              */
 108              $row['avatar_width'] = $row['avatar_height'] = min($this->config['avatar_max_width'], $this->config['avatar_max_height']);
 109              $url = $this->get_gravatar_url($row);
 110   
 111              if (($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0) && (($image_data = getimagesize($url)) === false))
 112              {
 113                  $error[] = 'UNABLE_GET_IMAGE_SIZE';
 114                  return false;
 115              }
 116   
 117              if (!empty($image_data) && ($image_data[0] <= 0 || $image_data[1] <= 0))
 118              {
 119                  $error[] = 'AVATAR_NO_SIZE';
 120                  return false;
 121              }
 122   
 123              $row['avatar_width'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_width'] : $image_data[0];
 124              $row['avatar_height'] = ($row['avatar_width'] && $row['avatar_height']) ? $row['avatar_height'] : $image_data[1];
 125          }
 126   
 127          if ($row['avatar_width'] <= 0 || $row['avatar_height'] <= 0)
 128          {
 129              $error[] = 'AVATAR_NO_SIZE';
 130              return false;
 131          }
 132   
 133          if ($this->config['avatar_max_width'] || $this->config['avatar_max_height'])
 134          {
 135              if ($row['avatar_width'] > $this->config['avatar_max_width'] || $row['avatar_height'] > $this->config['avatar_max_height'])
 136              {
 137                  $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $row['avatar_width'], $row['avatar_height']);
 138                  return false;
 139              }
 140          }
 141   
 142          if ($this->config['avatar_min_width'] || $this->config['avatar_min_height'])
 143          {
 144              if ($row['avatar_width'] < $this->config['avatar_min_width'] || $row['avatar_height'] < $this->config['avatar_min_height'])
 145              {
 146                  $error[] = array('AVATAR_WRONG_SIZE', $this->config['avatar_min_width'], $this->config['avatar_min_height'], $this->config['avatar_max_width'], $this->config['avatar_max_height'], $row['avatar_width'], $row['avatar_height']);
 147                  return false;
 148              }
 149          }
 150   
 151          return array(
 152              'avatar' => $row['avatar'],
 153              'avatar_width' => $row['avatar_width'],
 154              'avatar_height' => $row['avatar_height'],
 155          );
 156      }
 157   
 158      /**
 159      * {@inheritdoc}
 160      */
 161      public function get_template_name()
 162      {
 163          return 'ucp_avatar_options_gravatar.html';
 164      }
 165   
 166      /**
 167      * Build gravatar URL for output on page
 168      *
 169      * @param array $row User data or group data that has been cleaned with
 170      *        \phpbb\avatar\manager::clean_row
 171      * @return string Gravatar URL
 172      */
 173      protected function get_gravatar_url($row)
 174      {
 175          $url = self::GRAVATAR_URL;
 176          $url .=  md5(strtolower(trim($row['avatar'])));
 177   
 178          if ($row['avatar_width'] || $row['avatar_height'])
 179          {
 180              $url .= '?s=' . max($row['avatar_width'], $row['avatar_height']);
 181          }
 182   
 183          return $url;
 184      }
 185  }
 186