PluginProbe
PixCodes / trunk
PixCodes vtrunk
2.3.9 trunk 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8
pixcodes / shortcodes.php

shortcodes.php in PixCodes trunk, at shortcodes.php

170 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'WPGRADE_SHORTCODES_PATH' ) or define( 'WPGRADE_SHORTCODES_PATH', plugin_dir_path( __FILE__ ) );
4 defined( 'WPGRADE_SHORTCODES_URL' ) or define( 'WPGRADE_SHORTCODES_URL', plugin_dir_url( dirname( __FILE__ ) . '/shortcodes.php' ) );
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 die( '-1' );
8 }
9
10 require_once 'util.php';
11
12 class WpGradeShortcode {
13
14 public $plug_dir;
15 protected $shortcode;
16 protected $settings;
17 protected $params;
18 protected $self_closed;
19 protected $one_line;
20 protected $code;
21 protected $direct;
22 protected $icon;
23 protected $shortcodes;
24 protected $name;
25 protected $backend_assets;
26 protected $frontend_assets;
27 protected $load_frontend_scripts;
28 protected $assets;
29 //we use this to get the prefix for the meta data from the theme - usually it's short theme name
30 protected $meta_prefix;
31
32 public function __construct() {
33
34 $this->plug_dir = plugins_url();
35 $this->self_closed = false;
36 $this->one_line = false;
37 $this->shortcodes = array();
38
39 $this->autoload();
40
41 // init assets list // useless
42 $this->assets = array(
43 'js' => array(),
44 'css' => array()
45 );
46 }
47
48 public function autoload() {
49
50 $shortcodes = get_option( 'wpgrade_shortcodes_list' );
51
52 if ( empty( $shortcodes ) ) {
53 $shortcodes = array(
54 'Arrow',
55 'Button',
56 'Columns',
57 'Heading',
58 'Icon',
59 'InfoBox',
60 'OpenTableReservations',
61 'ProgressBar',
62 'Quote',
63 'RestaurantMenu',
64 'Separator',
65 'Slider',
66 'Tabs',
67 'TeamMember',
68 'PixFields'
69 );
70 }
71
72 foreach ( $shortcodes as $file ) {
73
74 $file_name = 'WpGradeShortcode_' . $file . '.php';
75 $file_path = WPGRADE_SHORTCODES_PATH . '/shortcodes/' . $file_name;
76
77 if ( ! file_exists( $file_path ) ) {
78 continue;
79 }
80
81 include_once( $file_path );
82 $shortcode_class = 'WpGradeShortcode_' . $file;
83 $shortcode = new $shortcode_class();
84
85 // create a list of params needed for js to create the admin panel
86 $this->shortcodes[ $shortcode_class ]["name"] = $shortcode->name;
87 $this->shortcodes[ $shortcode_class ]["code"] = $shortcode->code;
88 $this->shortcodes[ $shortcode_class ]["self_closed"] = $shortcode->self_closed;
89 $this->shortcodes[ $shortcode_class ]["direct"] = $shortcode->direct;
90 $this->shortcodes[ $shortcode_class ]["one_line"] = $shortcode->one_line;
91 $this->shortcodes[ $shortcode_class ]["icon"] = $shortcode->icon;
92 if ( $shortcode->direct == false ) {
93 $this->shortcodes[ $shortcode_class ]["params"] = $shortcode->params;
94 }
95 }
96 }
97
98 public function get_shortcodes() {
99 return $this->shortcodes;
100 }
101
102 public function get_code() {
103 return $this->code;
104 }
105
106 public function load_backend_assets( $buttons ) {
107
108 if ( ! empty( $this->backend_assets ) ) {
109 $types = $this->backend_assets;
110
111 foreach ( $types as $type => $assets ) {
112 foreach ( $assets as $key => $asset ) {
113 $path = WPGRADE_SHORTCODES_URL . $asset['path'];
114 if ( $type == 'js' ) {
115 wp_enqueue_script( $asset['name'], $path, $asset['deps'], '2.3.9', true );
116 } elseif ( $type == 'css' ) {
117 wp_enqueue_style( $asset['name'], $path, $asset['deps'], '2.3.9' );
118 }
119 }
120 }
121 }
122
123 // do not modify buttons here ... we just add our scripts
124 return $buttons;
125 }
126
127 public function load_frontend_assets() {
128
129 if ( ! empty( $this->frontend_assets ) && $this->load_frontend_scripts == true ) {
130 $types = $this->frontend_assets;
131
132 foreach ( $types as $type => $assets ) {
133 foreach ( $assets as $key => $asset ) {
134 $path = WPGRADE_SHORTCODES_URL . $asset['path'];
135 if ( $type == 'js' ) {
136 wp_enqueue_script( $asset['name'], $path, $asset['deps'], '2.3.9', true );
137 } elseif ( $type == 'css' ) {
138 wp_enqueue_style( $asset['name'], $path, $asset['deps'], '2.3.9' );
139 }
140 }
141 }
142 }
143 }
144
145 public function get_clean_content( $content ) {
146 $content = preg_replace( '#<br class="pxg_removable" />#', '', $content ); // remove our temp brs
147
148 return do_shortcode( $content );
149 }
150
151 public function render_param( $param ) {
152
153 $file_name = $param['type'] . '.php';
154 $file_path = WPGRADE_SHORTCODES_PATH . 'params/' . $file_name;
155
156 if ( ! file_exists( $file_path ) ) {
157 return '<span class="error">' . esc_html__( 'Inexistent param', 'pixcodes' ) . '</span>';
158 }
159 ob_start();
160
161 include( $file_path );
162
163 return ob_get_clean();
164 }
165
166 }
167
168 global $wpgrade_shortcodes;
169 $wpgrade_shortcodes = new WpGradeShortcode();
170