[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/template/twig/extension/ -> username.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\template\twig\extension;
  15  
  16  class username extends \Twig_Extension
  17  {
  18      /**
  19       * Get the name of this extension
  20       *
  21       * @return string
  22       */
  23  	public function getName()
  24      {
  25          return 'username';
  26      }
  27  
  28      /**
  29       * Returns a list of global functions to add to the existing list.
  30       *
  31       * @return array An array of global functions
  32       */
  33  	public function getFunctions()
  34      {
  35          return array(
  36              new \Twig\TwigFunction('username', array($this, 'get_username')),
  37          );
  38      }
  39  
  40      /**
  41       * Get username details for placing into templates.
  42       *
  43       * How to use in a template:
  44       * - {{ username('mode', user_id, username, user_colour, guest_username, custom_profile_url) }}
  45       * - {{ username('mode', user_row, guest_username, custom_profile_url) }}
  46       * It's possible to provide the user identifier, name and colour separately,
  47       * or provide the entire user row at once as an array.
  48       *
  49       * The mode, user_id and username are required (separately or through a user row).
  50       * The other fields (user_colour|guest_username|custom_profile_url) are optional.
  51       *
  52       * @uses \get_username_string()
  53       *
  54       * @return string        A string based on what is wanted depending on $mode
  55       */
  56  	public function get_username()
  57      {
  58          $args = func_get_args();
  59  
  60          $mode = $args[0];
  61          $user = $args[1];
  62  
  63          // If the entire user row is provided
  64          if (is_array($user))
  65          {
  66              $user_id = isset($user['user_id']) ? $user['user_id'] : '';
  67              $username = isset($user['username']) ? $user['username'] : '';
  68              $user_colour = isset($user['user_colour']) ? $user['user_colour'] : '';
  69              $guest_username = isset($args[2]) ? $args[2] : false;
  70              $custom_profile_url = isset($args[3]) ? $args[3] : false;
  71          }
  72          else
  73          {
  74              // Options are provided separately
  75              $user_id = $user;
  76              $username = $args[2];
  77              $user_colour = isset($args[3]) ? $args[3] : '';
  78              $guest_username = isset($args[4]) ? $args[4] : false;
  79              $custom_profile_url = isset($args[5]) ? $args[5] : false;
  80          }
  81  
  82          return get_username_string($mode, $user_id, $username, $user_colour, $guest_username, $custom_profile_url);
  83      }
  84  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1