_ok = parent::isValidAid( true ); add_shortcode( 'adfever', array(&$this, 'shortCode') ); if ( !is_admin() ) { wp_enqueue_style( 'adfever-shortcode', get_bloginfo('siteurl').'/?adfever-css=shortcode', array(), $this->version, 'all' ); $this->checkCSS(); } } function shortCode($atts) { global $post; if ( get_post_meta($post->ID, 'desactive_adfever', true) == '1' ) { // Options desactive adfever return ''; } if($this->_ok!==true) { return ''; } extract(shortcode_atts(array( 'type' => '', 'value' => '', ), $atts)); if ( empty($type) || empty($value) ) { return ''; } $shop_obj = $this->getShopObj(); switch ( $type ) { case 'top-category' : $item = $shop_obj->getTop( $value, 5 ); if ( !is_array($item["shopping"]["products"]["product"]) ) { return ''; } $key = array_rand( $item["shopping"]["products"]["product"] ); return $this->buildTableProduct( $item["shopping"]["products"]["product"][$key] ); break; case 'product' : default : // Get item and stores $item = $shop_obj->find( $value ); $item = $item["shopping"]["product"]; if($item) { return $this->buildTableProduct( $item ); } else { return ""; } break; } return ''; } function buildTableProduct( $item = null ) { if ( is_null($item) || ( isset($item[0]) && empty($item[0]) ) ) { //return __( 'Internal error.', 'adfever' ); return ""; } $stores = isset($item["offers"]["offer"]) ? $item["offers"]["offer"] : (isset($item[0]["offers"]["offer"]) ? $item[0]["offers"]["offer"]: False); if (!$stores) return ""; $item = isset($item['name']) ? $item : $item[0]; $current_options = get_option( $this->option_name ); $output = ''; $output .= '
' . "\n"; if ( isset($current_options['photo']) && $current_options['photo'] == '1' && !empty($item['image']) ) $output .= ''.attribute_escape($item['name']).'' . "\n"; if(isset($current_options['title']) && $current_options['title']==1) { $output .= '
'.wp_specialchars($item['name']).'
' . "\n"; } if(isset($current_options['description']) && $current_options['description']==1) { $output .= apply_filters('the_adfever_description', $item['description']) . "\n"; } $output .= '
' . "\n"; if ( is_array($stores) && !empty($stores) ) : $output .= '' . "\n"; $output .= '' . "\n"; $output .= '' . "\n"; $output .= '' . "\n"; $output .= '' . "\n"; $output .= '' . "\n"; $output .= '' . "\n"; $output .= '' . "\n"; $output .= '' . "\n"; $stores = array_slice( $stores, 0, (isset($current_options['max-store']) ? $current_options['max-store'] : 5)); foreach( (array) $stores as $store ) { $output .= '' . "\n"; $logo_url = $store['logo']; if ( isset($current_options['logos']) && $current_options['logos'] == '1' && !empty($logo_url) ) $output .= '' . "\n"; // Display logo for each stores else $output .= '' . "\n"; $output .= '' . "\n"; $output .= '' . "\n"; $output .= '' . "\n"; } $output .= '' . "\n"; $output .= '
'.__('Retailer', 'adfever').''.__('Availability', 'adfever').''.__('Total price (incl.delivery)', 'adfever').'
'.attribute_escape($store['merchant']).''.wp_specialchars($store['merchant']).''.$store['stock'].''.$store['total_price']['value'].'
' . "\n"; else : $output .= '

'.__('No retailers for this product.', 'adfever').'

' . "\n"; endif; $output .= parent::getCopyright(); $output .= '
' . "\n"; return $output; } function checkCSS() { if ( isset($_GET['adfever-css']) && $_GET['adfever-css'] == 'shortcode' ) { $this->displayCSS(); exit(); } } function displayCSS() { $expires_offset = 31536000; header('Content-Type: text/css'); header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT'); header("Cache-Control: public, max-age=$expires_offset"); $current_options = get_option( $this->option_name ); require_once ADFEVER_DIR.'/inc/css/shortcode.css'; exit(); } } ?>