PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/dk-pricr-responsive-pricing-table/rpt.php

https://gitlab.com/iamgraeme/royalmile
PHP | 420 lines | 295 code | 86 blank | 39 comment | 80 complexity | cb9068035c54539e0449a0f8374b61af MD5 | raw file
  1. <?php
  2. /**
  3. * Plugin Name: Responsive Pricing Table
  4. * Plugin URI: http://wpdarko.com/items/responsive-pricing-table-pro/
  5. * Description: A responsive, easy and elegant way to present your offer to your visitors. Just create a new pricing table (custom type) and copy-paste the shortcode into your posts/pages. Find help and information on our <a href="http://wpdarko.com/support/">support site</a>. This free version is NOT limited and does not contain any ad. Check out the <a href='http://wpdarko.com/items/responsive-pricing-table-pro/'>PRO version</a> for more great features.
  6. * Version: 4.3
  7. * Author: WP Darko
  8. * Author URI: http://wpdarko.com
  9. * Text Domain: dk-pricr-responsive-pricing-table
  10. * Domain Path: /lang/
  11. * License: GPL2
  12. */
  13. // Loading text domain
  14. add_action( 'plugins_loaded', 'rpt_load_plugin_textdomain' );
  15. function rpt_load_plugin_textdomain() {
  16. load_plugin_textdomain( 'dk-pricr-responsive-pricing-table', FALSE, basename( dirname( __FILE__ ) ) . '/lang/' );
  17. }
  18. // Check for the PRO version
  19. add_action( 'admin_init', 'rpt_free_pro_check' );
  20. function rpt_free_pro_check() {
  21. if (is_plugin_active('responsive-pricing-table-pro/rpt_pro.php')) {
  22. function my_admin_notice(){
  23. echo '<div class="updated">
  24. <p><strong>PRO</strong> version is activated.</p>
  25. </div>';
  26. }
  27. add_action('admin_notices', 'my_admin_notice');
  28. deactivate_plugins(__FILE__);
  29. }
  30. }
  31. /* Enqueue styles */
  32. add_action( 'wp_enqueue_scripts', 'add_rpt_scripts', 99 );
  33. function add_rpt_scripts() {
  34. wp_enqueue_style( 'rpt', plugins_url('css/rpt_style.min.css', __FILE__));
  35. }
  36. /* Enqueue admin styles */
  37. add_action( 'admin_enqueue_scripts', 'add_admin_rpt_style' );
  38. function add_admin_rpt_style() {
  39. global $post_type;
  40. if( 'rpt_pricing_table' == $post_type ) {
  41. wp_enqueue_style( 'rpt', plugins_url('css/admin_de_style.min.css', __FILE__));
  42. wp_enqueue_script( 'rpt', plugins_url('js/rpt_admin.min.js', __FILE__), array( 'jquery' ));
  43. }
  44. }
  45. // Register Pricing Table post type
  46. add_action( 'init', 'register_rpt_type' );
  47. function register_rpt_type() {
  48. $labels = array(
  49. 'name' => __( 'Pricing Tables', 'dk-pricr-responsive-pricing-table' ),
  50. 'singular_name' => __( 'Pricing Table', 'dk-pricr-responsive-pricing-table' ),
  51. 'menu_name' => __( 'Pricing Tables', 'dk-pricr-responsive-pricing-table' ),
  52. 'name_admin_bar' => __( 'Pricing Table', 'dk-pricr-responsive-pricing-table' ),
  53. 'add_new' => __( 'Add New', 'dk-pricr-responsive-pricing-table' ),
  54. 'add_new_item' => __( 'Add New Pricing Table', 'dk-pricr-responsive-pricing-table' ),
  55. 'new_item' => __( 'New Pricing Table', 'dk-pricr-responsive-pricing-table' ),
  56. 'edit_item' => __( 'Edit Pricing Table', 'dk-pricr-responsive-pricing-table' ),
  57. 'view_item' => __( 'View Pricing Table', 'dk-pricr-responsive-pricing-table' ),
  58. 'all_items' => __( 'All Pricing Tables', 'dk-pricr-responsive-pricing-table' ),
  59. 'search_items' => __( 'Search Pricing Tables', 'dk-pricr-responsive-pricing-table' ),
  60. 'not_found' => __( 'No Pricing Tables found.', 'dk-pricr-responsive-pricing-table' ),
  61. 'not_found_in_trash' => __( 'No Pricing Tables found in Trash.', 'dk-pricr-responsive-pricing-table' )
  62. );
  63. $args = array(
  64. 'labels' => $labels,
  65. 'public' => false,
  66. 'publicly_queryable' => false,
  67. 'show_ui' => true,
  68. 'show_in_admin_bar' => false,
  69. 'capability_type' => 'post',
  70. 'has_archive' => false,
  71. 'hierarchical' => false,
  72. 'supports' => array( 'title' ),
  73. 'menu_icon' => 'dashicons-plus'
  74. );
  75. register_post_type( 'rpt_pricing_table', $args );
  76. }
  77. // Customize update messages
  78. add_filter( 'post_updated_messages', 'rpt_updated_messages' );
  79. function rpt_updated_messages( $messages ) {
  80. $post = get_post();
  81. $post_type = get_post_type( $post );
  82. $post_type_object = get_post_type_object( $post_type );
  83. $messages['rpt_pricing_table'] = array(
  84. 1 => __( 'Pricing Table updated.', 'dk-pricr-responsive-pricing-table' ),
  85. 4 => __( 'Pricing Table updated.', 'dk-pricr-responsive-pricing-table' ),
  86. 6 => __( 'Pricing Table published.', 'dk-pricr-responsive-pricing-table' ),
  87. 7 => __( 'Pricing Table saved.', 'dk-pricr-responsive-pricing-table' ),
  88. 10 => __( 'Pricing Table draft updated.', 'dk-pricr-responsive-pricing-table' )
  89. );
  90. if ( $post_type_object->publicly_queryable ) {
  91. $permalink = get_permalink( $post->ID );
  92. $view_link = sprintf( '', '', '' );
  93. $messages[ $post_type ][1] .= $view_link;
  94. $messages[ $post_type ][6] .= $view_link;
  95. $messages[ $post_type ][9] .= $view_link;
  96. $preview_permalink = add_query_arg( 'preview', 'true', $permalink );
  97. $preview_link = sprintf( '', '', '' );
  98. $messages[ $post_type ][8] .= $preview_link;
  99. $messages[ $post_type ][10] .= $preview_link;
  100. }
  101. return $messages;
  102. }
  103. // Add the amazing metabox class (CMB2)
  104. if ( file_exists( dirname( __FILE__ ) . '/inc/cmb2/init.php' ) ) {
  105. require_once dirname( __FILE__ ) . '/inc/cmb2/init.php';
  106. } elseif ( file_exists( dirname( __FILE__ ) . '/inc/CMB2/init.php' ) ) {
  107. require_once dirname( __FILE__ ) . '/inc/CMB2/init.php';
  108. }
  109. // Registering Pricing Table metaboxes
  110. add_action( 'cmb2_init', 'rpt_register_group_metabox' );
  111. require_once('inc/rpt-metaboxes.php');
  112. // Shortcode column
  113. add_action( 'manage_rpt_pricing_table_posts_custom_column' , 'rpt_custom_columns', 10, 2 );
  114. add_filter('manage_rpt_pricing_table_posts_columns' , 'add_rpt_pricing_table_columns');
  115. function rpt_custom_columns( $column, $post_id ) {
  116. switch ( $column ) {
  117. case 'dk_shortcode' :
  118. global $post;
  119. $slug = '' ;
  120. $slug = $post->post_name;
  121. $shortcode = '<span style="display:inline-block;border:solid 2px lightgray; background:white; padding:0 8px; font-size:13px; line-height:25px; vertical-align:middle;">[rpt name="'.$slug.'"]</span>';
  122. echo $shortcode;
  123. break;
  124. }
  125. }
  126. function add_rpt_pricing_table_columns($columns) { return array_merge($columns, array('dk_shortcode' => 'Shortcode'));}
  127. // Display Shortcode
  128. add_shortcode("rpt", "rpt_sc");
  129. function rpt_sc($atts) {
  130. extract(shortcode_atts(array(
  131. "name" => ''
  132. ), $atts));
  133. $output2 = '';
  134. global $post;
  135. $args = array('post_type' => 'rpt_pricing_table', 'name' => $name);
  136. $custom_posts = get_posts($args);
  137. foreach($custom_posts as $post) : setup_postdata($post);
  138. $entries = get_post_meta( $post->ID, '_rpt_plan_group', true );
  139. $nb_entries = count($entries);;
  140. // Forcing original fonts?
  141. $original_font = get_post_meta( $post->ID, '_rpt_original_font', true );
  142. if ($original_font == true){
  143. $ori_f = 'rpt_plan_ori';
  144. } else {
  145. $ori_f = '';
  146. }
  147. // Get font sizes
  148. $title_fontsize = get_post_meta( $post->ID, '_rpt_title_fontsize', true );
  149. if ($title_fontsize == 'small') {
  150. $title_fs_class = ' rpt_sm_title';
  151. } else if ($title_fontsize == 'tiny') {
  152. $title_fs_class = ' rpt_xsm_title';
  153. } else {
  154. $title_fs_class = '';
  155. }
  156. $subtitle_fontsize = get_post_meta( $post->ID, '_rpt_subtitle_fontsize', true );
  157. if ($subtitle_fontsize == 'small') {
  158. $subtitle_fs_class = ' rpt_sm_subtitle';
  159. } else if ($subtitle_fontsize == 'tiny') {
  160. $subtitle_fs_class = ' rpt_xsm_subtitle';
  161. } else {
  162. $subtitle_fs_class = '';
  163. }
  164. $description_fontsize = get_post_meta( $post->ID, '_rpt_description_fontsize', true );
  165. if ($description_fontsize == 'small') {
  166. $description_fs_class = ' rpt_sm_description';
  167. } else {
  168. $description_fs_class = '';
  169. }
  170. $price_fontsize = get_post_meta( $post->ID, '_rpt_price_fontsize', true );
  171. if ($price_fontsize == 'small') {
  172. $price_fs_class = ' rpt_sm_price';
  173. } else if ($price_fontsize == 'tiny') {
  174. $price_fs_class = ' rpt_xsm_price';
  175. } else if ($price_fontsize == 'supertiny') {
  176. $price_fs_class = ' rpt_xxsm_price';
  177. } else {
  178. $price_fs_class = '';
  179. }
  180. $recurrence_fontsize = get_post_meta( $post->ID, '_rpt_recurrence_fontsize', true );
  181. if ($recurrence_fontsize == 'small') {
  182. $recurrence_fs_class = ' rpt_sm_recurrence';
  183. } else {
  184. $recurrence_fs_class = '';
  185. }
  186. $features_fontsize = get_post_meta( $post->ID, '_rpt_features_fontsize', true );
  187. if ($features_fontsize == 'small') {
  188. $features_fs_class = ' rpt_sm_features';
  189. } else {
  190. $features_fs_class = '';
  191. }
  192. $button_fontsize = get_post_meta( $post->ID, '_rpt_button_fontsize', true );
  193. if ($button_fontsize == 'small') {
  194. $button_fs_class = ' rpt_sm_button';
  195. } else {
  196. $button_fs_class = '';
  197. }
  198. // Opening rpt_pricr container
  199. $output2 .= '<div id="rpt_pricr" class="rpt_plans rpt_'.$nb_entries .'_plans rpt_style_basic">';
  200. // Opening rpt_pricr inner
  201. $output2 .= '<div class="'. $title_fs_class . $subtitle_fs_class . $description_fs_class . $price_fs_class . $recurrence_fs_class . $features_fs_class. $button_fs_class .'">';
  202. if (is_array($entries) || is_object($entries))
  203. foreach ($entries as $key => $plans) {
  204. if (!empty($plans['_rpt_recommended'])){
  205. $is_reco = $plans['_rpt_recommended'];
  206. //Opening plan
  207. if ($is_reco == true ){
  208. $reco = '<img class="rpt_recommended" src="' . plugins_url('img/rpt_recommended.png', __FILE__) . '"/>';
  209. $reco_class = 'rpt_recommended_plan';
  210. } else if ($is_reco == false ) {
  211. $reco = '';
  212. $reco_class = '';
  213. }
  214. } else {
  215. $reco = '';
  216. $reco_class = '';
  217. }
  218. if (empty($plans['_rpt_custom_classes'])){
  219. $plans['_rpt_custom_classes'] = '';
  220. }
  221. $output2 .= '<div class="rpt_plan '.$ori_f.' rpt_plan_' . $key . ' ' . $reco_class . ' ' . $plans['_rpt_custom_classes'] . '">';
  222. // Title
  223. if (!empty($plans['_rpt_title'])){
  224. $output2 .= '<div class="rpt_title rpt_title_' . $key . '">';
  225. if (!empty($plans['_rpt_icon'])){
  226. $output2 .= '<img height=30px width=30px src="' . $plans['_rpt_icon'] . '" class="rpt_icon rpt_icon_' . $key . '"/> ';
  227. }
  228. $output2 .= $plans['_rpt_title'];
  229. $output2 .= $reco . '</div>';
  230. }
  231. // Head
  232. $output2 .= '<div class="rpt_head rpt_head_' . $key . '">';
  233. // Recurrence
  234. if (!empty($plans['_rpt_recurrence'])){
  235. $output2 .= '<div class="rpt_recurrence rpt_recurrence_' . $key . '">' . $plans['_rpt_recurrence'] . '</div>';
  236. }
  237. // Price
  238. if (!empty($plans['_rpt_price'])){
  239. $output2 .= '<div class="rpt_price rpt_price_' . $key . '">';
  240. if (!empty($plans['_rpt_free'])){
  241. if ($plans['_rpt_free'] == true ){
  242. $output2 .= $plans['_rpt_price'];
  243. } else {
  244. $output2 .= '<span class="rpt_currency"></span>' . $plans['_rpt_price'];
  245. }
  246. } else {
  247. $currency = get_post_meta( $post->ID, '_rpt_currency', true );
  248. if (!empty($currency)){
  249. $output2 .= '<span class="rpt_currency">';
  250. $output2 .= $currency;
  251. $output2 .= '</span>';
  252. }
  253. $output2 .= $plans['_rpt_price'];
  254. }
  255. $output2 .= '</div>';
  256. }
  257. // Subtitle
  258. if (!empty($plans['_rpt_subtitle'])){
  259. $output2 .= '<div style="color:' . $plans['_rpt_color'] . ';" class="rpt_subtitle rpt_subtitle_' . $key . '">' . $plans['_rpt_subtitle'] . '</div>';
  260. }
  261. // Description
  262. if (!empty($plans['_rpt_description'])){
  263. $output2 .= '<div class="rpt_description rpt_description_' . $key . '">' . $plans['_rpt_description'] . '</div>';
  264. }
  265. // Closing plan head
  266. $output2 .= '</div>';
  267. if (!empty($plans['_rpt_features'])){
  268. $output2 .= '<div class="rpt_features rpt_features_' . $key . '">';
  269. $string = $plans['_rpt_features'];
  270. $stringAr = explode("\n", $string);
  271. $stringAr = array_filter($stringAr, 'trim');
  272. $features = '';
  273. foreach ($stringAr as $feature) {
  274. $features[] .= strip_tags($feature,'<strong></strong><br><br/></br><img><a>');
  275. }
  276. foreach ($features as $small_key => $feature){
  277. if (!empty($feature)){
  278. $check = substr($feature, 0, 2);
  279. if ($check == '-n') {
  280. $feature = substr($feature, 2);
  281. $check_color = '#bbbbbb';
  282. } else {
  283. $check_color = 'black';
  284. }
  285. $output2 .= '<div style="color:' . $check_color . ';" class="rpt_feature rpt_feature_' . $key . '-' . $small_key . '">';
  286. $output2 .= $feature;
  287. $output2 .= '</div>';
  288. }
  289. }
  290. $output2 .= '</div>';
  291. }
  292. if (!empty($plans['_rpt_btn_text'])){
  293. $btn_text = $plans['_rpt_btn_text'];
  294. if (!empty($plans['_rpt_btn_link'])){
  295. $btn_link = $plans['_rpt_btn_link'];
  296. } else { $btn_link = '#'; }
  297. } else {
  298. $btn_text = '';
  299. $btn_link = '#';
  300. }
  301. // Link option
  302. $newcurrentwindow = get_post_meta( $post->ID, '_rpt_open_newwindow', true );
  303. if ($newcurrentwindow == 'newwindow'){
  304. $link_behavior = 'target="_blank"';
  305. } else {
  306. $link_behavior = 'target="_self"';
  307. }
  308. // Check for custom button
  309. if (!empty($plans['_rpt_btn_custom_btn'])){
  310. $output2 .= '<div class="rpt_custom_btn" style="border-bottom-left-radius:5px; border-bottom-right-radius:5px; text-align:center; padding:16px 20px; background-color:'.$plans['_rpt_color'].'">';
  311. $output2 .= do_shortcode($plans['_rpt_btn_custom_btn']);
  312. $output2 .= '</div>';
  313. } else {
  314. // Default footer
  315. if (!empty($plans['_rpt_btn_text'])){
  316. $output2 .= '<a '. $link_behavior .' href="' . do_shortcode($btn_link) . '" style="background:' . $plans['_rpt_color'] . '" class="rpt_foot rpt_foot_' . $key . '">';
  317. } else {
  318. $output2 .= '<a '. $link_behavior .' style="background:' . $plans['_rpt_color'] . '" class="rpt_foot rpt_foot_' . $key . '">';
  319. }
  320. $output2 .= do_shortcode($btn_text);
  321. // Closing default footer
  322. $output2 .= '</a>';
  323. }
  324. $output2 .= '</div>';
  325. }
  326. // Closing rpt_inner
  327. $output2 .= '</div>';
  328. // Closing rpt_container
  329. $output2 .= '</div>';
  330. $output2 .= '<div style="clear:both;"></div>';
  331. endforeach; wp_reset_postdata();
  332. return $output2;
  333. }
  334. ?>