* Invision Power Services * IP.Board v3.2.3 * Custom fields library * Last Updated: $Date: 2011-05-07 17:35:35 -0400 (Sat, 07 May 2011) $ * * * @author $Author: rtissier $ * @copyright (c) 2001 - 2009 Invision Power Services, Inc. * @license This is NULLED! * @package IP.Board * @subpackage Kernel * @link http://hatynka.in * @since Thursday 8th May 2008 10:31 * @version $Revision: 8670 $ * */ 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 * * @return string Current value of $this->parsed */ public function __tostring() { return $this->getValue(); } /** * Gets the value of the field * * @return string Current value of $this->parsed */ public function getValue() { if( is_array( $this->parsed ) ) { return implode( ", ", $this->parsed ); } else { return $this->parsed; } } /** * Creates an attribute string from an array * * @return 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 string */ protected function makeSafeForView( $t ) { $t = htmlspecialchars( $t, ENT_QUOTES ); $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 string */ protected function makeSafeForForm( $t ) { return str_replace( "'", "'", $t ); } } /** * Interface for custom fields * */ interface interfaceCustomFieldPlugin { /** * Editing a custom field * * @return @e void */ public function edit(); /** * Viewing a custom field * * @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, data, value, class } * @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, value, class } * @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