Esempio n. 1
0
 public static function get_pricing_columns($show_header, $show_features, $show_buy_button = true)
 {
     global $psts;
     $columns = array();
     $level_list = get_site_option('psts_levels');
     //Filter Level List based upon visibility
     if (!empty($level_list) && is_array($level_list)) {
         foreach ($level_list as $level_key => $level) {
             if (empty($level['is_visible']) || $level['is_visible'] == 0) {
                 unset($level_list[$level_key]);
             }
         }
     }
     $total_plans = count($level_list);
     $total_columns = $total_plans + 1;
     $periods = (array) $psts->get_setting('enabled_periods');
     $show_periods = true;
     if (2 > count($periods)) {
         $total_columns = $total_columns - 1;
         $show_periods = false;
     }
     $default_order = array();
     for ($i = 1; $i <= $total_plans; $i++) {
         $default_order[] = $i;
     }
     $default_order = implode(',', $default_order);
     $pricing_levels_order = $psts->get_setting('pricing_levels_order', $default_order);
     $pricing_levels_order = explode(',', $pricing_levels_order);
     //Check if the associated level exists in level list, else remove it
     if (!empty($pricing_levels_order) && is_array($pricing_levels_order)) {
         foreach ($pricing_levels_order as $key => $level) {
             if (empty($level_list[$level])) {
                 unset($pricing_levels_order[$key]);
             }
         }
     }
     // Now add the levels that got missed at the end
     foreach (array_keys($level_list) as $level) {
         if (!in_array($level, $pricing_levels_order)) {
             array_push($pricing_levels_order, $level);
         }
     }
     // Initialize all columns
     for ($i = 0; $i < $total_columns; $i++) {
         $columns[] = array();
     }
     $col_count = 0;
     if ($show_header) {
         if ($show_periods) {
             $columns[$col_count]['title'] = '';
             $columns[$col_count]['summary'] = self::get_header_details();
             $col_count += 1;
         } else {
             if ($show_features) {
                 $columns[$col_count]['title'] = '';
                 $columns[$col_count]['summary'] = '';
                 $col_count += 1;
             }
         }
         foreach ($pricing_levels_order as $level) {
             $columns[$col_count] = self::get_header_details($level);
             $columns[$col_count]['level_id'] = $level;
             $col_count += 1;
         }
     }
     if ($show_features) {
         // Set first row
         $col_count = 0;
         $row_count = 0;
         $columns[$col_count]['alt'] = $row_count % 2 != 0;
         $columns[$col_count]['sub_title'] = __('Compare Features', 'psts');
         $columns[$col_count]['features'] = array();
         $col_count += 1;
         foreach ($pricing_levels_order as $level) {
             $columns[$col_count]['alt'] = $row_count % 2 != 0;
             $columns[$col_count]['sub_title'] = '';
             $columns[$col_count]['features'] = array();
             $col_count += 1;
         }
         $row_count += 1;
         $feature_table = ProSites_Model_Pricing::load_feature_settings();
         $feature_order = $feature_table['feature_order'];
         $feature_order = explode(',', $feature_order);
         $feature_order = array_filter($feature_order);
         $enabled_modules = $psts->get_setting('modules_enabled', array());
         foreach ($feature_order as $index => $feature_key) {
             if (empty($feature_table[$feature_key]['visible'])) {
                 continue;
             }
             if (isset($feature_table[$feature_key]['module']) && !in_array($feature_table[$feature_key]['module'], $enabled_modules)) {
                 continue;
             }
             $col_count = 0;
             $columns[$col_count]['features'][$index]['name'] = $feature_table[$feature_key]['description'];
             $columns[$col_count]['features'][$index]['alt'] = $row_count % 2 != 0;
             $col_count += 1;
             foreach ($pricing_levels_order as $level) {
                 $columns[$col_count]['features'][$index]['indicator'] = self::get_feature_indicator($feature_table[$feature_key], $level);
                 $columns[$col_count]['features'][$index]['text'] = isset($feature_table[$feature_key]['levels'][$level]) ? $feature_table[$feature_key]['levels'][$level]['text'] : '';
                 $columns[$col_count]['features'][$index]['alt'] = $row_count % 2 != 0;
                 $col_count += 1;
             }
             $row_count += 1;
         }
     }
     if ($show_buy_button) {
         $col_count = 0;
         if ($show_header) {
             if ($show_periods || $show_features) {
                 $columns[$col_count]['button'] = '';
                 $col_count += 1;
             }
             foreach ($pricing_levels_order as $level) {
                 if (!self::$new_signup) {
                     $columns[$col_count]['button'] = '<button class="choose-plan-button">' . __('Choose Plan', 'psts') . '</button>';
                 } else {
                     $columns[$col_count]['button'] = '<button class="choose-plan-button register-new">' . __('Sign Up', 'psts') . '</button>';
                 }
                 $col_count += 1;
             }
         }
     }
     $coupons_enabled = $psts->get_setting('coupons_enabled');
     $coupons_enabled = 'enabled' === $coupons_enabled ? true : false;
     if ($coupons_enabled) {
         $col_count = 0;
         $columns[$col_count]['coupon'] = __('Apply coupon', 'psts');
     }
     $featured_level = $psts->get_setting('featured_level');
     foreach ($columns as $key => $column) {
         $columns[$key]['featured'] = $key == $featured_level;
     }
     return $columns;
 }
