示例#1
0
 private static function render_pricing_columns($columns, $blog_id = false, $echo = false)
 {
     global $psts;
     $content = '';
     $periods = (array) $psts->get_setting('enabled_periods');
     $show_periods = 2 <= count($periods) ? true : false;
     $show_first_column = $show_periods && 'option2' != $psts->get_setting('pricing_table_period_position', 'option1');
     $total_columns = $show_first_column ? count($columns) : count($columns) - 1;
     $total_width = 100.0;
     $total_width -= 6.0;
     // account for extra space around featured plan
     $column_width = $total_width / $total_columns;
     $feature_width = $column_width + 6.0;
     $normal_style = 'width: ' . $column_width . '%; ';
     $feature_style = 'width: ' . $feature_width . '%; ';
     $column_keys = array_keys($columns[0]);
     $show_pricing_table = in_array('title', $column_keys);
     $show_feature_table = in_array('sub_title', $column_keys);
     $show_buy_buttons = in_array('button', $column_keys);
     $add_coupon = in_array('coupon', $column_keys);
     //			$show_buy_buttons = false;
     foreach ($columns as $key => $column) {
         $style = true === $column['featured'] ? $feature_style : $normal_style;
         $col_class = true === $column['featured'] ? ' featured' : '';
         $level_id = isset($column['level_id']) ? $column['level_id'] : 0;
         // Has a chosen plan been given? Note: Period should already be set.
         if (!empty(self::$selected_level) && 0 != $level_id) {
             $col_class = $level_id == (int) self::$selected_level ? $col_class . ' chosen-plan' : $col_class;
         }
         // Remove the 0 column
         $override = '';
         if (empty($level_id)) {
             $override = $show_first_column ? '' : 'hidden';
             $col_class .= ' ' . $override;
             //continue;
         }
         $content .= '<ul class="pricing-column psts-level-' . esc_attr($level_id) . ' ' . esc_attr($col_class) . '" style="' . esc_attr($style) . '">';
         if ($show_pricing_table) {
             if (empty($column['title'])) {
                 $content .= '<li class="title no-title"></li>';
             } else {
                 $content .= '<li class="title">' . ProSites::filter_html($column['title']) . '</li>';
             }
             $content .= '<li class="summary ' . $override . '">' . ProSites::filter_html($column['summary']) . '</li>';
         }
         if ($show_feature_table) {
             $features_class = $show_pricing_table ? '' : 'no-header';
             if (empty($column['sub_title'])) {
                 $content .= '<li class="sub-title no-title ' . $features_class . '"></li>';
             } else {
                 $content .= '<li class="sub-title ' . $features_class . '">' . ProSites::filter_html($column['sub_title']) . '</li>';
             }
             $content .= '<li><ul class="feature-section">';
             foreach ($column['features'] as $index => $feature) {
                 $alt = isset($feature['alt']) && true == $feature['alt'] ? 'alternate' : '';
                 $content .= '<li class="feature feature-' . $index . ' ' . $alt . '"><div class="feature-content">';
                 if (isset($feature['name']) && !empty($feature['name'])) {
                     $content .= '<div class="feature-name">' . ProSites::filter_html($feature['name']) . '</div>';
                 }
                 if (isset($feature['indicator']) && !empty($feature['indicator'])) {
                     $content .= '<div class="feature-indicator">' . ProSites::filter_html($feature['indicator']) . '</div>';
                 }
                 if (isset($feature['text']) && !empty($feature['text'])) {
                     $content .= '<div class="feature-text">' . ProSites::filter_html($feature['text']) . '</div>';
                 }
                 $content .= '</div></li>';
             }
             $content .= '</ul></li>';
         }
         if ($show_buy_buttons) {
             if (empty($column['button'])) {
                 if ($add_coupon && 'option1' == $psts->get_setting('pricing_table_coupon_position', 'option1')) {
                     $content .= '<li class="coupon">';
                     $content .= '<div class="coupon-box">';
                     $content .= '<input type="text" name="apply-coupon" placeholder="' . __('Enter coupon', 'psts') . '" />';
                     $content .= '<a name="apply-coupon-link" class="apply-coupon-link">' . $column['coupon'] . '</a>';
                     $content .= '</div>';
                     $content .= '</li>';
                 } else {
                     $content .= '<li class="button-box no-button"></li>';
                 }
             } else {
                 $content .= '<li class="button-box">' . $column['button'] . '</li>';
             }
         }
         $content .= '</ul>';
     }
     $allow_free = $psts->get_setting('free_signup');
     $style = 'margin-left: ' . $column_width . '%; ';
     $style .= 'width: ' . (100 - $column_width) . '%; ';
     $content = apply_filters('psts_checkout_before_free', $content, $blog_id, $style);
     if ($allow_free) {
         $content .= self::render_free($style, $blog_id);
     }
     $content = apply_filters('psts_checkout_after_free', $content, $blog_id, $style);
     if ($echo) {
         echo $content;
     }
     return $content;
 }