*/
abstract class Rex_Feed_Abstract_Template {
/**
* The Feed Attributes.
*
* @since 1.0.0
* @access protected
* @var Rex_Feed_Abstract_Template attributes Feed attributes.
*/
protected $attributes;
/**
* WooCommerce Product Meta Keys.
*
* @since 1.0.0
* @access protected
* @var Rex_Feed_Abstract_Template attributes Feed attributes.
*/
protected $product_meta_keys;
/**
* The Feed Template Mappings Attributes and associated value and other constraints.
*
* @since 1.0.0
* @access protected
* @var Rex_Feed_Abstract_Template template_mappings Feed attributes mapping for template genaration.
*/
protected $template_mappings;
/**
* Data Sanitization options
*
* @since 1.0.0
* @access protected
* @var Rex_Feed_Abstract_Template template_mappings Feed attributes mapping for template genaration.
*/
protected $sanitization_options;
/**
* Set the plugin atts and mapping.
*
* @since 1.0.0
* @param bool $feed_rules
*/
public function __construct( $feed_rules = false ){
$this->init_atts();
$this->init_template_mappings( $feed_rules );
// $this->init_product_meta_keys();
$this->init_sanitization_options();
}
/**
* Return the attributes
*
* @since 1.0.0
*/
public function getAttributes(){
return $this->attributes;
}
/**
* Return the template_mappings
*
* @since 1.0.0
*/
public function getTemplateMappings(){
return $this->template_mappings;
}
/**
* @desc Retrieve markups for product dropdown
*
* @since 1.0.0
* @param $selected
* @return bool|string|string[]
*/
public function printProductAttributes( $selected = '' ) {
$product_attribute_dropdown = $this->get_feed_cached_dropdown( 'product_attributes_dropdown', $selected );
if ( false === $product_attribute_dropdown ) {
$product_attributes = Rex_Feed_Attributes::get_attributes();
return $this->make_cache_dropdown( 'product_attributes_dropdown', $product_attributes , $selected );
}
return $product_attribute_dropdown;
}
/**
*
* @param $key
* @param string $selected
* @return bool|string|string[]
*/
private function get_feed_cached_dropdown( $key, $selected = '' ) {
$product_attribute_dropdown = wpfm_get_cached_data( $key );
if ( $selected && strpos( $product_attribute_dropdown, "value='" . esc_attr($selected) . "'" ) !== false ) {
$product_attribute_dropdown = str_replace( "value='" . esc_attr($selected) . "'", 'value="' . esc_attr($selected) . '"' . ' selected', $product_attribute_dropdown );
}
return empty( $product_attribute_dropdown ) ? false : $product_attribute_dropdown;
}
/**
* make cached dropdown list
* for future use
*
* @param $key
* @param $items
* @param string $selected
* @return string|string[]
*/
private function make_cache_dropdown( $key, $items, $selected = '' ) {
$drop_down = '';
$i = 1;
foreach ($items as $groupLabel => $groups) {
if ( !empty($groupLabel)) {
$drop_down .= "";
}
$i = $i + 1;
}
wpfm_set_cached_data( $key, $drop_down );
if ( $selected && strpos( $drop_down, "value='" . esc_attr($selected) . "'" ) !== false ) {
$drop_down = str_replace( "value='" . esc_attr($selected) . "'", 'value="' . esc_attr($selected) . '"' . ' selected', $drop_down );
}
return $drop_down;
}
/**
* Print attributes as select dropdown.
*
* @since 1.0.0
* @param $key
* @param $name
* @param string $selected
*/
public function printSelectDropdown( $key, $name, $selected = '', $class = '', $multiple = '', $array = '' ){
if ( $name === 'attr' ) {
$items = $this->attributes;
}elseif ( $name === 'meta_key' ) {
$items = $this->product_meta_keys;
}elseif ( $name === 'escape' ) {
$items = $this->sanitization_options;
}else{
return;
}
echo '";
}
/**
* Print attributes Type.
*
* @since 1.0.0
* @param $key
* @param string $select
*/
public function printAttType( $key, $select = '' ){
$options = apply_filters('wpfm_pro_feed_attribute_type_render', array( 'meta' => 'Attribute', 'static' => 'Static'));
echo "";
}
/**
* Print Prefix input.
*
* @since 1.0.0
* @param $key
* @param string $name
* @param string $val
*/
public function printInput( $key, $name = '', $val = '', $class = '' ){
echo '';
}
/**
* Initialize Product Meta Attributes
*
* @since 1.0.0
*/
protected function init_product_meta_keys(){
$this->product_meta_keys = Rex_Feed_Attributes::get_attributes();
}
/**
* Initialize Sanitization Options
*
* @since 1.0.0
*/
protected function init_sanitization_options(){
$this->sanitization_options = array(
'' => array(
'default' => 'Default',
'strip_tags' => 'Strip Tags',
'utf_8_encode' => 'UTF-8 Encode',
'htmlentities' => 'htmlentities',
'integer' => 'Integer',
'price' => 'Price',
'remove_space' => 'Remove Space',
'first_word_uppercase' => 'First Word Uppercase Only',
'remove_shortcodes' => 'Remove ShortCodes',
'remove_shortcodes_and_tags' => 'Remove ShortCodes and Strip Tags',
'remove_special character' => 'Remove Special Character',
'cdata' => 'CDATA',
'cdata_without_space' => 'CDATA without space',
'remove_underscore' => 'Remove underscore',
'decode_url' => 'Decode url',
'remove_decimal' => 'Remove decimal points (Marktplaats only)',
'add_two_decimal' => 'Two decimal points',
'comma_decimal' => 'Decimal Separator - Comma (,)',
'remove_hyphen' => 'Remove hyphen',
'remove_hyphen_space' => 'Remove hyphen(space)',
'replace_space_with_hyphen' => 'Replace Space With Hyphen',
)
);
}
/**
* Initialize Template Mappings with Attributes from feed post_meta.
*
* @since 1.0.0
* @param string $feed_rules The Rules Of Feeds
*/
protected function init_template_mappings( $feed_rules ){
if ( !empty($feed_rules) && $feed_rules ) {
$this->template_mappings = $feed_rules;
}else{
$this->init_default_template_mappings();
}
}
/**
* Initialize Attributes
*
* @since 1.0.0
*/
abstract protected function init_atts();
/**
* Initialize Default Template Mappings with Attributes.
*
* @since 1.0.0
*/
abstract protected function init_default_template_mappings();
}