Esempio n. 2
0
        /**
         * Pricing Table
         *
         * @return string
         */
        public static function render_tab_comparison_table()
        {
            global $psts;
            $active_tab = ProSites_Helper_Tabs_Pricing::get_active_tab();
            ProSites_Helper_Settings::settings_header($active_tab);
            $plans_table_enabled = $psts->get_setting('comparison_table_enabled');
            $checked = 'enabled' == $plans_table_enabled ? 'enabled' : 'disabled';
            $level_list = get_site_option('psts_levels');
            $last_level = is_array($level_list) ? count($level_list) : 0;
            $table_settings = ProSites_Model_Pricing::load_feature_settings();
            $enabled_modules = $psts->get_setting('modules_enabled', array());
            ?>
			<input type="hidden" name="pricing_settings" value="<?php 
            echo esc_attr($active_tab['tab_key']);
            ?>
"/>
			<table class="form-table">
				<tr>
					<th scope="row"><?php 
            _e('Enable Feature Table', 'psts');
            ?>
</th>
					<td>
						<input type="checkbox" name="psts[comparison_table_enabled]" value="1" <?php 
            checked($checked, 'enabled');
            ?>
 />
					</td>
				</tr>

				<!-- MODULE TABLE -->
				<tr id="module-comparison-table">
					<td colspan="2">
						<div class="form-description"><?php 
            _e('Use the form below to build your feature comparison table.', 'psts');
            ?>
</div>
						<div class="level-select-bar">
							<?php 
            //								_e( 'Select level: ', 'psts' );
            if (is_array($level_list) && count($level_list)) {
                foreach ($level_list as $key => $level) {
                    $class = 1 == $key ? 'selected' : '';
                    echo '<strong><a data-id="' . $key . '" class="' . $class . '">' . $level['name'] . '</a></strong>';
                    if ($key != count($level_list)) {
                        echo ' | ';
                    }
                }
            }
            ?>
							<input type="hidden" name="current_level" value="1"/>
						</div>

						<?php 
            // define the columns to display, the syntax is 'internal name' => 'display name'
            $posts_columns = array('order' => array('title' => __('#', 'psts'), 'width' => '8px', 'class' => ''), 'visible' => array('title' => __('Visible', 'psts'), 'width' => '36px', 'class' => ''), 'name' => array('title' => __('Name', 'psts'), 'small' => __('(double-click to change)'), 'width' => '150px', 'class' => ''), 'description' => array('title' => __('Description', 'psts'), 'small' => __('(double-click to change)'), 'width' => '', 'class' => ''), 'tick_cross' => array('title' => __('Indicator', 'psts'), 'small' => __('(for selected level)', 'psts'), 'width' => '60px', 'class' => 'level-settings'), 'custom' => array('title' => __('Custom text', 'psts'), 'small' => __('(for selected level)', 'psts'), 'width' => '', 'class' => ''));
            $status_array_normal = array('tick' => '&#x2713', 'cross' => '&#x2718');
            $status_array_module = array('module' => __('Level: %s', 'psts'), 'inverse' => __('Invert: %s', 'psts'));
            $hover_actions = array('edit' => __('edit', 'psts'), 'save' => __('change', 'psts'), 'reset' => __('reset', 'psts'));
            $feature_order = array();
            ?>

						<table width="100%" cellpadding="3" cellspacing="3" class="widefat feature-table" id="prosites-level-list">
							<thead>
								<tr>
								<?php 
            foreach ($posts_columns as $col) {
                $style = !empty($col['width']) ? ' style="max-width:' . $col['width'] . '"' : '';
                $class = !empty($col['class']) ? ' class="' . $col['class'] . '"' : '';
                $small = !empty($col['small']) ? ' <small>' . esc_html($col['small']) . '</small>' : '';
                echo '<th scope="col"' . $style . $class . '>' . esc_html($col['title']) . $small . '</th>';
            }
            ?>
								</tr>
							</thead>
							<tbody id="the-list">
								<?php 
            if (!empty($table_settings)) {
                $bgcolor = $class = '';
                $count = 0;
                $modules_array = array();
                foreach ($table_settings as $key => $setting) {
                    if ('modules' == $key || 'feature_order' == $key || 'levels' == $key) {
                        continue;
                    }
                    // don't show disabled modules
                    if (isset($setting['module']) && !in_array($setting['module'], $enabled_modules)) {
                        continue;
                    }
                    $feature_order[] = $key;
                    $count += 1;
                    $level_code = 0;
                    //										$level = $level_list[ $order ];
                    $class = $count % 2 == 0 ? '' : 'alternate';
                    $class .= empty($setting['module']) ? ' custom' : ' module';
                    echo '<tr class="' . $class . ' blog-row" data-level="' . $level_code . '">';
                    foreach ($posts_columns as $column_name => $column) {
                        switch ($column_name) {
                            case 'order':
                                $style = !empty($column['width']) ? ' max-width:' . $column['width'] . ';' : '';
                                ?>
													<td scope="row" style="padding-left: 10px; <?php 
                                echo $style;
                                ?>
" class="order-col">
														<div class="position"><?php 
                                echo $count;
                                ?>
</div>
														<?php 
                                if (isset($setting['custom'])) {
                                    echo '<input type="hidden" name="psts[feature_table][' . $key . '][custom]" value="' . esc_attr($setting['custom']) . '" />';
                                    echo '<a class="delete"><span class="dashicons dashicons-trash"></span></a>';
                                }
                                if (isset($setting['module'])) {
                                    $modules_array[] = $setting['module'];
                                    echo '<input type="hidden" name="psts[feature_table][' . $key . '][module]" value="' . esc_attr($setting['module']) . '" />';
                                    echo '<input type="hidden" name="psts[feature_table][' . $key . '][module_key]" value="' . $key . '" />';
                                }
                                ?>
													</td>
													<?php 
                                break;
                            case 'visible':
                                ?>
													<td scope="row" style="padding-left: 20px;">
														<?php 
                                if (!isset($setting['visible'])) {
                                    $setting['visible'] = false;
                                }
                                ?>
														<input type="checkbox" name="psts[feature_table][<?php 
                                echo $key;
                                ?>
][visible]" value="1" <?php 
                                checked($setting['visible']);
                                ?>
>
													</td>
													<?php 
                                break;
                            case 'name':
                                $original_value = '';
                                if (isset($setting['module']) && !empty($setting['module'])) {
                                    if (method_exists($setting['module'], 'get_name')) {
                                        $original_value = call_user_func($setting['module'] . '::get_name');
                                    }
                                }
                                if (isset($setting['custom']) && !empty($setting['custom'])) {
                                    $original_value = $setting['name'];
                                }
                                ?>
													<td scope="row">
														<div class="text-item"><?php 
                                echo esc_html($setting['name']);
                                ?>
</div>
														<div class="edit-box" style="display:none">
															<input class="editor" type="text" name="psts[feature_table][<?php 
                                echo $key;
                                ?>
][name]" value="<?php 
                                echo esc_html($setting['name']);
                                ?>
"/><br/>
															<span><a class="save-link"><?php 
                                echo esc_html($hover_actions['save']);
                                ?>
</a> <a style="margin-left: 10px;" class="reset-link"><?php 
                                echo esc_html($hover_actions['reset']);
                                ?>
</a></span>
														</div>
														<input type="hidden" value="<?php 
                                echo esc_html($original_value);
                                ?>
"/>
													</td>
													<?php 
                                break;
                            case 'description':
                                if (isset($setting['module']) && !empty($setting['module'])) {
                                    if (method_exists($setting['module'], 'get_description')) {
                                        $original_value = call_user_func($setting['module'] . '::get_description');
                                    }
                                }
                                if (isset($setting['custom']) && !empty($setting['custom'])) {
                                    $original_value = $setting['description'];
                                }
                                ?>
													<td scope="row">
														<div class="text-item"><?php 
                                echo esc_html($setting['description']);
                                ?>
</div>
														<div class="edit-box" style="display:none">
															<textarea class="editor" type="text" name="psts[feature_table][<?php 
                                echo $key;
                                ?>
][description]"><?php 
                                echo esc_html($setting['description']);
                                ?>
</textarea><br/>
															<span><a class="save-link"><?php 
                                echo esc_html($hover_actions['save']);
                                ?>
</a> <a style="margin-left: 10px;" class="reset-link"><?php 
                                echo esc_html($hover_actions['reset']);
                                ?>
</a></span>
														</div>
														<input type="hidden" value="<?php 
                                echo esc_html($original_value);
                                ?>
"/>
													</td>
													<?php 
                                break;
                            case 'tick_cross':
                                ?>
													<td scope="row" class="<?php 
                                echo esc_attr($column['class']);
                                ?>
">
														<?php 
                                // We're working with level based settings
                                if (is_array($level_list) && count($level_list)) {
                                    foreach ($level_list as $level_id => $level) {
                                        if (!empty($setting['levels'][$level_id]['status']) && !is_array($setting['levels'][$level_id]['status'])) {
                                            $status = $setting['levels'][$level_id]['status'];
                                            $level_status = '';
                                            if (isset($setting['module']) && method_exists($setting['module'], 'get_level_status')) {
                                                $level_status = call_user_func($setting['module'] . '::get_level_status', $level_id);
                                            }
                                            if (!empty($setting['module'])) {
                                                $chosen_array = $status_array_module;
                                                $invert = 'tick' == $level_status ? 'cross' : 'tick';
                                                $chosen_array['module'] = sprintf($chosen_array['module'], $status_array_normal[$level_status]);
                                                $chosen_array['inverse'] = sprintf($chosen_array['inverse'], $status_array_normal[$invert]);
                                            } else {
                                                $chosen_array = $status_array_normal;
                                            }
                                            if (!empty($setting['module'])) {
                                                //																	echo '*hide* ' . $setting['levels'][ $key ]['status'];
                                            } else {
                                                //																	echo '*hide* Not a module';
                                            }
                                            ?>
																	<!-- Change name... -->
																	<select class="chosen" name="psts[feature_table][<?php 
                                            echo $key;
                                            ?>
][levels][<?php 
                                            echo $level_id;
                                            ?>
][status]" data-level="level-<?php 
                                            echo $level_id;
                                            ?>
[status]">
																    <?php 
                                            foreach ($chosen_array as $item_key => $item) {
                                                echo '<option value="' . esc_attr($item_key) . '" ' . selected($status, $item_key) . '>' . $item . '</option>';
                                            }
                                            echo '<option value="none" ' . selected($status, 'none') . '>' . __('None', 'psts') . '</option>';
                                            ?>
																	</select>
																<?php 
                                        } elseif (isset($setting['levels'][$level_id]['status']) && is_array($setting['levels'][$level_id]['status'])) {
                                            //																	$new_status = $setting['levels'][ $level_id ]['status'];
                                            //																	if( method_exists( $setting[ 'module' ], 'get_level_status' ) ) {
                                            //																		$new_status = call_user_func( $setting[ 'module' ] . '::get_level_status', $level_id );
                                            //																		$old_status = $setting['levels'][ $level_id ]['status'] ;
                                            //																		if( 'none' != $old_status['selection'] ) {
                                            //																			$new_status['selection'] = $new_status['value'];
                                            //																		} else {
                                            //																			$new_status['selection'] = 'none';
                                            //																		}
                                            //
                                            //																	}
                                            //																	$keys = array_keys( $new_status );
                                            $keys = array_keys($setting['levels'][$level_id]['status']);
                                            foreach ($keys as $index) {
                                                echo '<input type="hidden" name="psts[feature_table][' . $key . '][levels][' . $level_id . '][status][' . $index . ']" value="' . $setting['levels'][$level_id]['status'][$index] . '" />';
                                            }
                                            ?>

																	<select class="chosen" name="psts[feature_table][<?php 
                                            echo $key;
                                            ?>
][levels][<?php 
                                            echo $level_id;
                                            ?>
][status][selection]">
																    <?php 
                                            $value = $setting['levels'][$level_id]['status']['value'];
                                            $selection = isset($setting['levels'][$level_id]['status']['selection']) ? $setting['levels'][$level_id]['status']['selection'] : $value;
                                            $selected = selected($selection, $value, false);
                                            echo '<option value="' . esc_attr($value) . '" ' . $selected . '>' . esc_html($setting['levels'][$level_id]['status']['display']) . '</option>';
                                            echo '<option value="none" ' . selected($selection, 'none') . '>' . __('None', 'psts') . '</option>';
                                            ?>
																	</select>
																<?php 
                                        }
                                    }
                                }
                                // There are no level specific settings
                                if (isset($setting['active']) && (!empty($setting['active']) || false === $setting['active'])) {
                                    $module_active = true;
                                    if (method_exists($setting['module'], 'is_active')) {
                                        $module_active = call_user_func($setting['module'] . '::is_active');
                                    }
                                    $active_status = array('active' => array('title' => __('Active: %s', 'psts'), 'status' => 'tick'), 'inactive' => array('title' => __('Not active: %s', 'psts'), 'status' => 'cross'));
                                    $value = $setting['active'];
                                    if ($module_active) {
                                        $option = '<option value="module" ' . selected($value, 'module', false) . '>' . sprintf($active_status['active']['title'], $status_array_normal[$active_status['active']['status']]) . '</option>';
                                    } else {
                                        $option = '<option value="module" ' . selected($value, 'module', false) . '>' . sprintf($active_status['inactive']['title'], $status_array_normal[$active_status['inactive']['status']]) . '</option>';
                                    }
                                    ?>
															<select class="chosen" name="psts[feature_table][<?php 
                                    echo $key;
                                    ?>
][active]">
															    <?php 
                                    echo $option;
                                    echo '<option value="none" ' . selected($value, 'none') . '>' . __('None', 'psts') . '</option>';
                                    ?>
																</select>
														<?php 
                                }
                                ?>
													</td>
													<?php 
                                break;
                            case 'custom':
                                ?>
													<td scope="row">
														<?php 
                                $x = '';
                                if (is_array($level_list) && count($level_list)) {
                                    foreach ($level_list as $level_id => $level) {
                                        ?>
																<textarea name="psts[feature_table][<?php 
                                        echo $key;
                                        ?>
][levels][<?php 
                                        echo $level_id;
                                        ?>
][text]"><?php 
                                        echo esc_html($setting['levels'][$level_id]['text']);
                                        ?>
</textarea>
															<?php 
                                    }
                                }
                                ?>
													</td>
													<?php 
                                break;
                        }
                    }
                    ?>
									</tr>
								<?php 
                    $level_keys = array_keys($level_list);
                    $level_keys = implode(',', $level_keys);
                }
                ?>
										<input type="hidden" name="psts[feature_table][modules]" value="<?php 
                echo implode(',', $modules_array);
                ?>
