* Invision Power Services
* IP.Board v3.4.8
* Custom fields library
* Last Updated: $Date: 2013-10-14 17:55:18 -0400 (Mon, 14 Oct 2013) $
*
*
* @author $Author: rashbrook $
* @copyright (c) 2001 - 2009 Invision Power Services, Inc.
* @license http://www.invisionpower.com/company/standards.php#license
* @package IP.Board
* @subpackage Kernel
* @link http://www.invisionpower.com
* @since Thursday 8th May 2008 10:31
* @version $Revision: 12377 $
*
*/
abstract class customFieldPlugin
{
/**
* Custom field name
*
* @var string
*/
public $name = '';
/**
* Custom field title
*
* @var string
*/
public $title = '';
/**
* Custom field id
*
* @var integer
*/
public $id = 0;
/**
* Custom field attributes
*
* @var array
*/
public $attributes = array();
/**
* Custom field value
*
* @var array
*/
public $raw_data = array();
/**
* Custom field mode
*
* @var string
*/
public $mode = '';
/**
* Allows you to treat a custom field type as a string, returning the current value of $this->parsed
*
* @see getValue()
* @return @e string
*/
public function __tostring()
{
return $this->getValue();
}
/**
* Gets the value of the field (the current value of $this->parsed)
*
* @return @e string
*/
public function getValue()
{
if( is_array( $this->parsed ) )
{
return implode( ", ", $this->parsed );
}
else
{
return $this->parsed;
}
}
/**
* Creates an attribute string from an array
*
* @return @e string
*/
protected function _compileAttributes()
{
$_attributes = '';
if( is_array( $this->attributes ) )
{
foreach( $this->attributes as $k => $v )
{
$_attributes .= " {$k}='{$v}'";
}
}
return $_attributes;
}
/**
* Removes harmful html from display
*
* @var string String to make safe
* @return @e string
*/
protected function makeSafeForView( $t )
{
$t = IPSText::htmlspecialchars( $t );
$t = preg_replace("/&#([0-9]+);/s", "\\1;", $t );
$t = nl2br( $t );
return $t;
}
/**
* Format value for display in a form field
*
* @var string String to make safe
* @return @e string
*/
protected function makeSafeForForm( $t )
{
return IPSText::htmlspecialchars( $t );
}
}
/**
* Interface for custom fields
*
*/
interface interfaceCustomFieldPlugin
{
/**
* Format the field for display and store to $this->parsed
*
* @return @e void
*/
public function edit();
/**
* Format the field for viewing and store to $this->parsed
*
* @return @e void
*/
public function view();
}
/**
* Text input custom fields
*
*/
class customFieldText extends customFieldPlugin implements interfaceCustomFieldPlugin
{
/**
* Plugin type
*
* @var string
*/
public $plugin_type = '';
/**
* Value
*
* @var string
*/
public $value = '';
/**
* Parsed value
*
* @var string
*/
public $parsed = '';
/**
* CONSTRUCTOR
*
* @param array $field Array of field data { id, type, title, attributes, value }
* @param string $mode Set to 'view' or 'edit'
* @return @e void
*/
public function __construct( $field, $mode )
{
/* INI */
$this->value = $field['value'];
$this->plugin_type = $field['type'];
$this->name = 'field_' . $field['id'];
$this->id = $field['id'];
$this->title = isset( $field['title'] ) ? $field['title'] : '';
$this->attributes = isset( $field['attributes'] ) ? $field['attributes'] : '';
$this->raw_data = $field;
$this->mode = $mode;
if( $mode == 'edit' )
{
$this->edit();
}
else
{
$this->view();
}
}
/**
* Edit a field
*
* @return @e void
*/
public function edit()
{
/* Attributes */
$_attributes = $this->_compileAttributes();
/* Make Safe */
$this->value = $this->makeSafeForForm( $this->value );
if( $this->plugin_type == 'input' )
{
$this->parsed = "";
}
else
{
$this->parsed = "";
}
}
/**
* View a field
*
* @return @e void
*/
public function view()
{
/* Make Safe */
$this->value = $this->makeSafeForView( $this->value );
$this->parsed = $this->value;
}
}
/**
* Check boxes button custom fields
*
*/
class customFieldCbox extends customFieldPlugin implements interfaceCustomFieldPlugin
{
/**
* Plugin type
*
* @var string
*/
public $plugin_type = 'radio';
/**
* Value
*
* @var string
*/
public $value = '';
/**
* Parsed value
*
* @var string
*/
public $parsed = '';
/**
* Data
*
* @var string
*/
public $data = '';
/**
* CONSTRUCTOR
*
* @param array $field Array of field data { id, data, title, attributes, value }
* @param string $mode Set to 'view' or 'edit'
* @return @e void
*/
public function __construct( $field, $mode )
{
/* INI */
$this->data = $field['data'];
$this->value = $field['value'];
$this->name = 'field_' . $field['id'];
$this->id = $field['id'];
$this->title = isset($field['title']) ? $field['title'] : '';
$this->attributes = isset($field['attributes']) ? $field['attributes'] : '';
$this->raw_data = $field;
$this->mode = $mode;
if( $mode == 'edit' )
{
$this->edit();
}
else
{
$this->view();
}
}
/**
* Edit a field
*
* @return @e void
*/
public function edit()
{
/* INI */
$carray = explode( '|', $this->data );
$def_values = ( is_array( $this->value ) ) ? $this->value : explode( '|', $this->value );
$_attributes = $this->_compileAttributes();
#The first checkbox gets shifted over to the right due to the