setAttributes( $attributes );
}
}
public function setAttributes( $attributes )
{
if( ! is_array( $attributes ) ){
$attributes = array( $attributes );
}
$this->attributes = $this->sanitizeAttributes( $attributes );
}
protected function getAttribute( $key ){
if( isset( $this->attributes[ $key ] ) ){
return $this->attributes[ $key ];
}
return false;
}
public function getAttributes()
{
return $this->attributes;
}
protected function sanitizeAttributes( $attributes )
{
$sanitizedAttributes = [];
$attributes = array_change_key_case( $attributes, CASE_LOWER );
foreach ( $attributes as $key => $value ){
if( in_array( $key, $this->validAttributes ) ){
$sanitizedAttributes[ $key ] = $value;
}
if( mb_strpos( $key, 'data-' ) !== false ){
$sanitizedAttributes[ $key ] = $value;
}
}
return $sanitizedAttributes;
}
protected function renderAttributes( $skip = [] )
{
$html = '';
foreach ( (array) $this->attributes as $key => $value ) {
// do not sanitize attribute name because we already validated them
if( in_array( $key, $skip ) ){
continue;
}
$html .= ' ' . esc_attr($key) . '="' . esc_attr( $value ).'"';
}
return $html;
}
}
class Checkbox extends Input {
public function render(){
$html = 'renderAttributes( array('placeholder') );
$html .= checked('yes', $this->getAttribute('value'), false );
$html .= ' />';
if( $this->getAttribute('placeholder') ){
$html .= ''.esc_html( $this->getAttribute('placeholder') ).'';
}
return apply_filters( 'wpc_input_type_checkbox', $html, $this->getAttributes() );
}
}
class File extends Input {
public function render(){
$html = 'renderAttributes();
$html .= ' />';
return apply_filters( 'wpc_input_type_file', $html, $this->getAttributes() );
}
}
class Hidden extends Input {
public function render(){
$html = 'renderAttributes();
$html .= ' />'."\r\n";
return apply_filters( 'wpc_input_type_hidden', $html, $this->getAttributes() );
}
}
class Image extends Input {
}
class Password extends Input {
public function render(){
$html = 'renderAttributes();
$html .= ' />'."\r\n";
return apply_filters( 'wpc_input_type_password', $html, $this->getAttributes() );
}
}
class Submit extends Input {
public function __construct($options, $validation = []){
if(!is_array($options)){
$o = [];
$o['value'] = $options;
$o['name'] = 'submit';
$o['id'] = 'submit';
} else {
$o = $options;
}
parent::__construct($o, $validation);
}
public function render(){
$class = 'class';
if(!$this->$class){
$class = ' class="submit"';
}
$html = ' renderAttributes();
$html .= ' value="'.$this->value.'"';
$html .= ' />';
return apply_filters( 'wpc_input_type_submit', $html, $this->getAttributes() );
}
}
class Text extends Input {
public function render(){
$html = 'renderAttributes();
$html .= ' />'."\r\n";
return apply_filters( 'wpc_input_type_text', $html, $this->getAttributes() );
}
}
class Radio extends Input {
public function render(){
$html = '
';
return apply_filters( 'wpc_input_type_radio', $html, $this->getAttributes() );
}
}
class Select extends Input {
public function render(){
$html = ''."\r\n";
return apply_filters( 'wpc_input_type_select', $html, $this->getAttributes() );
}
private function renderDropdown( $options, $selected, $disabled = [] )
{
$html = '';
$option_group = false;
// For multidimensional array
foreach ( $options as $key => $option ){
if( isset( $option['group_label'] ) ){
$option_group = true;
$html .= ''."\r\n";
}
}
// In case for simple options array
if( ! $option_group ){
$html .= $this->renderOptions( $options, $selected, $disabled );
}
return $html;
}
private function renderOptions( $options, $selected = '', $disabled = [] ){
if( ! $options || ! is_array( $options ) ){
return false;
}
$html = '';
foreach ( $options as $value => $label ){
$html .= $this->renderOption( $label, $value, $selected, $disabled );
}
return $html;
}
private function renderOption( $label, $value, $selected = '', $disabled = [] ){
$attributes = '';
$attr = apply_filters( 'wpc_dropdown_option_attr', $label );
$label = flrt_extract_var( $attr, 'label' );
foreach ( (array) $attr as $key => $val ){
$attributes .= $key .'="'.$val.'" ';
}
$html = ''."\r\n";
return $html;
}
}
class Textarea extends Input {
public function render(){
$html = ''."\r\n";
return apply_filters( 'wpc_input_type_textarea', $html, $this->getAttributes() );
}
}
class Wpeditor extends Input {
public function render(){
$settings = array(
'textarea_rows' => $this->getAttribute('textarea_rows'),
'textarea_name' => $this->getAttribute('name')
);
wp_editor( $this->getAttribute('value' ), $this->getAttribute('id' ), $settings );
}
}
class inProButton extends Input {
public function render(){
return flrt_unlock_in_pro();
}
}
class RangeList extends Input {
public function render(){
$html = '';
$disabled = '';
$range_list = $this->getAttribute('value');
if(!empty($range_list)){
foreach ($range_list as $key => $value) {
$html .= '';
}
$total = (int) (defined('FLRT_RANGE_LIST_LIMIT') && FLRT_RANGE_LIST_LIMIT ) ? FLRT_RANGE_LIST_LIMIT : 20;
if(count($range_list) > $total){
$disabled = ' disabled';
}
}
if(!empty($this->getAttribute('button_name'))){
if(!empty($this->getAttribute('class' ))){
$id = ' id="'.$this->getAttribute('id' ).'"';
$class = ' class="'.$this->getAttribute('class' ).' button"';
}
$html .= ''."\r\n";
}
return apply_filters( 'wpc_input_type_button', $html, $this->getAttributes() );
}
}