" />
										<input type="hidden" name="psts[feature_table][levels]" value="<?php 
                echo $level_keys;
                ?>
" />
<!--										<input type="hidden" name="psts[pricing_levels_order]" value="--><?php 
                //echo implode( ',' , $pricing_levels_order );
                ?>
<!--" />-->
									<?php 
            } else {
                ?>
									<tr class='no-features'>
										<td colspan="6"><?php 
                _e('No features added yet.', 'psts');
                ?>
</td>
									</tr>
								<?php 
            }
            // end if levels
            ?>

							</tbody>
						</table>

						<?php 
            // Add order...
            $feature_order = implode(',', $feature_order);
            echo '<input type="hidden" name="psts[feature_table][feature_order]" value="' . $feature_order . '" />';
            // Mark for delete...
            echo '<input type="hidden" name="mark_for_delete" value="" />';
            ?>

					</td>
				</tr>


				<tr id="add-feature-box">
					<td colspan="2">
						<strong><?php 
            _e('Add custom feature', 'psts');
            ?>
</strong>
						<table id="add-pricing-feature" class="form-table">
							<thead>
							<tr>
								<th><?php 
            _e('Name', 'psts');
            ?>
</th>
								<th><?php 
            _e('Description', 'psts');
            ?>
</th>
								<th><?php 
            _e('Custom text', 'psts');
            ?>
</th>
								<th></th>
							</tr>
							</thead>
							<tbody>
							<tr class="alternate">
								<td>
									<input name="new-feature-name" type="text"/>
									<input name="new-feature-levels" type="hidden" value="<?php 
            echo count($level_list);
            ?>
"/>
								</td>
								<td><textarea name="new-feature-description"></textarea></td>
								<td><textarea name="new-feature-text"></textarea></td>
								<td><input type="button" class="button" name="add-feature-button" id="add-feature-button" value="Add"/></td>

							</tr>
							</tbody>
						</table>

					</td>
				</tr>

			</table>
			<?php 
            //			$gateway = new ProSites_Gateway_2Checkout();
            //			echo $gateway->settings();
        }