Advertisement
chrishajer

Combined five functions into one

Jan 9th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 43.19 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! function_exists( 'boutique_active_plugin' ) ) :
  4. function boutique_active_plugin(){
  5.     $active_plugins = get_option('active_plugins');
  6.     $plugin_name = '';
  7.    
  8.     if ( in_array( 'shopp/Shopp.php',$active_plugins ) || in_array( 'Shopp.php',$active_plugins ) ) $plugin_name = 'shopp';
  9.     elseif ( in_array( 'wp-e-commerce/wp-shopping-cart.php',$active_plugins ) ) $plugin_name = 'wp_ecommerce';
  10.     elseif ( in_array( 'eshop/eshop.php',$active_plugins ) || in_array( 'eshop.php',$active_plugins ) ) $plugin_name = 'eshop';
  11.     elseif ( in_array( 'cart66-lite/cart66.php',$active_plugins ) || in_array( 'cart66/cart66.php',$active_plugins ) || in_array( 'cart66-pro/cart66.php',$active_plugins ) )   $plugin_name = 'cart66';
  12.     elseif ( in_array( 'wordpress-simple-paypal-shopping-cart/wp_shopping_cart.php',$active_plugins ) ) $plugin_name = 'wp_simple_paypal_sc';
  13.    
  14.     return ( $plugin_name <> '' ) ? $plugin_name : false;
  15. }
  16. endif;
  17.  
  18. add_action( 'after_setup_theme', 'et_setup_theme' );
  19. if ( ! function_exists( 'et_setup_theme' ) ){
  20.     function et_setup_theme(){
  21.         global $themename, $shortname;
  22.         $themename = "Boutique";
  23.         $shortname = "boutique";
  24.        
  25.         require_once(TEMPLATEPATH . '/epanel/custom_functions.php');
  26.  
  27.         require_once(TEMPLATEPATH . '/includes/functions/comments.php');
  28.  
  29.         require_once(TEMPLATEPATH . '/includes/functions/sidebars.php');
  30.  
  31.         load_theme_textdomain('Boutique',get_template_directory().'/lang');
  32.  
  33.         require_once(TEMPLATEPATH . '/epanel/options_boutique.php');
  34.  
  35.         require_once(TEMPLATEPATH . '/epanel/core_functions.php');
  36.  
  37.         require_once(TEMPLATEPATH . '/epanel/post_thumbnails_boutique.php');
  38.        
  39.         include(TEMPLATEPATH . '/includes/widgets.php');
  40.        
  41.         add_action( 'pre_get_posts', 'et_home_posts_query' );
  42.        
  43.         add_action( 'et_epanel_changing_options', 'et_delete_featured_ids_cache' );
  44.         add_action( 'delete_post', 'et_delete_featured_ids_cache' );   
  45.         add_action( 'save_post', 'et_delete_featured_ids_cache' );
  46.     }
  47. }
  48.  
  49. /**
  50.  * Gets featured posts IDs from transient, if the transient doesn't exist - runs the query and stores IDs
  51.  */
  52. function et_get_featured_posts_ids(){
  53.     if ( false === ( $et_featured_post_ids = get_transient( 'et_featured_post_ids' ) ) ) {
  54.         $featured_query = new WP_Query( apply_filters( 'et_featured_post_args', array(
  55.             'posts_per_page'    => (int) et_get_option( 'boutique_featured_num' ),
  56.             'cat'               => get_catId( et_get_option( 'boutique_feat_cat' ) )
  57.         ) ) );
  58.  
  59.         if ( $featured_query->have_posts() ) {
  60.             while ( $featured_query->have_posts() ) {
  61.                 $featured_query->the_post();
  62.                
  63.                 $et_featured_post_ids[] = get_the_ID();
  64.             }
  65.  
  66.             set_transient( 'et_featured_post_ids', $et_featured_post_ids );
  67.         }
  68.        
  69.         wp_reset_postdata();
  70.     }
  71.    
  72.     return $et_featured_post_ids;
  73. }
  74.  
  75. /**
  76.  * Filters the main query on homepage
  77.  */
  78. function et_home_posts_query( $query = false ) {
  79.     /* Don't proceed if it's not homepage or the main query */
  80.     if ( ! is_home() || ! is_a( $query, 'WP_Query' ) || ! $query->is_main_query() ) return;
  81.    
  82.     $boutique_active_plugin_name = boutique_active_plugin();
  83.    
  84.     if ( 'wp_ecommerce' != $boutique_active_plugin_name ){
  85.         /* Set the amount of posts per page on homepage */
  86.         $query->set( 'posts_per_page', et_get_option( 'boutique_homepage_posts', '6' ) );
  87.        
  88.         /* Exclude categories set in ePanel */
  89.         $exclude_categories = et_get_option( 'boutique_exlcats_recent', false );
  90.         if ( $exclude_categories ) $query->set( 'category__not_in', $exclude_categories );
  91.     } else {
  92.         $query->set( 'posts_per_page', et_get_option( 'boutique_homepage_posts', '6' ) );
  93.         $query->set( 'post_type', 'wpsc-product' );
  94.         $query->set( 'tax_query', array(
  95.             array(
  96.                 'taxonomy' => 'wpsc_product_category',
  97.                 'field' => 'id',
  98.                 'terms' => get_option('boutique_exlcats_recent'),
  99.                 'operator' => 'NOT IN',
  100.             )
  101.         ) );
  102.     }
  103.    
  104.     /* Exclude slider posts, if the slider is activated, pages are not featured and posts duplication is disabled in ePanel  */
  105.     if ( 'on' == et_get_option( 'boutique_featured', 'on' ) && 'false' == et_get_option( 'boutique_use_pages', 'false' ) && 'false' == et_get_option( 'boutique_duplicate', 'on' ) && 'wp_ecommerce' != $boutique_active_plugin_name )
  106.         $query->set( 'post__not_in', et_get_featured_posts_ids() );
  107. }
  108.  
  109. /**
  110.  * Deletes featured posts IDs transient, when the user saves, resets ePanel settings, creates or moves posts to trash in WP-Admin
  111.  */
  112. function et_delete_featured_ids_cache(){
  113.     if ( false !== get_transient( 'et_featured_post_ids' ) ) delete_transient( 'et_featured_post_ids' );
  114. }
  115.  
  116. add_action('wp_head','et_portfoliopt_additional_styles',100);
  117. function et_portfoliopt_additional_styles(){ ?>
  118.     <style type="text/css">
  119.         #et_pt_portfolio_gallery { margin-left: -41px; margin-right: -51px; }
  120.         .et_pt_portfolio_item { margin-left: 35px; }
  121.         .et_portfolio_small { margin-left: -40px !important; }
  122.         .et_portfolio_small .et_pt_portfolio_item { margin-left: 32px !important; }
  123.         .et_portfolio_large { margin-left: -26px !important; }
  124.         .et_portfolio_large .et_pt_portfolio_item { margin-left: 11px !important; }
  125.     </style>
  126. <?php }
  127.  
  128. function register_main_menus() {
  129.     register_nav_menus(
  130.         array(
  131.             'primary-menu' => __( 'Primary Menu' ),
  132.             'secondary-menu' => __( 'Secondary Menu' ),
  133.             'footer-menu' => __( 'Footer Menu' )
  134.         )
  135.     );
  136. }
  137. if (function_exists('register_nav_menus')) add_action( 'init', 'register_main_menus' );
  138.  
  139. // add Home link to the custom menu WP-Admin page
  140. function et_add_home_link( $args ) {
  141.     $args['show_home'] = true;
  142.     return $args;
  143. }
  144. add_filter( 'wp_page_menu_args', 'et_add_home_link' );
  145.  
  146. add_action( 'et_get_additional_color_scheme', 'et_disable_color_scheme' );
  147. function et_disable_color_scheme( $color_scheme ){
  148.     global $default_colorscheme;
  149.     return $default_colorscheme;
  150. }
  151.  
  152. add_action('wp_head','et_add_meta_javascript');
  153. function et_add_meta_javascript(){
  154.     global $shortname;
  155.     echo '<!-- used in scripts -->';
  156.     echo '<meta name="et_featured_auto_speed" content="'.get_option($shortname.'_slider_autospeed').'" />';
  157.            
  158.     $disable_toptier = get_option($shortname.'_disable_toptier') == 'on' ? 1 : 0;
  159.     echo '<meta name="et_disable_toptier" content="'.$disable_toptier.'" />';
  160.    
  161.     $featured_slider_pause = get_option($shortname.'_slider_pause') == 'on' ? 1 : 0;
  162.     echo '<meta name="et_featured_slider_pause" content="'.$featured_slider_pause.'" />';
  163.    
  164.     $featured_slider_auto = get_option($shortname.'_slider_auto') == 'on' ? 1 : 0;
  165.     echo '<meta name="et_featured_slider_auto" content="'.$featured_slider_auto.'" />';
  166.    
  167.     echo '<meta name="et_theme_folder" content="'.get_template_directory_uri().'" />';
  168. }
  169.  
  170. if ( ! function_exists( 'boutique_product_name' ) ) :
  171. function boutique_product_name( $slug = '' ){
  172.     global $post;
  173.     $name = get_option('boutique_use_pages') == 'on' ? 'page' : 'post';
  174.    
  175.     return 'et-' . $slug . '-' . $name . '-' . $post->ID;
  176. }
  177. endif;
  178.  
  179. if ( ! function_exists( 'boutique_price' ) ) :
  180. function boutique_price(){
  181.     global $post, $boutique_active_plugin_name, $wpdb;
  182.     $price = 0;
  183.     switch ($boutique_active_plugin_name){
  184.         case 'shopp':
  185.             global $Shopp;
  186.             $Shopp->Catalog->tag('product',array('id'=>get_post_meta($post->ID,'_et_shopp_product_id',true)));
  187.             $price = shopp('product','saleprice','echo=false') ? shopp('product','saleprice','echo=false') : shopp('product','price','echo=false');
  188.             $price = preg_replace('/[^\d.,]/','',$price);
  189.            
  190.             break;
  191.         case 'eshop':
  192.             $eshop_post_settings = get_post_meta($post->ID,'_eshop_product',true);
  193.             if ($eshop_post_settings) $price = $eshop_post_settings['products'][1]['price'];
  194.            
  195.             break;
  196.         case 'cart66':
  197.             $cart66_tablename = Cart66Common::getTableName('products');
  198.             $results = $wpdb->get_results($wpdb->prepare("SELECT price FROM $cart66_tablename WHERE item_number = %s", get_post_meta($post->ID,'_et_cart66_product_id',true)));
  199.             if ( $results ) $price = $results[0]->price;
  200.            
  201.             break;
  202.         case 'wp_simple_paypal_sc':
  203.             $price = get_post_meta($post->ID,'_et_simple_paypal_price',true);
  204.            
  205.             break;
  206.         case 'wp_ecommerce':
  207.             global $wpsc_variations;
  208.            
  209.             $wpsc_variations = new wpsc_variations( get_the_ID() );
  210.            
  211.             $price = get_post_meta( get_the_ID(), '_wpsc_special_price', true ) ? get_post_meta( get_the_ID(), '_wpsc_special_price', true ) : get_post_meta( get_the_ID(), '_wpsc_price', true );
  212.            
  213.             $price = ! empty( $wpsc_variations->first_variations ) ? str_replace( boutique_currency_sign(), '', wpsc_product_variation_price_available( get_the_ID() ) ) : apply_filters( 'et_wp_ecommerce_price_format', number_format( $price, 2 ), $price );
  214.         break;
  215.     }
  216.     return $price;
  217. }
  218. endif;
  219.  
  220. if ( ! function_exists( 'boutique_currency_sign' ) ) :
  221. function boutique_currency_sign(){
  222.     global $post, $boutique_active_plugin_name, $wpsc_currency_data, $wpdb;
  223.     $currency_sign = 0;
  224.     switch ($boutique_active_plugin_name){
  225.         case 'shopp':
  226.             $shopp_currency = currency_format();
  227.             $currency_sign = $shopp_currency['currency'];
  228.            
  229.             break;
  230.         case 'eshop':
  231.             global $eshopoptions;
  232.             $currency_sign = $eshopoptions['currency_symbol'] ? $eshopoptions['currency_symbol'] : '$';
  233.            
  234.             break;
  235.         case 'cart66':
  236.             $currency_sign = defined('CART66_CURRENCY_SYMBOL') ? CART66_CURRENCY_SYMBOL : CURRENCY_SYMBOL;
  237.            
  238.             break;
  239.         case 'wp_simple_paypal_sc':
  240.             $currency_sign = get_option('cart_currency_symbol');
  241.            
  242.             break;
  243.         case 'wp_ecommerce':
  244.             if ( !$wpsc_currency_data ){
  245.                 $wpsc_currency_data = $wpdb->get_row( $wpdb->prepare("SELECT `symbol`, `symbol_html`, `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id` = '" . '%d' . "' LIMIT 1", get_option( 'currency_type' )), ARRAY_A );
  246.             }
  247.             $currency_sign = $wpsc_currency_data['symbol'];
  248.            
  249.             break;
  250.     }
  251.     return $currency_sign;
  252. }
  253. endif;
  254.  
  255. add_action('init','et_global_active_plugin');
  256. function et_global_active_plugin(){
  257.     global $boutique_active_plugin_name;
  258.     $boutique_active_plugin_name = boutique_active_plugin();
  259. }
  260.  
  261. add_action('boutique_featured_product','boutique_featured_product_options');
  262. function boutique_featured_product_options(){
  263.     boutique_popup_info('featured');
  264. }
  265.  
  266. add_action('boutique_special_offer','boutique_special_offer_options');
  267. function boutique_special_offer_options(){
  268.     boutique_popup_info('offer');
  269. }
  270.  
  271. add_action('boutique_product_entry','boutique_product_entry_options');
  272. function boutique_product_entry_options(){
  273.     global $post, $boutique_active_plugin_name;
  274.     boutique_popup_info('entry'); ?>
  275.     <div class="boutique_description_border">
  276.         <div class="boutique_description">
  277.             <h4 class="description-title"><?php the_title(); ?></h4>
  278.             <span class="price"><span>€</span><?php if ( ( $myprice = get_post_meta( $post->ID, 'myprice', true) ) && $myprice <> '' ){echo $myprice;} ?></span>
  279.             <div class="clear"></div>
  280.             <div class="entry-item-ratings clearfix"><?php et_boutique_display_rating(); ?></div>
  281.             <?php
  282.                 if ( $boutique_active_plugin_name == 'wp_ecommerce' ) {
  283.                     if(wpsc_the_product_additional_description())
  284.                         echo wpsc_the_product_additional_description();
  285.                     else
  286.                         echo wpsc_the_product_description();
  287.                 } else { ?>
  288.                     <p><?php truncate_post(400); ?></p>
  289.             <?php } ?>
  290.         </div> <!-- end .boutique_description -->
  291.     </div> <!-- end .boutique_description_border -->
  292. <?php
  293. }
  294.  
  295. add_action('boutique_single_before_comments','boutique_related_posts');
  296. function boutique_related_posts(){ ?>
  297.     <?php
  298.         global $post;
  299.        
  300.         if ( boutique_is_single_blog_post() ) return;
  301.        
  302.         $orig_post = $post;
  303.         $tags = wp_get_post_tags($post->ID);
  304.         if ($tags) {
  305.             $tag_ids = array();
  306.            
  307.             foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
  308.             $args=array(
  309.                 'tag__in' => $tag_ids,
  310.                 'post__not_in' => array($post->ID),
  311.                 'showposts'=> apply_filters('boutique_related_items','4'),
  312.                 'ignore_sticky_posts'=> '1'
  313.             );
  314.             $related_query = new WP_Query( $args );
  315.            
  316.             if( $related_query->have_posts() ) { ?>
  317.                 <div class="related-items clearfix">
  318.                     <h3 class="offer-title related_products"><span><?php esc_html_e('Related Products','Boutique'); ?></span></h3>
  319.                     <?php
  320.                         $i=0;
  321.                         while ( $related_query->have_posts() ) : $related_query->the_post();
  322.                             $i++;
  323.                             boutique_display_product($i,'entry');
  324.                         endwhile;
  325.                     ?>
  326.                 </div> <!-- end .related-items -->
  327.             <?php }
  328.         }
  329.         $post = $orig_post;
  330.         wp_reset_postdata();
  331.     ?>
  332. <?php
  333. }
  334.  
  335. if ( ! function_exists( 'boutique_popup_info' ) ) :
  336. function boutique_popup_info($template_name){
  337.     global $boutique_active_plugin_name, $post;
  338.     $div_name = boutique_product_name($template_name);
  339. ?>
  340.     <div class="product_frame">
  341.         <div id="<?php echo $div_name; ?>">
  342.             <div class="et_popup_product_info et_<?php echo $boutique_active_plugin_name; ?>">
  343.                 <?php
  344.                     do_action('boutique_popup_product_description');
  345.                    
  346.                     if ( in_array( $boutique_active_plugin_name,array('cart66','eshop','wp_simple_paypal_sc') ) ){
  347.                         echo '<h2 class="et_popup_title"><a href="'.get_permalink().'">'.get_the_title().'</a></h2>';
  348.                         echo '<div class="et_popup_excerpt">' . get_the_excerpt() . '</div>';
  349.                     }
  350.                    
  351.                     do_action('boutique_popup_before_add_button');
  352.                    
  353.                     switch ($boutique_active_plugin_name){
  354.                         case 'shopp':
  355.                             if ( get_post_meta($post->ID,'_et_shopp_product_id',true) ) echo do_shortcode('[product id="'.get_post_meta($post->ID,'_et_shopp_product_id',true).'" ]');
  356.                             break;
  357.                         case 'eshop':
  358.                             #activate 'Show add to cart forms on WordPress post listings'
  359.                             global $eshopoptions;
  360.                             $eshopoptions['show_forms'] = 'yes';
  361.                             echo do_shortcode('[eshop_addtocart]');
  362.                            
  363.                             break;
  364.                         case 'cart66':
  365.                             echo do_shortcode('[add_to_cart item="'.get_post_meta($post->ID,'_et_cart66_product_id',true).'" ]');
  366.                             break;
  367.                         case 'wp_simple_paypal_sc':
  368.                             $sc_additional_settings = get_post_meta( $post->ID, '_et_simple_paypal_additional_settings', true ) ? get_post_meta( $post->ID, '_et_simple_paypal_additional_settings', true ) : '';
  369.                             $output = apply_filters('the_content',do_shortcode('[wp_cart:'.$post->post_title.':price:'.get_post_meta($post->ID,'_et_simple_paypal_price',true). esc_attr($sc_additional_settings) . ':end]'));
  370.                             $output = preg_replace('/"cartLink" value="([^"]+)"/','"cartLink" value="'.get_permalink($post->ID).'"',$output);
  371.                             echo $output;
  372.                             break;
  373.                         case 'wp_ecommerce':
  374.                             get_template_part('wpsc-boutique_index','index');
  375.                             break;
  376.                     }
  377.  
  378.                     do_action('boutique_popup_after_add_button'); ?>
  379.             </div> <!-- end .et_popup_product_info -->
  380.         </div> <!-- end #<?php echo $div_name; ?> -->
  381.     </div> <!-- end .product_frame -->
  382. <?php }
  383. endif;
  384.  
  385. $boutique_active_plugin_name = boutique_active_plugin();
  386. if ( $boutique_active_plugin_name == 'eshop' ) {
  387.     remove_filter('the_content', 'eshop_boing'); //don't add eshop data to the end of single post
  388. } else if ( $boutique_active_plugin_name == 'shopp' ){
  389.     add_action( 'wp_head', 'et_fix_shopp_pricetags' );
  390.    
  391.     function et_fix_shopp_pricetags(){
  392.     echo    '<script type="text/javascript">
  393.                 var pricetags = {};
  394.                 document.documentElement.id = "shopp";
  395.             </script>';
  396.     }
  397. }
  398.  
  399. if ( is_admin() && $boutique_active_plugin_name && !in_array($boutique_active_plugin_name,apply_filters('et_plugins_without_custom_panels',array('wp_ecommerce','eshop'))) ) {
  400.     function boutique_add_custom_panels(){
  401.         add_meta_box("et_post_meta", "ET Settings", "et_post_meta", "post", "normal", "high");
  402.     }
  403.     add_action("admin_init", "boutique_add_custom_panels");
  404.  
  405.     function et_post_meta() {
  406.         global $post, $boutique_active_plugin_name;
  407.         $active_plugin = $boutique_active_plugin_name;
  408.         if ( $active_plugin == 'shopp' )
  409.             $et_shopp_product_id = get_post_meta( $post->ID, '_et_shopp_product_id', true ) ? get_post_meta( $post->ID, '_et_shopp_product_id', true ) : '';
  410.         if ( $active_plugin == 'wp_simple_paypal_sc' ) {
  411.             $et_simple_paypal_price = get_post_meta( $post->ID, '_et_simple_paypal_price', true ) ? get_post_meta( $post->ID, '_et_simple_paypal_price', true ) : '';
  412.             $et_simple_paypal_additional_settings = get_post_meta( $post->ID, '_et_simple_paypal_additional_settings', true ) ? get_post_meta( $post->ID, '_et_simple_paypal_additional_settings', true ) : '';
  413.         }
  414.         if ( $active_plugin == 'cart66' )
  415.             $et_cart66_product_id = get_post_meta( $post->ID, '_et_cart66_product_id', true ) ? get_post_meta( $post->ID, '_et_cart66_product_id', true ) : ''; ?>
  416.        
  417.         <div id="et_custom_settings" style="margin: 13px 0 17px 4px;">
  418.             <?php if ( $active_plugin == 'shopp' ) { ?>
  419.                 <div class="et_fs_setting" style="margin: 13px 0 26px 4px;">
  420.                     <label for="et_shopp_product_id" style="color: #000; font-weight: bold;"> Shopp Product ID: </label>
  421.                     <input type="text" style="width: 30em;" value="<?php echo esc_attr($et_shopp_product_id); ?>" id="et_shopp_product_id" name="et_shopp_product_id" size="67" />
  422.                     <br />
  423.                     <small style="position: relative; top: 8px;">Insert Shopp Product ID here</small>
  424.                 </div>
  425.             <?php } ?>
  426.            
  427.             <?php if ( $active_plugin == 'wp_simple_paypal_sc' ) { ?>
  428.                 <div class="et_fs_setting" style="margin: 13px 0 26px 4px;">
  429.                     <label for="et_simple_paypal_price" style="color: #000; font-weight: bold;"> Product Price: </label>
  430.                     <input type="text" style="width: 30em;" value="<?php echo esc_attr($et_simple_paypal_price); ?>" id="et_simple_paypal_price" name="et_simple_paypal_price" size="67" />
  431.                     <br />
  432.                     <small style="position: relative; top: 8px;">ex. <code>19.99</code></small>
  433.                 </div>
  434.                 <div class="et_fs_setting" style="margin: 13px 0 26px 4px;">
  435.                     <label for="et_simple_paypal_additional_settings" style="color: #000; font-weight: bold;"> Additional Settings: </label>
  436.                     <input type="text" style="width: 30em;" value="<?php echo esc_attr($et_simple_paypal_additional_settings); ?>" id="et_simple_paypal_additional_settings" name="et_simple_paypal_additional_settings" size="67" />
  437.                     <br />
  438.                     <small style="position: relative; top: 8px;">You can set shipping and variations here. e.g. <code><?php echo esc_html(':shipping:15:var1[Size|Small|Medium|Large]:var2[Color|Red|Green]'); ?></code><br /> Learn more about it <a href="http://www.tipsandtricks-hq.com/ecommerce/simple-wp-shopping-cart-installation-usage-290" target="_blank">here</a></small>
  439.                 </div>
  440.             <?php } ?>
  441.            
  442.             <?php if ( $active_plugin == 'cart66' ) { ?>
  443.                 <div class="et_fs_setting" style="margin: 13px 0 26px 4px;">
  444.                     <label for="et_cart66_product_id" style="color: #000; font-weight: bold;"> Cart66 Item Number: </label>
  445.                     <input type="text" style="width: 30em;" value="<?php echo esc_attr($et_cart66_product_id); ?>" id="et_cart66_product_id" name="et_cart66_product_id" size="67" />
  446.                     <br />
  447.                     <small style="position: relative; top: 8px;">Insert Cart66 Item Number here. ex: <code>0001</code></small>
  448.                 </div>
  449.             <?php } ?>
  450.         </div> <!-- #et_custom_settings -->
  451.            
  452.         <?php
  453.     }
  454.  
  455.     add_action('save_post', 'boutique_save_details');
  456.     function boutique_save_details($post_id){
  457.         global $pagenow;
  458.    
  459.         if ( 'post.php' != $pagenow ) return $post_id;
  460.        
  461.         if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
  462.             return $post_id;
  463.            
  464.         global $boutique_active_plugin_name;
  465.         $active_plugin = $boutique_active_plugin_name;
  466.            
  467.         if ( $active_plugin == 'shopp' ) {
  468.             if ( isset($_POST['et_shopp_product_id']) ) update_post_meta( $post_id, '_et_shopp_product_id', esc_attr($_POST['et_shopp_product_id']) );
  469.         }
  470.         if ( $active_plugin == 'wp_simple_paypal_sc' ) {
  471.             if ( isset($_POST['et_simple_paypal_price']) ) update_post_meta( $post_id, '_et_simple_paypal_price', esc_attr($_POST['et_simple_paypal_price']) );
  472.             if ( isset($_POST['et_simple_paypal_additional_settings']) ) update_post_meta( $post_id, '_et_simple_paypal_additional_settings', esc_attr($_POST['et_simple_paypal_additional_settings']) );
  473.         }
  474.         if ( $active_plugin == 'cart66' ) {
  475.             if ( isset($_POST['et_cart66_product_id'] ) ) update_post_meta( $post_id, '_et_cart66_product_id', esc_attr($_POST['et_cart66_product_id']) );
  476.         }
  477.     }
  478. }
  479.  
  480.  
  481. add_action('et_header_top','et_boutique_control_panel');
  482. function et_boutique_control_panel(){
  483.     $admin_access = apply_filters( 'et_showcontrol_panel', current_user_can('switch_themes') );
  484.     if ( !$admin_access ) return;
  485.     if ( get_option('boutique_show_control_panel') <> 'on' ) return;
  486.     global $et_bg_texture_urls, $et_google_fonts; ?>
  487.     <div id="et-control-panel">
  488.         <div id="control-panel-main">
  489.             <a id="et-control-close" href="#"></a>
  490.             <div id="et-control-inner">
  491.                 <h3 class="control_title">Example Colors</h3>
  492.                 <a href="#" class="et-control-colorpicker" id="et-control-background"></a>
  493.                
  494.                 <div class="clear"></div>
  495.                
  496.                 <?php
  497.                     $sample_colors = array( '6a8e94', '8da49c', 'b0b083', '859a7c', 'c6bea6', 'b08383', 'a4869d', 'f5f5f5', '4e4e4e', '556f6a', '6f5555', '6f6755' );
  498.                     for ( $i=1; $i<=12; $i++ ) { ?>
  499.                         <a class="et-sample-setting" id="et-sample-color<?php echo $i; ?>" href="#" rel="<?php echo esc_attr($sample_colors[$i-1]); ?>" title="#<?php echo esc_attr($sample_colors[$i-1]); ?>"><span class="et-sample-overlay"></span></a>
  500.                 <?php } ?>
  501.                 <p>or define your own in ePanel</p>
  502.                
  503.                 <h3 class="control_title">Texture Overlays</h3>
  504.                 <div class="clear"></div>
  505.                
  506.                 <?php
  507.                     $sample_textures = $et_bg_texture_urls;
  508.                     for ( $i=1; $i<=count($et_bg_texture_urls); $i++ ) { ?>
  509.                         <a title="<?php echo esc_attr($sample_textures[$i-1]); ?>" class="et-sample-setting et-texture" id="et-sample-texture<?php echo $i; ?>" href="#" rel="bg<?php echo $i+1; ?>"><span class="et-sample-overlay"></span></a>
  510.                 <?php } ?>
  511.                
  512.                 <p>or define your own in ePanel</p>
  513.                
  514.                 <?php
  515.                     $google_fonts = $et_google_fonts;
  516.                     $font_setting = 'Kreon';
  517.                     $body_font_setting = 'Droid+Sans';
  518.                     if ( isset( $_COOKIE['et_boutique_header_font'] ) ) $font_setting = $_COOKIE['et_boutique_header_font'];
  519.                     if ( isset( $_COOKIE['et_boutique_body_font'] ) ) $body_font_setting = $_COOKIE['et_boutique_body_font'];
  520.                 ?>
  521.                
  522.                 <h3 class="control_title">Fonts</h3>
  523.                 <div class="clear"></div>
  524.                
  525.                 <label for="et_control_header_font">Header
  526.                     <select name="et_control_header_font" id="et_control_header_font">
  527.                         <?php foreach( $google_fonts as $google_font ) { ?>
  528.                             <?php $encoded_value = urlencode($google_font); ?>
  529.                             <option value="<?php echo esc_attr($encoded_value); ?>" <?php selected( $font_setting, $encoded_value ); ?>><?php echo esc_html($google_font); ?></option>
  530.                         <?php } ?>
  531.                     </select>
  532.                 </label>
  533.                 <a href="#" class="et-control-colorpicker et-font-control" id="et-control-headerfont_bg"></a>
  534.                 <div class="clear"></div>
  535.                
  536.                 <label for="et_control_body_font">Body
  537.                     <select name="et_control_body_font" id="et_control_body_font">
  538.                         <?php foreach( $google_fonts as $google_font ) { ?>
  539.                             <?php $encoded_value = urlencode($google_font); ?>
  540.                             <option value="<?php echo esc_attr($encoded_value); ?>" <?php selected( $body_font_setting, $encoded_value ); ?>><?php echo esc_html($google_font); ?></option>
  541.                         <?php } ?>
  542.                     </select>
  543.                 </label>
  544.                 <a href="#" class="et-control-colorpicker et-font-control" id="et-control-bodyfont_bg"></a>
  545.                 <div class="clear"></div>
  546.                
  547.             </div> <!-- end #et-control-inner -->
  548.         </div> <!-- end #control-panel-main -->
  549.     </div> <!-- end #et-control-panel -->
  550. <?php
  551. }
  552.  
  553. add_action( 'wp_enqueue_scripts', 'et_load_boutique_scripts' );
  554. function et_load_boutique_scripts(){
  555.     if ( !is_admin() ){
  556.         $template_dir = get_template_directory_uri();
  557.        
  558.         wp_enqueue_script('easing', $template_dir . '/js/jquery.easing.1.3.js', array('jquery'), '1.0', true);
  559.         wp_enqueue_script('cycle', $template_dir . '/js/jquery.cycle.all.min.js', array('jquery'), '1.0', true);
  560.         wp_enqueue_script('superfish', $template_dir . '/js/superfish.js', array('jquery'), '1.0', true);
  561.         wp_enqueue_script('custom_script', $template_dir . '/js/custom.js', array('jquery'), '1.0', true);
  562.        
  563.         $admin_access = apply_filters( 'et_showcontrol_panel', current_user_can('switch_themes') );
  564.         if ( $admin_access && get_option('boutique_show_control_panel') == 'on' ) {
  565.             wp_enqueue_script('et_colorpicker', $template_dir . '/epanel/js/colorpicker.js', array('jquery'), '1.0', true);
  566.             wp_enqueue_script('et_eye', $template_dir . '/epanel/js/eye.js', array('jquery'), '1.0', true);
  567.             wp_enqueue_script('et_cookie', $template_dir . '/js/jquery.cookie.js', array('jquery'), '1.0', true);
  568.             wp_enqueue_script('et_control_panel', $template_dir . '/js/et_control_panel.js', array('jquery'), '1.0', true);
  569.         }
  570.     }
  571. }
  572.  
  573. add_action( 'wp_head', 'et_set_bg_properties' );
  574. function et_set_bg_properties(){
  575.     global $et_bg_texture_urls;
  576.    
  577.     $bgcolor = '';
  578.     $bgcolor = ( isset( $_COOKIE['et_boutique_bgcolor'] ) && get_option('boutique_show_control_panel') == 'on' ) ? $_COOKIE['et_boutique_bgcolor'] : get_option('boutique_bgcolor');
  579.    
  580.     $bgtexture_url = '';
  581.     $bgimage_url = '';
  582.     if ( get_option('boutique_bgimage') == '' ) {
  583.         if ( isset( $_COOKIE['et_boutique_texture_url'] ) && get_option('boutique_show_control_panel') == 'on' ) $bgtexture_url =  $_COOKIE['et_boutique_texture_url'];
  584.         else {
  585.             $bgtexture_url = get_option('boutique_bgtexture_url');
  586.             if ( $bgtexture_url == 'Default' ) $bgtexture_url = '';
  587.             else $bgtexture_url = get_template_directory_uri() . '/images/cp/body-bg' . ( array_search( $bgtexture_url, $et_bg_texture_urls )+2 ) . '.png';
  588.         }
  589.     } else {
  590.         $bgimage_url = get_option('boutique_bgimage');
  591.     }
  592.    
  593.     $style = '';
  594.     $style .= '<style type="text/css">';
  595.     if ( $bgcolor <> '' ) {
  596.         $style .= '#top-area,#footer { background-color: #' . esc_attr($bgcolor) . '; }';
  597.     }
  598.     if ( $bgtexture_url <> '' ) $style .= '#top-area,#footer { background-image: url(' . esc_attr($bgtexture_url) . '); }';
  599.     if ( $bgimage_url <> '' ) $style .= '#top-area,#footer { background-image: url(' . esc_attr($bgimage_url) . '); background-position: top center; background-repeat: no-repeat; }';
  600.     $style .= '</style>';
  601.    
  602.     if ( $bgcolor <> '' || $bgtexture_url <> '' || $bgimage_url <> '' ) echo $style;
  603. }
  604.  
  605. add_action( 'wp_head', 'et_set_font_properties' );
  606. function et_set_font_properties(){
  607.     $font_style = '';
  608.     $font_color = '';
  609.     $font_family = '';
  610.     $font_color_string = '';
  611.    
  612.     if ( isset( $_COOKIE['et_boutique_header_font'] ) && get_option('boutique_show_control_panel') == 'on' ) $et_header_font =  $_COOKIE['et_boutique_header_font'];
  613.     else {
  614.         $et_header_font = get_option('boutique_header_font');
  615.         if ( $et_header_font == 'Kreon' ) $et_header_font = '';
  616.     }
  617.    
  618.     if ( isset( $_COOKIE['et_boutique_header_font_color'] ) && get_option('boutique_show_control_panel') == 'on' )  
  619.         $et_header_font_color =  $_COOKIE['et_boutique_header_font_color'];
  620.     else
  621.         $et_header_font_color = get_option('boutique_header_font_color');
  622.    
  623.     if ( $et_header_font <> '' || $et_header_font_color <> '' ) {
  624.         $et_header_font_id = strtolower( str_replace( '+', '_', $et_header_font ) );
  625.         $et_header_font_id = str_replace( ' ', '_', $et_header_font_id );
  626.        
  627.         if ( $et_header_font <> '' ) {
  628.             $font_style .= "<link id='" . esc_attr($et_header_font_id) . "' href='" . esc_url( "http://fonts.googleapis.com/css?family=" . str_replace( ' ', '+', $et_header_font )  . ( 'Raleway' == $et_header_font ? ':100' : '' ) ) . "' rel='stylesheet' type='text/css' />";
  629.             $font_family = "font-family: '" . str_replace( '+', ' ', $et_header_font ) . "', Arial, sans-serif !important; ";
  630.         }
  631.        
  632.         if ( $et_header_font_color <> '' ) {
  633.             $font_color_string = "color: #" . esc_html($et_header_font_color) . "; ";
  634.         }
  635.        
  636.         $font_style .= "<style type='text/css'>h1,h2,h3,h4,h5,h6 { ". $font_family .  " }</style>";
  637.         $font_style .= "<style type='text/css'>h1,h2,h3,h4,h5,h6, h2 a, h3 a, h4 a, h5 a, h6 a { ". esc_attr($font_color_string) .  " }
  638.         h2.featured-title a, #footer h4.widget-title { color: #fff !important; }
  639.         </style>";
  640.        
  641.         echo $font_style;
  642.     }
  643.    
  644.     $font_style = '';
  645.     $font_color = '';
  646.     $font_family = '';
  647.     $font_color_string = '';
  648.    
  649.     if ( isset( $_COOKIE['et_boutique_body_font'] ) && get_option('boutique_show_control_panel') == 'on' ) $et_body_font =  $_COOKIE['et_boutique_body_font'];
  650.     else {
  651.         $et_body_font = get_option('boutique_body_font');
  652.         if ( $et_body_font == 'Droid+Sans' ) $et_body_font = '';
  653.     }
  654.    
  655.     if ( isset( $_COOKIE['et_boutique_body_font_color'] ) && get_option('boutique_show_control_panel') == 'on' )    
  656.         $et_body_font_color =  $_COOKIE['et_boutique_body_font_color'];
  657.     else
  658.         $et_body_font_color = get_option('boutique_body_font_color');
  659.    
  660.     if ( $et_body_font <> '' || $et_body_font_color <> '' ) {
  661.         $et_body_font_id = strtolower( str_replace( '+', '_', $et_body_font ) );
  662.         $et_body_font_id = str_replace( ' ', '_', $et_body_font_id );
  663.        
  664.         if ( $et_body_font <> '' ) {
  665.             $font_style .= "<link id='" . esc_attr($et_body_font_id) . "' href='" . esc_url( "http://fonts.googleapis.com/css?family=" . str_replace( ' ', '+', $et_body_font ) . ( 'Raleway' == $et_body_font ? ':100' : '' ) ) . "' rel='stylesheet' type='text/css' />";
  666.             $font_family = "font-family: '" . str_replace( '+', ' ', $et_body_font ) . "', Arial, sans-serif !important; ";
  667.         }
  668.        
  669.         if ( $et_body_font_color <> '' ) {
  670.             $font_color_string = "color: #" . esc_attr($et_body_font_color) . " !important; ";
  671.         }
  672.        
  673.         $font_style .= "<style type='text/css'>body { ". html_entity_decode( $font_family ) .  " }</style>";
  674.         $font_style .= "<style type='text/css'>body { ". esc_html($font_color_string) .  " }</style>";
  675.        
  676.         echo $font_style;
  677.     }
  678. }
  679.  
  680. if ( ! function_exists( 'boutique_display_product' ) ) :
  681. function boutique_display_product( $post_iterator, $template_name ){
  682.     global $post; ?>
  683.     <div class="main-product<?php if ( $post_iterator % 4 == 0 ) echo ' last'; ?>">
  684.         <?php  
  685.             $width = 196;
  686.             $height = 166;
  687.             $titletext = get_the_title();
  688.             $thumbnail = get_thumbnail($width,$height,'',$titletext,$titletext,false,'Entry');
  689.             $thumb = $thumbnail["thumb"];
  690.         ?>
  691.         <a href="<?php the_permalink(); ?>">
  692.             <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, ''); ?>
  693.             <span class="price-tag"><span>€</span><?php if ( ( $myprice = get_post_meta( $post->ID, 'myprice', true) ) && $myprice <> '' ){echo $myprice;} ?></span>
  694.         </a>
  695.         <h4 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
  696.         <div class="et-links clearfix">
  697.                <a href="<?php if ( ( $producturl = get_post_meta( $post->ID, 'producturl', true) ) && $producturl <> '' ){ echo $producturl;}?>" class="add-to-cart"><?php esc_html_e('Cart','Boutique'); ?></a>
  698.  
  699.             <a href="<?php the_permalink(); ?>" class="more-info"><?php esc_html_e('Info','Boutique'); ?></a>
  700.         </div> <!-- end .et-links -->
  701.         <?php do_action('boutique_product_entry'); ?>
  702.     </div> <!-- end .main-product -->
  703.     <?php if ( $post_iterator % 4 == 0 ) echo '<div class="clear"></div>'; ?>
  704. <?php
  705. }
  706. endif;
  707.  
  708. if ( ! function_exists( 'boutique_display_blogpost' ) ) :
  709. function boutique_display_blogpost(){
  710.     global $post;
  711.    
  712.     $thumb = '';
  713.     $width = 249;
  714.     $height = 244;
  715.     $classtext = 'blog-thumb';
  716.     $titletext = get_the_title();
  717.     $thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Blog');
  718.     $thumb = $thumbnail["thumb"];
  719.    
  720.     if ( is_category() ){ ?>
  721.         <div class="blogpost clearfix">
  722.             <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
  723.             <?php get_template_part('includes/postinfo','blog'); ?>
  724.     <?php }
  725.    
  726.     if( $thumb <> '' && ( ( get_option('boutique_thumbnails_index') == 'on' && is_category() ) || ( get_option('boutique_thumbnails') == 'on' && is_single() ) ) ) { ?>
  727.         <div class="post-thumbnail">
  728.             <?php if ( is_category() ) echo '<a href="' . get_permalink() . '">'; ?>
  729.                 <?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
  730.             <?php if ( is_category() ) echo '</a>'; ?>
  731.         </div>  <!-- end .post-thumbnail -->
  732.     <?php }
  733.    
  734.     if ( is_category() ) {
  735.             if (get_option('boutique_blog_style') == 'on') the_content(''); else { ?>
  736.                 <p><?php truncate_post(500); ?></p>
  737.             <?php } ?>
  738.        
  739.             <a href="<?php the_permalink(); ?>" class="read-more"><span><?php _e('Read More','Boutique'); ?></span></a>
  740.         </div>  <!-- end .blogpost -->
  741.     <?php }
  742. }
  743. endif;
  744.  
  745. if ( ! function_exists( 'et_is_blog_post' ) ) :
  746. function et_is_blog_post( $blog_categories ){
  747.     global $post;
  748.    
  749.     $categories = get_the_category();
  750.     foreach ( $categories as $category ){
  751.         if ( in_array( $category->cat_ID, $blog_categories ) ) return true;
  752.     }
  753.    
  754.     return false;
  755. }
  756. endif;
  757.  
  758. if ( ! function_exists( 'boutique_is_single_blog_post' ) ) :
  759. function boutique_is_single_blog_post(){
  760.     #detect if single post should have a Blog layout
  761.     global $boutique_active_plugin_name, $wp_query;
  762.    
  763.     if ( 'wp_ecommerce' == $boutique_active_plugin_name && isset( $wp_query->is_product ) && $wp_query->is_product ) return false;
  764.     if ( 'wp_ecommerce' == $boutique_active_plugin_name ) return true;
  765.    
  766.     return ( get_option('boutique_blog_categories') !== false && et_is_blog_post(get_option('boutique_blog_categories')) );
  767. }
  768. endif;
  769.  
  770.  
  771. // RATING Functions //
  772.  
  773. add_action( 'admin_enqueue_scripts', 'upload_etsettings_scripts' );
  774. function upload_etsettings_scripts( $hook_suffix ) {
  775.     if ( in_array( $hook_suffix, array('post.php','post-new.php') ) ) {
  776.         wp_enqueue_script('metadata', get_bloginfo('template_directory') . '/js/jquery.MetaData.js', array('jquery'), '3.13', true);
  777.         wp_enqueue_script('rating', get_bloginfo('template_directory') . '/js/jquery.rating.pack.js', array('jquery'), '3.13', true);
  778.         wp_enqueue_style('et-rating', get_bloginfo('template_directory') . '/css/jquery.rating.css');
  779.     }
  780. }
  781.  
  782. add_action('wp_enqueue_scripts', 'et_add_comment_rating');
  783. function et_add_comment_rating(){
  784.     #integrate jquery rating files into single post pages ( frontend )
  785.     if ( is_single() ) {
  786.         wp_enqueue_script('metadata', get_bloginfo('template_directory') . '/js/jquery.MetaData.js', array('jquery'), '3.13', true);
  787.         wp_enqueue_script('rating', get_bloginfo('template_directory') . '/js/jquery.rating.pack.js', array('jquery'), '3.13', true);
  788.         wp_enqueue_style('et-rating', get_bloginfo('template_directory') . '/css/jquery.rating.css');
  789.     }
  790. }
  791.  
  792. add_action('comment_post','et_add_rating_commentmeta', 10, 2);
  793. function et_add_rating_commentmeta( $comment_id, $comment_approved ){
  794.     #when user adds a comment, check if it's approved
  795.    
  796.     $comment_rating = ( isset($_POST['et_star']) ) ? $_POST['et_star'] : 0;
  797.     add_comment_meta($comment_id,'et_comment_rating',$comment_rating);
  798.     if ( $comment_approved == 1 ) {
  799.         $comment_info = get_comment($comment_id);      
  800.         et_update_post_user_rating( $comment_info->comment_post_ID );
  801.     }
  802. }
  803.  
  804. add_action('et-comment-meta','et_show_comment_rating');
  805. function et_show_comment_rating( $comment_id ){
  806.     #displays user comment rating on single post page ( frontend )
  807.    
  808.     if ( boutique_is_single_blog_post() ) return;
  809.    
  810.     $user_comment_rating = get_comment_meta($comment_id,'et_comment_rating',true) ? get_comment_meta($comment_id,'et_comment_rating',true) : 0;            
  811.     if ( $user_comment_rating <> 0 ) { ?>
  812.         <div class="review-rating">
  813.             <div class="review-score" style="width: <?php echo esc_attr(et_get_star_rating($user_comment_rating)); ?>px;"></div>
  814.         </div>
  815.  
  816.         <div class="clear"></div>
  817.     <?php }
  818. }
  819.  
  820. add_filter('comment_form_field_comment','et_boutique_comment_form_add_rating');
  821. function et_boutique_comment_form_add_rating( $comment_field ){
  822.     if ( is_page() || boutique_is_single_blog_post() ) return $comment_field;
  823.    
  824.     $rating_field = '<div id="et-rating" class="clearfix">
  825.                         <span id="choose_rating">' . esc_html__('Rating','Boutique') . '</span>
  826.                             <div class="clearfix">';
  827.    
  828.     for ( $increment = 0.5; $increment <= 5; $increment = $increment+0.5  ) {
  829.         $rating_field .= '<input name="et_star" type="radio" class="star {half:true}" value="' . $increment . '" />';
  830.     }
  831.    
  832.     $rating_field .= '      </div> <!-- end .clearfix -->
  833.                        
  834.                     </div> <!-- end #et-rating -->';
  835.    
  836.     return $rating_field . $comment_field;
  837. }
  838.  
  839. if ( ! function_exists( 'et_get_post_user_rating' ) ){
  840.     function et_get_post_user_rating( $post_id ){
  841.         #calculates user (comments) rating for the post
  842.         $approved_comments = et_get_approved_comments( $post_id );
  843.         if ( empty($approved_comments) ) return 0;
  844.        
  845.         $user_rating = 0;
  846.         $approved_comments_number = count($approved_comments);
  847.        
  848.         foreach ( $approved_comments as $comment ) {
  849.             $comment_rating = get_comment_meta($comment->comment_ID,'et_comment_rating',true) ? get_comment_meta($comment->comment_ID,'et_comment_rating',true) : 0;
  850.             if ( $comment_rating == 0 ) $approved_comments_number--;
  851.            
  852.             $user_rating += $comment_rating;
  853.         }
  854.        
  855.         $result = ( $user_rating <> 0 ) ? round( $user_rating / $approved_comments_number, 2 ) : 0;
  856.         # save user rating to the post meta
  857.         if ( !get_post_meta($post_id,'_et_boutique_comments_rating',true) ) update_post_meta($post_id,'_et_boutique_comments_rating',$result);
  858.        
  859.         return $result;
  860.     }
  861. }
  862.  
  863. if ( ! function_exists( 'et_update_post_user_rating' ) ){
  864.     function et_update_post_user_rating( $post_id ){
  865.         #update (recalculate) user (comments) rating for the post
  866.         $new_comments_rating = et_get_post_user_rating( $post_id );
  867.        
  868.         if ( get_post_meta($post_id,'_et_boutique_comments_rating',true) <> $new_comments_rating )
  869.             update_post_meta($post_id,'_et_boutique_comments_rating',$new_comments_rating);
  870.     }
  871. }
  872.  
  873. add_action('wp_set_comment_status','et_comment_status_changed', 10, 2);
  874. function et_comment_status_changed($comment_id, $comment_status){
  875.     $comment_info = get_comment( $comment_id );    
  876.     et_update_post_user_rating( $comment_info->comment_post_ID );
  877. }
  878.  
  879. if ( ! function_exists( 'et_get_approved_comments' ) ){
  880.     function et_get_approved_comments($post_id) {
  881.         global $wpdb;
  882.         return $wpdb->get_results($wpdb->prepare("SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post_id));
  883.     }
  884. }
  885.  
  886. if ( ! function_exists( 'et_get_star_rating' ) ){
  887.     function et_get_star_rating( $rating ) {
  888.         #round to 0.5, 1.5, 2.5 etc. * 16px ( star sprite image )
  889.         $width_value = ( round( $rating*2 ) / 2 ) * 16;
  890.        
  891.         return $width_value;
  892.     }
  893. }
  894.  
  895. function et_add_rating_custom_panel(){
  896.     add_meta_box("et_cp_rating_meta", "Rating Settings", "et_cp_rating_meta", "post", "normal", "high");
  897.     add_meta_box("et_cp_rating_meta", "Rating Settings", "et_cp_rating_meta", "wpsc-product", "normal", "high");
  898. }
  899. add_action("admin_init", "et_add_rating_custom_panel");
  900.  
  901. function et_cp_rating_meta() {
  902.     global $post;
  903.        
  904.     $et_boutique_features_rating = get_post_meta($post->ID,'_et_boutique_rating',true) ? get_post_meta($post->ID,'_et_boutique_rating',true) : 0;
  905.     do_action( 'et_ratings_get_features' ); ?>
  906.    
  907.     <div id="et_custom_settings" style="margin: 13px 0 17px 4px;">         
  908.         <div class="et_setting" style="margin: 13px 0 26px 4px; overflow: hidden;">
  909.             <p style="float: left;"><label for="et_feature_name" style="color: #000; font-weight: bold;"> Item Rating: </label></p>
  910.            
  911.             <p style="float: left;">
  912.                 <?php for ( $increment = 0.5; $increment <= 5; $increment = $increment+0.5  ) { ?>
  913.                     <?php
  914.                         if ( $et_boutique_features_rating[0] == $increment ) $checked = ' checked="checked"';
  915.                         else $checked = '';
  916.                     ?>
  917.                     <input name="et_star" type="radio" class="star {half:true}" value="<?php echo $increment; ?>"<?php echo $checked; ?> />
  918.                 <?php } ?>
  919.             </p>
  920.         </div>
  921.     </div> <!-- #et_custom_settings -->
  922.        
  923.     <?php
  924. }
  925.  
  926. add_action('save_post', 'et_cp_save_ratings');
  927. function et_cp_save_ratings($post_id){
  928.     global $pagenow;
  929.    
  930.     if ( 'post.php' != $pagenow ) return $post_id;
  931.            
  932.     if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
  933.         return $post_id;
  934.    
  935.     global $post;
  936.     $rating_number = 0;
  937.     $features_number = 0;
  938.    
  939.     $rating1 = isset( $_POST["et_star"] ) ? $_POST["et_star"] : 0;
  940.     $features_rating = apply_filters( 'et_boutique_features_save', array($rating1) );
  941.    
  942.     foreach ( $features_rating as $rating ) {
  943.         #actual number of features used in the post
  944.         if ( $rating != 0 ) $features_number++;
  945.     }
  946.     for ( $i=1; $i<=$features_number; $i++ ){
  947.         $rating_number += $features_rating[$i-1];
  948.     }
  949.    
  950.     $post_rating = $features_number <> 0 ? round( $rating_number / $features_number, 2 ) : 0;
  951.    
  952.     if ( get_post_meta( $post_id, "_et_boutique_rating", true ) == $post_rating ) return $post_id;
  953.     else {
  954.         update_post_meta( $post_id, "_et_boutique_rating", $features_rating );
  955.         update_post_meta( $post_id, "_et_boutique_user_rating", $post_rating );
  956.     }
  957.    
  958.     do_action( 'et_boutique_save_features' );
  959. }
  960.  
  961. if ( ! function_exists( 'et_boutique_display_rating' ) ) :
  962. function et_boutique_display_rating(){
  963.     global $post;
  964.     $et_author_rating = get_post_meta($post->ID,'_et_boutique_user_rating',true) ? get_post_meta($post->ID,'_et_boutique_user_rating',true) : 0;
  965.     $et_comments_rating = get_post_meta($post->ID,'_et_comments_rating',true) ? get_post_meta($post->ID,'_et_comments_rating',true) : et_get_post_user_rating($post->ID);
  966.    
  967.     if ( $et_author_rating <> 0 ) { ?>
  968.         <div class="rating-container">
  969.             <div class="rating-inner clearfix">
  970.                 <span><?php esc_html_e('Author','Boutique'); ?></span>
  971.                 <div class="review-rating">
  972.                     <div class="review-score" style="width: <?php echo esc_attr(et_get_star_rating($et_author_rating)); ?>px;"></div>
  973.                 </div>
  974.             </div> <!-- end .rating-inner -->
  975.         </div> <!-- end .rating-container -->
  976.     <?php }
  977.    
  978.     if ( $et_comments_rating <> 0 ) { ?>
  979.         <div class="rating-container">
  980.             <div class="rating-inner clearfix">
  981.                 <span><?php esc_html_e('Users','Boutique'); ?></span>
  982.                 <div class="review-rating">
  983.                     <div class="review-score" style="width: <?php echo esc_attr(et_get_star_rating($et_comments_rating)); ?>px;"></div>
  984.                 </div>
  985.             </div> <!-- end .rating-inner -->
  986.         </div> <!-- end .rating-container -->
  987.     <?php }
  988. }
  989. endif;
  990.  
  991.  
  992. add_filter('comments_open','wp_ecommerce_force_comments',10,2);
  993. function wp_ecommerce_force_comments( $open, $post_id ){
  994.     $post_info = get_post($post_id);
  995.     if ( $post_info->post_type == 'wpsc-product' ) return true;
  996.     else return $open;
  997. }
  998.  
  999. add_action( 'admin_init', 'et_remove_wp_ecommerce_notification' );
  1000. function et_remove_wp_ecommerce_notification(){
  1001.     global $boutique_active_plugin_name;
  1002.     if ( 'wp_ecommerce' == $boutique_active_plugin_name ){
  1003.         remove_action( 'admin_notices', 'wpsc_theme_upgrade_notice' );
  1004.     }
  1005. }
  1006.  
  1007. if ( ! function_exists( 'et_list_pings' ) ){
  1008.     function et_list_pings($comment, $args, $depth) {
  1009.         $GLOBALS['comment'] = $comment; ?>
  1010.         <li id="comment-<?php comment_ID(); ?>"><?php comment_author_link(); ?> - <?php comment_excerpt(); ?>
  1011.     <?php }
  1012. }
  1013. // http://www.gravityhelp.com/forums/topic/change-option-value?replies=19#post-103945
  1014. // this code will apply to form 1 only
  1015. add_action('gform_pre_submission_filter_1', 'strip_pricing');
  1016. function strip_pricing($form) {
  1017.         $field_pair = array('input_1' => 'input_57',    // envia el Desayuno elegido al ZOHO
  1018.                             'input_2' => 'input_58',    // envia el Nº de personas  al ZOHO
  1019.                             'input55' => 'input_59',    // envia los extras al ZOHO
  1020.                             'input_27' => 'input_60',   // envia forma de pago al ZOHO
  1021.                             'input_52' => 'input_61');  // envia la población al ZOHO
  1022.                            
  1023.         // define the separator one time
  1024.         $needle   = '|';
  1025.        
  1026.         // loop through all the field pairs
  1027.         // the unmodified value is stored in $_POST[$original]
  1028.         // and after modification it will be assigned to $_POST[$hidden]
  1029.         foreach ($array as $original => $hidden) {
  1030.             $haystack = $_POST[$original];
  1031.             $result = substr($haystack, 0, strpos($haystack, $needle));
  1032.             $_POST[$hidden] = $result;
  1033.         }
  1034.  
  1035.         // return the form
  1036.         return $form;
  1037. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement