Source for file text.php

Documentation is available at text.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.  
  12. /**
  13.  * Form Field class for the FOF framework
  14.  * Supports a one line text field.
  15.  *
  16.  * @package  FrameworkOnFramework
  17.  * @since    2.0
  18.  */
  19. class FOFFormFieldText extends JFormFieldText implements FOFFormField
  20. {
  21.     protected $static;
  22.  
  23.     protected $repeatable;
  24.     
  25.     /** @var   FOFTable  The item being rendered in a repeatable form field */
  26.     public $item;
  27.     
  28.     /** @var int A monotonically increasing number, denoting the row number in a repeatable view */
  29.     public $rowid;
  30.  
  31.     /**
  32.      * Method to get certain otherwise inaccessible properties from the form field object.
  33.      *
  34.      * @param   string  $name  The property name for which to the the value.
  35.      *
  36.      * @return  mixed  The property value or null.
  37.      *
  38.      * @since   2.0
  39.      */
  40.     public function __get($name)
  41.     {
  42.         switch ($name)
  43.         {
  44.             case 'static':
  45.                 if (empty($this->static))
  46.                 {
  47.                     $this->static = $this->getStatic();
  48.                 }
  49.  
  50.                 return $this->static;
  51.                 break;
  52.  
  53.             case 'repeatable':
  54.                 if (empty($this->repeatable))
  55.                 {
  56.                     $this->repeatable = $this->getRepeatable();
  57.                 }
  58.  
  59.                 return $this->static;
  60.                 break;
  61.  
  62.             default:
  63.                 return parent::__get($name);
  64.         }
  65.     }
  66.  
  67.     /**
  68.      * Get the rendering of this field type for static display, e.g. in a single
  69.      * item view (typically a "read" task).
  70.      *
  71.      * @since 2.0
  72.      *
  73.      * @return  string  The field HTML
  74.      */
  75.     public function getStatic()
  76.     {
  77.         $class $this->element['class'' class="' . (string) $this->element['class''"' '';
  78.         $empty_replacement '';
  79.  
  80.         if ($this->element['empty_replacement'])
  81.         {
  82.             $empty_replacement = (string) $this->element['empty_replacement'];
  83.         }
  84.  
  85.         if (!empty($empty_replacement&& empty($this->value))
  86.         {
  87.             $this->value = JText::_($empty_replacement);
  88.         }
  89.  
  90.         return '<span id="' $this->id . '" ' $class '>' .
  91.             htmlspecialchars($this->valueENT_COMPAT'UTF-8'.
  92.             '</span>';
  93.     }
  94.  
  95.     /**
  96.      * Get the rendering of this field type for a repeatable (grid) display,
  97.      * e.g. in a view listing many item (typically a "browse" task)
  98.      *
  99.      * @since 2.0
  100.      *
  101.      * @return  string  The field HTML
  102.      */
  103.     public function getRepeatable()
  104.     {
  105.         // Initialise
  106.         $class                    $this->id;
  107.         $format_string            '';
  108.         $format_if_not_empty    false;
  109.         $parse_value            false;
  110.         $show_link                false;
  111.         $link_url                '';
  112.         $empty_replacement        '';
  113.  
  114.         // Get field parameters
  115.         if ($this->element['class'])
  116.         {
  117.             $class = (string) $this->element['class'];
  118.         }
  119.  
  120.         if ($this->element['format'])
  121.         {
  122.             $format_string = (string) $this->element['format'];
  123.         }
  124.  
  125.         if ($this->element['show_link'== 'true')
  126.         {
  127.             $show_link true;
  128.         }
  129.  
  130.         if ($this->element['format_if_not_empty'== 'true')
  131.         {
  132.             $format_if_not_empty true;
  133.         }
  134.  
  135.         if ($this->element['parse_value'== 'true')
  136.         {
  137.             $parse_value true;
  138.         }
  139.  
  140.         if ($this->element['url'])
  141.         {
  142.             $link_url $this->element['url'];
  143.         }
  144.         else
  145.         {
  146.             $show_link false;
  147.         }
  148.  
  149.         if ($show_link && ($this->item instanceof FOFTable))
  150.         {
  151.             $link_url $this->parseFieldTags($link_url);
  152.         }
  153.         else
  154.         {
  155.             $show_link false;
  156.         }
  157.  
  158.         if ($this->element['empty_replacement'])
  159.         {
  160.             $empty_replacement = (string) $this->element['empty_replacement'];
  161.         }
  162.  
  163.         // Get the (optionally formatted) value
  164.         $value $this->value;
  165.  
  166.         if (!empty($empty_replacement&& empty($this->value))
  167.         {
  168.             $value JText::_($empty_replacement);
  169.         }
  170.  
  171.         if ($parse_value)
  172.         {
  173.             $value $this->parseFieldTags($value);
  174.         }
  175.  
  176.         if (!empty($format_string&& (!$format_if_not_empty || ($format_if_not_empty && !empty($this->value))))
  177.         {
  178.             $format_string $this->parseFieldTags($format_string);
  179.             $value sprintf($format_string$value);
  180.         }
  181.         else
  182.         {
  183.             $value htmlspecialchars($valueENT_COMPAT'UTF-8');
  184.         }
  185.  
  186.         // Create the HTML
  187.         $html '<span class="' $class '">';
  188.  
  189.         if ($show_link)
  190.         {
  191.             $html .= '<a href="' $link_url '">';
  192.         }
  193.  
  194.         $html .= $value;
  195.  
  196.         if ($show_link)
  197.         {
  198.             $html .= '</a>';
  199.         }
  200.  
  201.         $html .= '</span>';
  202.  
  203.         return $html;
  204.     }
  205.  
  206.     /**
  207.      * Replace string with tags that reference fields
  208.      *
  209.      * @param   string  $text  Text to process
  210.      *
  211.      * @return  string         Text with tags replace
  212.      */
  213.     protected function parseFieldTags($text)
  214.     {
  215.         $ret $text;
  216.  
  217.         // Replace [ITEM:ID] in the URL with the item's key value (usually:
  218.         // the auto-incrementing numeric ID)
  219.         $keyfield $this->item->getKeyName();
  220.         $replace  $this->item->$keyfield;
  221.         $ret str_replace('[ITEM:ID]'$replace$ret);
  222.  
  223.         // Replace other field variables in the URL
  224.         $fields $this->item->getFields();
  225.  
  226.         foreach ($fields as $fielddata)
  227.         {
  228.             $fieldname $fielddata->Field;
  229.  
  230.             if (empty($fieldname))
  231.             {
  232.                 $fieldname $fielddata->column_name;
  233.             }
  234.  
  235.             $search    '[ITEM:' strtoupper($fieldname']';
  236.             $replace   $this->item->$fieldname;
  237.             $ret  str_replace($search$replace$ret);
  238.         }
  239.  
  240.         return $ret;
  241.     }
  242. }

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