Source for file user.php

Documentation is available at user.php

  1. <?php
  2. /**
  3.  * @package    FrameworkOnFramework
  4.  * @subpackage form
  5.  * @copyright  Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license    GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. // Protect from unauthorized access
  9. defined('_JEXEC'or die;
  10.  
  11. if (!class_exists('JFormFieldUser'))
  12. {
  13.     require_once JPATH_LIBRARIES '/cms/form/field/user.php';
  14. }
  15.  
  16. /**
  17.  * Form Field class for the FOF framework
  18.  * A user selection box / display field
  19.  *
  20.  * @package  FrameworkOnFramework
  21.  * @since    2.0
  22.  */
  23. class FOFFormFieldUser extends JFormFieldUser implements FOFFormField
  24. {
  25.     protected $static;
  26.  
  27.     protected $repeatable;
  28.     
  29.     /** @var   FOFTable  The item being rendered in a repeatable form field */
  30.     public $item;
  31.     
  32.     /** @var int A monotonically increasing number, denoting the row number in a repeatable view */
  33.     public $rowid;
  34.  
  35.     /**
  36.      * Method to get certain otherwise inaccessible properties from the form field object.
  37.      *
  38.      * @param   string  $name  The property name for which to the the value.
  39.      *
  40.      * @return  mixed  The property value or null.
  41.      *
  42.      * @since   2.0
  43.      */
  44.     public function __get($name)
  45.     {
  46.         switch ($name)
  47.         {
  48.             case 'static':
  49.                 if (empty($this->static))
  50.                 {
  51.                     $this->static = $this->getStatic();
  52.                 }
  53.  
  54.                 return $this->static;
  55.                 break;
  56.  
  57.             case 'repeatable':
  58.                 if (empty($this->repeatable))
  59.                 {
  60.                     $this->repeatable = $this->getRepeatable();
  61.                 }
  62.  
  63.                 return $this->static;
  64.                 break;
  65.  
  66.             default:
  67.                 return parent::__get($name);
  68.         }
  69.     }
  70.  
  71.     /**
  72.      * Get the rendering of this field type for static display, e.g. in a single
  73.      * item view (typically a "read" task).
  74.      *
  75.      * @since 2.0
  76.      *
  77.      * @return  string  The field HTML
  78.      */
  79.     public function getStatic()
  80.     {
  81.         // Initialise
  82.         $show_username true;
  83.         $show_email    false;
  84.         $show_name     false;
  85.         $show_id       false;
  86.         $class         '';
  87.  
  88.         // Get the field parameters
  89.         if ($this->element['class'])
  90.         {
  91.             $class ' class="' . (string) $this->element['class''"';
  92.         }
  93.  
  94.         if ($this->element['show_username'== 'false')
  95.         {
  96.             $show_username false;
  97.         }
  98.  
  99.         if ($this->element['show_email'== 'true')
  100.         {
  101.             $show_email true;
  102.         }
  103.  
  104.         if ($this->element['show_name'== 'true')
  105.         {
  106.             $show_name true;
  107.         }
  108.  
  109.         if ($this->element['show_id'== 'true')
  110.         {
  111.             $show_id true;
  112.         }
  113.  
  114.         // Get the user record
  115.         $user JFactory::getUser($this->value);
  116.  
  117.         // Render the HTML
  118.         $html '<div id="' $this->id . '" ' $class '>';
  119.  
  120.         if ($show_username)
  121.         {
  122.             $html .= '<span class="fof-userfield-username">' $user->username '</span>';
  123.         }
  124.  
  125.         if ($show_id)
  126.         {
  127.             $html .= '<span class="fof-userfield-id">' $user->id '</span>';
  128.         }
  129.  
  130.         if ($show_name)
  131.         {
  132.             $html .= '<span class="fof-userfield-name">' $user->name '</span>';
  133.         }
  134.  
  135.         if ($show_email)
  136.         {
  137.             $html .= '<span class="fof-userfield-email">' $user->email '</span>';
  138.         }
  139.  
  140.         $html .= '</div>';
  141.  
  142.         return $html;
  143.     }
  144.  
  145.     /**
  146.      * Get the rendering of this field type for a repeatable (grid) display,
  147.      * e.g. in a view listing many item (typically a "browse" task)
  148.      *
  149.      * @since 2.0
  150.      *
  151.      * @return  string  The field HTML
  152.      */
  153.     public function getRepeatable()
  154.     {
  155.         // Initialise
  156.         $show_username true;
  157.         $show_email    true;
  158.         $show_name     true;
  159.         $show_id       true;
  160.         $show_avatar   true;
  161.         $show_link     false;
  162.         $link_url      null;
  163.         $avatar_method 'gravatar';
  164.         $avatar_size   64;
  165.         $class         '';
  166.  
  167.         // Get the user record
  168.         $user JFactory::getUser($this->value);
  169.  
  170.         // Get the field parameters
  171.         if ($this->element['class'])
  172.         {
  173.             $class ' class="' . (string) $this->element['class''"';
  174.         }
  175.  
  176.         if ($this->element['show_username'== 'false')
  177.         {
  178.             $show_username false;
  179.         }
  180.  
  181.         if ($this->element['show_email'== 'false')
  182.         {
  183.             $show_email false;
  184.         }
  185.  
  186.         if ($this->element['show_name'== 'false')
  187.         {
  188.             $show_name false;
  189.         }
  190.  
  191.         if ($this->element['show_id'== 'false')
  192.         {
  193.             $show_id false;
  194.         }
  195.  
  196.         if ($this->element['show_avatar'== 'false')
  197.         {
  198.             $show_avatar false;
  199.         }
  200.  
  201.         if ($this->element['avatar_method'])
  202.         {
  203.             $avatar_method strtolower($this->element['avatar_method']);
  204.         }
  205.  
  206.         if ($this->element['avatar_size'])
  207.         {
  208.             $avatar_size $this->element['avatar_size'];
  209.         }
  210.  
  211.         if ($this->element['show_link'== 'true')
  212.         {
  213.             $show_link true;
  214.         }
  215.  
  216.         if ($this->element['link_url'])
  217.         {
  218.             $link_url $this->element['link_url'];
  219.         }
  220.         else
  221.         {
  222.             if (FOFPlatform::getInstance()->isBackend())
  223.             {
  224.                 // If no link is defined in the back-end, assume the user edit
  225.                 // link in the User Manager component
  226.                 $link_url 'index.php?option=com_users&task=user.edit&id=[USER:ID]';
  227.             }
  228.             else
  229.             {
  230.                 // If no link is defined in the front-end, we can't create a
  231.                 // default link. Therefore, show no link.
  232.                 $show_link false;
  233.             }
  234.         }
  235.  
  236.         // Post-process the link URL
  237.         if ($show_link)
  238.         {
  239.             $replacements array(
  240.                 '[USER:ID]'             => $user->id,
  241.                 '[USER:USERNAME]'     => $user->username,
  242.                 '[USER:EMAIL]'         => $user->email,
  243.                 '[USER:NAME]'         => $user->name,
  244.             );
  245.  
  246.             foreach ($replacements as $key => $value)
  247.             {
  248.                 $link_url str_replace($key$value$link_url);
  249.             }
  250.         }
  251.  
  252.         // Get the avatar image, if necessary
  253.         if ($show_avatar)
  254.         {
  255.             $avatar_url '';
  256.  
  257.             if ($avatar_method == 'plugin')
  258.             {
  259.                 // Use the user plugins to get an avatar
  260.                 FOFPlatform::getInstance()->importPlugin('user');
  261.                 $jResponse FOFPlatform::getInstance()->runPlugins('onUserAvatar'array($user$avatar_size));
  262.  
  263.                 if (!empty($jResponse))
  264.                 {
  265.                     foreach ($jResponse as $response)
  266.                     {
  267.                         if ($response)
  268.                         {
  269.                             $avatar_url $response;
  270.                         }
  271.                     }
  272.                 }
  273.  
  274.                 if (empty($avatar_url))
  275.                 {
  276.                     $show_avatar false;
  277.                 }
  278.             }
  279.             else
  280.             {
  281.                 // Fall back to the Gravatar method
  282.                 $md5 md5($user->email);
  283.  
  284.                 if (FOFPlatform::getInstance()->isCli())
  285.                 {
  286.                     $scheme 'http';
  287.                 }
  288.                 else
  289.                 {
  290.                     $scheme JURI::getInstance()->getScheme();
  291.                 }
  292.  
  293.                 if ($scheme == 'http')
  294.                 {
  295.                     $avatar_url 'http://www.gravatar.com/avatar/' $md5 '.jpg?s='
  296.                         . $avatar_size '&d=mm';
  297.                 }
  298.                 else
  299.                 {
  300.                     $avatar_url 'https://secure.gravatar.com/avatar/' $md5 '.jpg?s='
  301.                         . $avatar_size '&d=mm';
  302.                 }
  303.             }
  304.         }
  305.  
  306.         // Generate the HTML
  307.         $html '<div id="' $this->id . '" ' $class '>';
  308.  
  309.         if ($show_avatar)
  310.         {
  311.             $html .= '<img src="' $avatar_url '" align="left" class="fof-usersfield-avatar" />';
  312.         }
  313.  
  314.         if ($show_link)
  315.         {
  316.             $html .= '<a href="' $link_url '">';
  317.         }
  318.  
  319.         if ($show_username)
  320.         {
  321.             $html .= '<span class="fof-usersfield-username">' $user->username
  322.                 . '</span>';
  323.         }
  324.  
  325.         if ($show_id)
  326.         {
  327.             $html .= '<span class="fof-usersfield-id">' $user->id
  328.                 . '</span>';
  329.         }
  330.  
  331.         if ($show_name)
  332.         {
  333.             $html .= '<span class="fof-usersfield-name">' $user->name
  334.                 . '</span>';
  335.         }
  336.  
  337.         if ($show_email)
  338.         {
  339.             $html .= '<span class="fof-usersfield-email">' $user->email
  340.                 . '</span>';
  341.         }
  342.  
  343.         if ($show_link)
  344.         {
  345.             $html .= '</a>';
  346.         }
  347.  
  348.         $html .= '</div>';
  349.  
  350.         return $html;
  351.     }
  352. }

Documentation generated on Tue, 19 Nov 2013 15:16:30 +0100 by phpDocumentor 1.4.3