1 <?php
  2 /**
  3  * @package    FrameworkOnFramework
  4  * @subpackage form
  5  * @copyright   Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / 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('FOF_INCLUDED') or die;
 10 
 11 JFormHelper::loadFieldClass('text');
 12 
 13 /**
 14  * Form Field class for the FOF framework
 15  * Supports a button input.
 16  *
 17  * @package  FrameworkOnFramework
 18  * @since    2.0
 19  */
 20 class FOFFormFieldButton extends FOFFormFieldText implements FOFFormField
 21 {
 22     protected $static;
 23 
 24     protected $repeatable;
 25 
 26     /**
 27      * Method to get certain otherwise inaccessible properties from the form field object.
 28      *
 29      * @param   string  $name  The property name for which to the the value.
 30      *
 31      * @return  mixed  The property value or null.
 32      *
 33      * @since   2.0
 34      */
 35     public function __get($name)
 36     {
 37         switch ($name)
 38         {
 39             case 'static':
 40                 if (empty($this->static))
 41                 {
 42                     $this->static = $this->getStatic();
 43                 }
 44 
 45                 return $this->static;
 46                 break;
 47 
 48             case 'repeatable':
 49                 if (empty($this->repeatable))
 50                 {
 51                     $this->repeatable = $this->getRepeatable();
 52                 }
 53 
 54                 return $this->repeatable;
 55                 break;
 56 
 57             default:
 58                 return parent::__get($name);
 59         }
 60     }
 61 
 62     /**
 63      * Get the rendering of this field type for static display, e.g. in a single
 64      * item view (typically a "read" task).
 65      *
 66      * @since 2.0
 67      *
 68      * @return  string  The field HTML
 69      */
 70     public function getStatic()
 71     {
 72         return $this->getInput();
 73     }
 74 
 75     /**
 76      * Get the rendering of this field type for a repeatable (grid) display,
 77      * e.g. in a view listing many item (typically a "browse" task)
 78      *
 79      * @since 2.0
 80      *
 81      * @return  string  The field HTML
 82      */
 83     public function getRepeatable()
 84     {
 85         return $this->getInput();
 86     }
 87 
 88     /**
 89      * Get the rendering of this field type for static display, e.g. in a single
 90      * item view (typically a "read" task).
 91      *
 92      * @since 2.0
 93      *
 94      * @return  string  The field HTML
 95      */
 96     public function getInput()
 97     {
 98         $this->label = '';
 99 
100         $allowedElement = array('button', 'a');
101 
102         if (in_array($this->element['htmlelement'], $allowedElement))
103             $type = $this->element['htmlelement'];
104         else
105             $type = 'button';
106 
107         $text    = $this->element['text'];
108         $class   = $this->element['class'] ? (string) $this->element['class'] : '';
109         $icon    = $this->element['icon'] ? (string) $this->element['icon'] : '';
110         $onclick = $this->element['onclick'] ? 'onclick="' . (string) $this->element['onclick'] . '"' : '';
111         $url     = $this->element['url'] ? 'href="' . $this->parseFieldTags((string) $this->element['url']) . '"' : '';
112         $title   = $this->element['title'] ? 'title="' . JText::_((string) $this->element['title']) . '"' : '';
113 
114         $this->value = JText::_($text);
115 
116         if ($icon)
117         {
118             $icon = '<span class="icon ' . $icon . '"></span>';
119         }
120 
121         return '<' . $type . ' id="' . $this->id . '" class="btn ' . $class . '" ' .
122             $onclick . $url . $title . '>' .
123             $icon .
124             htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') .
125             '</' . $type . '>';
126     }
127 
128     /**
129      * Method to get the field title.
130      *
131      * @return  string  The field title.
132      */
133     protected function getTitle()
134     {
135         return null;
136     }
137 }
138