*/ class apptivo_ecommerce_payment_gateway { var $id; var $title; var $enabled; var $icon; var $description; var $plugin_id = 'apptivo_ecommerce_'; var $settings = array(); var $form_fields = array(); var $sanitized_fields = array(); function is_available() { if ($this->enabled=="yes") : return true; endif; return false; } function icon() { global $apptivo_ecommerce; if ($this->icon) : return ''.$this->title.''; endif; } function admin_options() {} function process_payment() {} function validate_fields() { return true; } public function process_admin_options() { $this->validate_settings_fields(); update_option( $this->plugin_id . $this->id . '_settings', $this->sanitized_fields ); } function init_settings () { if ( ! is_array( $this->settings ) ) { return; } $settings = array(); $existing_settings = get_option( $this->plugin_id . $this->id . '_settings' ); $defaults = array(); foreach ( $this->form_fields as $k => $v ) { if ( isset( $v['default'] ) ) { $defaults[$k] = $v['default']; } else { $defaults[$k] = ''; } } if ( ! $existing_settings ) { $existing_settings = $defaults; } else { // Prevent "undefined index" errors. foreach ( $existing_settings as $k => $v ) { if ( ! isset( $existing_settings[$k] ) ) { $existing_settings[$k] = $v; } } } $this->settings = $existing_settings; if ( isset( $this->settings['enabled'] ) && ( $this->settings['enabled'] == 'yes' ) ) { $this->enabled = 'yes'; } } // End init_settings() function generate_settings_html () { $html = ''; foreach ( $this->form_fields as $k => $v ) { if ( ! isset( $v['type'] ) || ( $v['type'] == '' ) ) { $v['type'] == 'text'; } // Default to "text" field type. if ( method_exists( $this, 'generate_' . $v['type'] . '_html' ) ) { $html .= $this->{'generate_' . $v['type'] . '_html'}( $k, $v ); } } echo $html; } function generate_text_html ( $key, $data ) { $html = ''; if ( isset( $data['title'] ) && $data['title'] != '' ) { $title = $data['title']; } $html .= '' . "\n"; $html .= '' . $title . '' . "\n"; $html .= '' . "\n"; $html .= '
' . $title . '' . "\n"; $html .= '
'; $html .= '' . "\n"; $html .= '' . "\n"; return $html; } function generate_textarea_html( $key, $data ) { $html = ''; if ( isset( $data['title'] ) && $data['title'] != '' ) { $title = $data['title']; } $html .= '' . "\n"; $html .= '' . $title . '' . "\n"; $html .= '' . "\n"; $html .= '
' . $title . '' . "\n"; $html .= '
'; $html .= '' . "\n"; $html .= '' . "\n"; return $html; } function generate_checkbox_html ( $key, $data ) { $html = ''; if ( isset( $data['title'] ) && $data['title'] != '' ) $title = $data['title']; if ( isset( $data['label'] ) && $data['label'] != '' ) $label = $data['label']; else $label = $data['title']; $html .= '' . "\n"; $html .= '' . $title . '' . "\n"; $html .= '' . "\n"; $html .= '
' . $title . '' . "\n"; $html .= '
' . "\n"; if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= '' . $data['description'] . '' . "\n"; } $html .= '
'; $html .= '' . "\n"; $html .= '' . "\n"; return $html; } function validate_settings_fields () { foreach ( $this->form_fields as $k => $v ) { if ( ! isset( $v['type'] ) || ( $v['type'] == '' ) ) { $v['type'] == 'text'; } // Default to "text" field type. if ( method_exists( $this, 'validate_' . $v['type'] . '_field' ) ) { $field = $this->{'validate_' . $v['type'] . '_field'}( $k ); $this->sanitized_fields[$k] = $field; } else { $this->sanitized_fields[$k] = $this->settings[$k]; } } } function validate_checkbox_field ( $key ) { $status = 'no'; if ( isset( $_POST[$this->plugin_id . $this->id . '_' . $key] ) && ( 1 == $_POST[$this->plugin_id . $this->id . '_' . $key] ) ) { $status = 'yes'; } return $status; } function validate_text_field ( $key ) { $text = (isset($this->settings[$key])) ? $this->settings[$key] : ''; if ( isset( $_POST[$this->plugin_id . $this->id . '_' . $key] ) ) { $text = esc_attr( apptivo_ecommerce_clean( $_POST[$this->plugin_id . $this->id . '_' . $key] ) ); } return $text; } function validate_textarea_field ( $key ) { $text = (isset($this->settings[$key])) ? $this->settings[$key] : ''; if ( isset( $_POST[$this->plugin_id . $this->id . '_' . $key] ) ) { $text = esc_attr( apptivo_ecommerce_clean( $_POST[$this->plugin_id . $this->id . '_' . $key] ) ); } return $text; } }